+#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"
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
*/
}
}
-/*
-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;