[or-cvs] r10921: Bufferevents and test program now compiles and runs on Linux (in libevent-urz/trunk: . sample)
Urz at seul.org
Urz at seul.org
Tue Jul 24 06:14:58 UTC 2007
Author: Urz
Date: 2007-07-24 02:14:57 -0400 (Tue, 24 Jul 2007)
New Revision: 10921
Modified:
libevent-urz/trunk/evbuffer.c
libevent-urz/trunk/sample/crossplat-bufferevent-test.c
Log:
Bufferevents and test program now compiles and runs on Linux.
Modified: libevent-urz/trunk/evbuffer.c
===================================================================
--- libevent-urz/trunk/evbuffer.c 2007-07-23 19:07:43 UTC (rev 10920)
+++ libevent-urz/trunk/evbuffer.c 2007-07-24 06:14:57 UTC (rev 10921)
@@ -57,13 +57,19 @@
}
// connect
int bufev_socket_connect(int sock, struct sockaddr_in *addr) {
- return connect(sock, (struct sockaddr*)addr, sizeof(addr));
+ return connect(sock, (struct sockaddr*)addr, sizeof(struct sockaddr_in));
}
// accept
struct bufferevent *bufev_socket_accept(int listen_sock, evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg) {
int returned;
returned = accept(listen_sock, NULL, NULL);
+ if(returned < 0) {
+ printf("Accept failed : %d");
+ perror(NULL);
+ return NULL;
+ }
+
return bufferevent_new(returned, readcb, writecb, errorcb, cbarg);
}
// listen
@@ -72,7 +78,7 @@
}
// bind
int bufev_socket_bind(int sock, struct sockaddr_in *bind_to) {
- return bind(sock, (struct sockaddr*) bind_to, sizeof(bind_to));
+ return bind(sock, (struct sockaddr*) bind_to, sizeof(struct sockaddr_in));
}
static int
Modified: libevent-urz/trunk/sample/crossplat-bufferevent-test.c
===================================================================
--- libevent-urz/trunk/sample/crossplat-bufferevent-test.c 2007-07-23 19:07:43 UTC (rev 10920)
+++ libevent-urz/trunk/sample/crossplat-bufferevent-test.c 2007-07-24 06:14:57 UTC (rev 10921)
@@ -143,7 +143,7 @@
struct bufferevent* lsabe;
int Listen;
- struct sockaddr_in listenAddr;
+ struct sockaddr_in listenAddr;
int Accept;
int bindingHandle = -1;
char buf[BUF_SIZE];
@@ -159,21 +159,30 @@
Listen = bufev_socket_new();
//lsabe = bufferevent_new(bufev_socket_new(), listener_on_read, listener_on_write, NULL, NULL);
printf("Listen = %d\n", (int) Listen);
-
+
listenAddr.sin_family = AF_INET;
listenAddr.sin_port = htons(LISTEN_PORT);
- listenAddr.sin_addr.s_addr = htonl(INADDR_ANY);
+ listenAddr.sin_addr.s_addr = htonl(INADDR_ANY);
printf("Binding Socket\n");
- bufev_socket_bind(Listen, &listenAddr);
- printf("Listening...\n");
- bufev_socket_listen(Listen, 1);
+ if(bufev_socket_bind(Listen, &listenAddr) == -1) {
+ printf("Bind Failed\n");
+ return;
+ }
+ printf("Listening...\n");
+ if(bufev_socket_listen(Listen, 1) == -1) {
+ printf("Bind Failed\n");
+ return;
+ }
- printf("Accepting...\n");
+ printf("Accepting...\n");
- lsabe = bufev_socket_accept(Listen, listener_on_read, listener_on_write, NULL, NULL);
+ lsabe = bufev_socket_accept(Listen, listener_on_read, listener_on_write, NULL, NULL);
// accept() and overlapped IO do not play well together.
-
+ bufferevent_enable(lsabe, EV_READ);
+ bufferevent_enable(lsabe, EV_WRITE);
+
+
printf("Client Accepted...\n");
gen_pattern_a(buf, BUF_SIZE);
@@ -248,11 +257,14 @@
printf("Connect = %d\n", (int) Connect);
printf("Connecting...\n");
- bufev_socket_connect(Connect, &socketAddr);
+ if(bufev_socket_connect(Connect, &socketAddr) == -1) {
+ printf("Connect Failed.\n");
+ return;
+ }
printf("Creating Bufferevent\n");
csabe = bufferevent_new(Connect, connector_on_read, NULL, NULL, NULL);
-
+ bufferevent_enable(csabe, EV_READ);
printf("Connected.\n");
More information about the tor-commits
mailing list