[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r10889: Bufferevent working on windows. Todo: Test Unix part of cros (in libevent-urz/trunk: . loaders sample)



Author: Urz
Date: 2007-07-19 23:30:38 -0400 (Thu, 19 Jul 2007)
New Revision: 10889

Modified:
   libevent-urz/trunk/evbuffer.c
   libevent-urz/trunk/event.h
   libevent-urz/trunk/loaders/IOCPloader.c
   libevent-urz/trunk/sample/crossplat-bufferevent-test.c
   libevent-urz/trunk/win_evbuffer.c
Log:
Bufferevent working on windows. Todo: Test Unix part of cross platform socket implementation, Close/Free&Close implementations

Modified: libevent-urz/trunk/evbuffer.c
===================================================================
--- libevent-urz/trunk/evbuffer.c	2007-07-19 20:47:18 UTC (rev 10888)
+++ libevent-urz/trunk/evbuffer.c	2007-07-20 03:30:38 UTC (rev 10889)
@@ -56,8 +56,8 @@
     return socket(AF_INET, SOCK_STREAM, 0);
 }
 // connect
-int bufev_socket_connect(struct bufferevent *bufev, struct sockaddr_in *addr) {
-    return connect(bufev->fd, (struct sockaddr*)addr, sizeof(addr));
+int bufev_socket_connect(int sock, struct sockaddr_in *addr) {
+    return connect(sock, (struct sockaddr*)addr, sizeof(addr));
 }
 // accept
 struct bufferevent *bufev_socket_accept(int listen_sock, evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg) {

Modified: libevent-urz/trunk/event.h
===================================================================
--- libevent-urz/trunk/event.h	2007-07-19 20:47:18 UTC (rev 10888)
+++ libevent-urz/trunk/event.h	2007-07-20 03:30:38 UTC (rev 10889)
@@ -276,10 +276,39 @@
 	short enabled;	/* events that are currently enabled */
 };
 
+/*
+ * Documentation for the below is rough, but should be complete
+ *
+ * int bufev_socket_new(void);
+ * Creates a new socket which is compatible with the local implementation
+ * of bufferevents. The return value is only required to fit in the same
+ * space as an int, it is not required to actually *be* an int.
+ * Regardless the true return type, (int) -1 is a reserved value which
+ * means creating a new socket failed.
+ *
+ * int bufev_socket_connect(int sock, struct sockaddr_in *addr);
+ * Connects a socket to an internet address. Returns -1 on failure,
+ * 0 on success.
+ *
+ * struct bufferevent *bufev_socket_accept(int listen_sock, evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg);
+ * listen_sock is a listening socket (see bufev_socket_listen).
+ * all other arguments are as bufferevent_new().
+ * Takes one connection off the pending connection queue for a listening socket and
+ * creates a new bufferevent based on the connection.
+ *
+ * int bufev_socket_listen(int sock, int backlog);
+ * Sets a socket (created with bufev_socket_new()) to listen. The socket must first be bound
+ * (with bufev_socket_bind()). Returns 0 on success, -1 on failure.
+ *
+ * int bufev_socket_bind(int sock, struct sockaddr_in *bind_to);
+ * Binds a socket (created with bufev_socket_new()) to a particular internet address.
+ * returns 0 on success, -1 on failure.
+ */
+
 //socket
 int bufev_socket_new(void);
 // connect
-int bufev_socket_connect(struct bufferevent *bufev, struct sockaddr_in *addr);
+int bufev_socket_connect(int sock, struct sockaddr_in *addr);
 // accept
 struct bufferevent *bufev_socket_accept(int listen_sock, evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg);
 // listen
@@ -287,6 +316,11 @@
 // bind
 int bufev_socket_bind(int sock, struct sockaddr_in *bind_to);
 
+/* 
+ * Note: bufferevent_new must only be called with *connected* bufev_sockets.
+ * attempting to create a new bufferevent with a disconnected bufev_socket may
+ * fail and it may fail silently.
+ */
 struct bufferevent *bufferevent_new(int fd,
     evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg);
 int bufferevent_base_set(struct event_base *base, struct bufferevent *bufev);

Modified: libevent-urz/trunk/loaders/IOCPloader.c
===================================================================
--- libevent-urz/trunk/loaders/IOCPloader.c	2007-07-19 20:47:18 UTC (rev 10888)
+++ libevent-urz/trunk/loaders/IOCPloader.c	2007-07-20 03:30:38 UTC (rev 10889)
@@ -270,7 +270,7 @@
         if(CompletedOverlapped->op == OP_SEND) {
             // the connection has sent all data and is ready for more
             SendComplete(Conn, CompleteSize);
-            printf("s");
+            //printf("s");
         } else if(CompletedOverlapped->op == OP_RECV) {
             // Now we have a completed read event, perform the operations
             // required on the read data.
@@ -279,7 +279,7 @@
             // Now the data has been removed from the WSABUF, we can reset the
             // read to continue reading.
             ResetRead(Conn);
-            printf("r");
+            //printf("r");
         }
         ev_unlock(Conn->lock);
     }

Modified: libevent-urz/trunk/sample/crossplat-bufferevent-test.c
===================================================================
--- libevent-urz/trunk/sample/crossplat-bufferevent-test.c	2007-07-19 20:47:18 UTC (rev 10888)
+++ libevent-urz/trunk/sample/crossplat-bufferevent-test.c	2007-07-20 03:30:38 UTC (rev 10889)
@@ -221,12 +221,13 @@
     Connect = bufev_socket_new();
     
     printf("Connect = %d\n", (int) Connect);
+
+    printf("Connecting...\n");
+    bufev_socket_connect(Connect, &socketAddr);
     
     printf("Creating Bufferevent\n");
     csabe = bufferevent_new(Connect, connector_on_read, NULL, NULL, NULL);
 
-    printf("Connecting...\n");
-    bufev_socket_connect(csabe, &socketAddr);
     
     printf("Connected.\n");
     

Modified: libevent-urz/trunk/win_evbuffer.c
===================================================================
--- libevent-urz/trunk/win_evbuffer.c	2007-07-19 20:47:18 UTC (rev 10888)
+++ libevent-urz/trunk/win_evbuffer.c	2007-07-20 03:30:38 UTC (rev 10889)
@@ -23,10 +23,10 @@
     return (int) ret;
 }
 // connect
-int bufev_socket_connect(struct bufferevent *bufev, struct sockaddr_in *addr) {
+int bufev_socket_connect(int sock, struct sockaddr_in *addr) {
     int ret;
-    printf("Connecting with %d\n", (SOCKET)(((struct sa_bufferevent *)bufev)->connection_handle));
-    ret = connect((SOCKET)(((struct sa_bufferevent *)bufev)->connection_handle), (struct sockaddr*)addr, sizeof(struct sockaddr_in));
+    printf("Connecting with %d\n", sock);
+    ret = connect((SOCKET) sock, (struct sockaddr*)addr, sizeof(struct sockaddr_in));
     if(ret == SOCKET_ERROR) {
         printf("Connecting failed with error %d\n", (int) GetLastError());
         return -1;