projects
/
soc-cxxrtl-sim.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
2a2db12
)
add totally unsophisticated socket listen/accept function
author
Luke Kenneth Casson Leighton
<lkcl@lkcl.net>
Thu, 8 Apr 2021 12:41:40 +0000
(13:41 +0100)
committer
Luke Kenneth Casson Leighton
<lkcl@lkcl.net>
Thu, 8 Apr 2021 12:41:40 +0000
(13:41 +0100)
small_jtag_test/main.cpp
patch
|
blob
|
history
diff --git
a/small_jtag_test/main.cpp
b/small_jtag_test/main.cpp
index 63c9cf8947b58cd219a5f9885948c3b9fe418b06..73dd45bb2d4b31d595bc89b487aabd4b546e886b 100644
(file)
--- a/
small_jtag_test/main.cpp
+++ b/
small_jtag_test/main.cpp
@@
-1,3
+1,10
@@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/select.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
#include <iostream>
#include "add.cpp"
#include <iostream>
#include "add.cpp"
@@
-5,11
+12,6
@@
using namespace std;
extern "C" {
using namespace std;
extern "C" {
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/select.h>
/* reads from a socket if it is ready (a single byte) and returns 1 if success
*/
/* reads from a socket if it is ready (a single byte) and returns 1 if success
*/
@@
-38,13
+40,32
@@
int read_handler(int fdread, char *buffer)
}
}
}
}
-/*
-static void event_handler(int fd, short event, void *arg)
+/* nothing sophisticated: wait for an incoming connection
+ */
+int get_connection()
{
{
- if (event & EV_READ)
- read_handler(fd, event, arg);
+ int listenfd = 0, connfd = 0;
+ struct sockaddr_in serv_addr;
+
+ listenfd = socket(AF_INET, SOCK_STREAM, 0);
+ memset(&serv_addr, '0', sizeof(serv_addr));
+
+ serv_addr.sin_family = AF_INET;
+ serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+ serv_addr.sin_port = htons(5000);
+
+ bind(listenfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr));
+
+ listen(listenfd, 1);
+
+ connfd = accept(listenfd, (struct sockaddr*)NULL, NULL);
+ close(listenfd);
+
+ return connfd;
}
}
+/*
+
static void accept_conn_cb(struct evconnlistener *listener, evutil_socket_t fd, struct sockaddr *address, int socklen, void *ctx)
{
struct session_s *s = (struct session_s*)ctx;
static void accept_conn_cb(struct evconnlistener *listener, evutil_socket_t fd, struct sockaddr *address, int socklen, void *ctx)
{
struct session_s *s = (struct session_s*)ctx;