[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r7066: - accept running nicely - clean up todos, and sync issues an (bsockets/trunk)
Author: chiussi
Date: 2006-08-15 05:39:36 -0400 (Tue, 15 Aug 2006)
New Revision: 7066
Modified:
bsockets/trunk/accept.c
bsockets/trunk/callback.c
bsockets/trunk/event.c
bsockets/trunk/event.h
bsockets/trunk/io.c
bsockets/trunk/io.h
bsockets/trunk/socket.c
bsockets/trunk/test.c
Log:
- accept running nicely
- clean up todos, and sync issues and we're ready to merge
Modified: bsockets/trunk/accept.c
===================================================================
--- bsockets/trunk/accept.c 2006-08-15 04:50:33 UTC (rev 7065)
+++ bsockets/trunk/accept.c 2006-08-15 09:39:36 UTC (rev 7066)
@@ -112,6 +112,8 @@
s = accept(b->s,name,namelen);
CHECK(s != INVALID_SOCKET,0);
+ post_accepted(b,s,env);
+
c = bsocket_new(s);
c_fd = claim_free_fd(c,env);
@@ -125,20 +127,23 @@
l = bsocket_list_get(env);
if (l != NULL) {
- make_connected(env->b[c_fd],-1,env);
+ make_connected(l[c_fd],-1,env);
bsocket_list_release(env);
out = c_fd;
} else {
+ err = errno;
close_win32(c_fd,env);
+ errno = err;
+ out = -1;
}
fail:
if (b != NULL) {
+ //todo verify that bsocket doesnt alter errno
bsocket_release(fd,AS_READ,env);
}
-
return out;
}
Modified: bsockets/trunk/callback.c
===================================================================
--- bsockets/trunk/callback.c 2006-08-15 04:50:33 UTC (rev 7065)
+++ bsockets/trunk/callback.c 2006-08-15 09:39:36 UTC (rev 7066)
@@ -24,23 +24,24 @@
if (err == 0) {
- if (msg->buf_wb.len == 0) {
+ if (msg->len == len) {
socket_raise(msg->fd,IS_WRITABLE,TRUE,msg->env);
msg_free(msg);
} else {
- //it is assumed that on an incomplete operation,
- //the buffer pointer is adjusted upward by the number
- //of written bytes. tests seem to confirm this, although
- //i can't find it documented anywhere
-
//it is pretty nasty to do the write operation twice, but
//its the method involving the least overhead right now
//todo -- figure out a way to test this, i can't figure out a
//way to force WSASend to do an incomplete write
+
+ msg->buf_wb.buf += len;
+ msg->buf_wb.len -= len;
+
+ msg->len -= len;
+
r = WSASend(
msg->s,
&msg->buf_wb,
@@ -88,13 +89,11 @@
ASSERT(len >= 0);
- ASSERT(len <= MSG_SIZE);
+ ASSERT(len <= msg->len);
if (len > 0) {
b = bsocket_get(msg->fd,AS_READ,msg->env);
- printf("%d %d\n",msg->fd,len);
- fflush(stdout);
ASSERT(b != NULL);
ASSERT(b->fd == msg->fd);
Modified: bsockets/trunk/event.c
===================================================================
--- bsockets/trunk/event.c 2006-08-15 04:50:33 UTC (rev 7065)
+++ bsockets/trunk/event.c 2006-08-15 09:39:36 UTC (rev 7066)
@@ -73,9 +73,12 @@
break;
case EV_LISTEN:
+ case EV_ACCEPT:
+
//nothing to do
break;
+
default:
ASSERT(FALSE);
break;
@@ -244,36 +247,29 @@
return out;
}
-
int post_write(struct bsocket *b, int *ret, int *err, struct socket_env *env) {
-
//todo assert is writable
return event_post(b,EV_WRITE,&b->w_wo,ret,err,TRUE,env);
-
}
int post_exception(struct bsocket *b, int err, struct socket_env *env) {
-
return event_post(b,EV_EXCEPTION,(void*) err,NULL,NULL,FALSE,env);
-
}
int post_close(struct bsocket *b, struct socket_env *env) {
-
return post_exception(b,ECLOSED,env);
-
}
int post_read(struct bsocket *b, struct socket_env *env) {
-
return event_post(b,EV_READ,&b->r_wo,NULL,NULL,FALSE,env);
-
}
int post_listen(struct bsocket *b, int backlog, int *res, int *err, struct socket_env *env) {
-
return event_post (b,EV_LISTEN,(void*) backlog, res,err,TRUE,env);
+}
+int post_accepted(struct bsocket *b, SOCKET s, struct socket_env *env) {
+ return event_post(b,EV_ACCEPT,(void*)s,NULL,NULL,TRUE,env);
}
struct _event *event_next(struct socket_env *env) {
@@ -307,10 +303,10 @@
ev[_j].type = TYPE;\
switch(TYPE) {\
case FD_CONNECT:\
- connect_lookup[(int)FD] = _j;\
+ connect_lookup[FD] = _j;\
break;\
case FD_ACCEPT:\
- listen_lookup[(int)FD] = _j;\
+ listen_lookup[FD] = _j;\
break;\
default:\
ASSERT(FALSE);\
@@ -337,9 +333,6 @@
void event_manager(struct socket_env *env) {
- SOCKET connect_lookup[MAX_BSOCKETS];
- SOCKET listen_lookup[MAX_BSOCKETS];
-
WSAEVENT we[WSA_MAXIMUM_WAIT_EVENTS];
struct __ev ev[WSA_MAXIMUM_WAIT_EVENTS];
@@ -356,6 +349,9 @@
struct bsocket *p;
+ int connect_lookup[MAX_BSOCKETS];
+ int listen_lookup[MAX_BSOCKETS];
+
int i, _j;
int err;
int out;
@@ -396,6 +392,7 @@
r = WSAWaitForMultipleEvents(WSA_MAXIMUM_WAIT_EVENTS,we,FALSE,INFINITE,TRUE);
ASSERT(connect_count <= MAX_SIMUL_CONNECT);
+ ASSERT(listen_count <= MAX_SIMUL_LISTEN);
switch (r) {
@@ -418,14 +415,17 @@
z = 0;
- //todo -- this is fishy
- if ((i = connect_lookup[(SOCKET) ev->fd]) != -1) {
+ //todo -- previously the index was was ev->fd before,
+ //what in the nameof christ was i thinking?
+ //furthermore, _why_ was it working!
+ if ((i = connect_lookup[e->fd]) != -1) {
E_DELETE(i);
z++;
}
- if ((i = listen_lookup[(SOCKET) ev->fd]) != -1) {
+ if ((i = listen_lookup[e->fd]) != -1) {
E_DELETE(i);
+ listen_count--;
z++;
}
@@ -563,9 +563,6 @@
} else {
- //it's tempting to use callback_read, but it's a bad
- //move. what if partner excepts inbetween calls?
-
p = bsocket_get(e->p_fd,AS_READ,env);
if (p != NULL) {
@@ -586,7 +583,6 @@
} else {
- //todo -- what is a better errno?
event_respond(e,-1,errno);
}
@@ -616,6 +612,23 @@
break;
+ case EV_ACCEPT:
+ //deassociate accepted socket with network events
+
+ z = listen_lookup[e->fd];
+
+ ASSERT(e->s == ev[z].s);
+ ASSERT(e->fd == ev[z].fd);
+
+ ASSERT(
+ WSAEventSelect((SOCKET) e->data,we[z],0)
+ != SOCKET_ERROR
+ );
+
+ event_respond(e,0,0);
+
+ break;
+
default:
ASSERT(FALSE);
break;
@@ -661,12 +674,13 @@
if (err) {
socket_exception(ev[i].fd,unixify_wsaerr(err),env);
+ E_DELETE(i);
+ listen_count--;
+
} else {
socket_client_in(ev[i].fd,env);
}
- E_DELETE(i);
- listen_count--;
break;
@@ -694,6 +708,7 @@
break;
case WAIT_IO_COMPLETION:
+ //a callback has been invoked
break;
}
Modified: bsockets/trunk/event.h
===================================================================
--- bsockets/trunk/event.h 2006-08-15 04:50:33 UTC (rev 7065)
+++ bsockets/trunk/event.h 2006-08-15 09:39:36 UTC (rev 7066)
@@ -10,6 +10,7 @@
#define EV_LISTEN (4)
#define EV_WRITE (5)
#define EV_READ (6)
+#define EV_ACCEPT (7)
#define EV_EXCEPTION (50)
@@ -52,5 +53,6 @@
int post_write(struct bsocket *, int*, int*, struct socket_env*);
int post_close(struct bsocket *, struct socket_env*);
int post_listen(struct bsocket *, int, int*, int*, struct socket_env*);
+int post_accepted(struct bsocket *, SOCKET, struct socket_env*);
#endif
Modified: bsockets/trunk/io.c
===================================================================
--- bsockets/trunk/io.c 2006-08-15 04:50:33 UTC (rev 7065)
+++ bsockets/trunk/io.c 2006-08-15 09:39:36 UTC (rev 7066)
@@ -84,15 +84,6 @@
wo->hEvent = (WSAEVENT) msg;
- WSABUF *wb;
- wb = (WSABUF*) malloc(sizeof (WSABUF));
-
-
- ASSERT(wb != NULL);
-
- wb->buf = malloc(1000);
- wb->len = 1000;
-
r = WSARecv(
s,
&msg->buf_wb,
@@ -235,7 +226,6 @@
int z;
int out;
-
b = bsocket_get(fd,AS_WRITE,env);
CHECK(b != NULL,0);
CHECK(b->connected,ENOTCONN);
Modified: bsockets/trunk/io.h
===================================================================
--- bsockets/trunk/io.h 2006-08-15 04:50:33 UTC (rev 7065)
+++ bsockets/trunk/io.h 2006-08-15 09:39:36 UTC (rev 7066)
@@ -1,10 +1,7 @@
#ifndef _IO_H_
#define _IO_H_
-//keep in increments of kernel page size
-#define MSG_SIZE 4096
-
struct _msg {
SOCKET s;
Modified: bsockets/trunk/socket.c
===================================================================
--- bsockets/trunk/socket.c 2006-08-15 04:50:33 UTC (rev 7065)
+++ bsockets/trunk/socket.c 2006-08-15 09:39:36 UTC (rev 7066)
@@ -433,6 +433,7 @@
CHECK_(s != INVALID_SOCKET);
+ //the underlying socket is always non-blocking
CHECK_( ioctlsocket(s,FIONBIO,(u_long*) &nonblocking) == 0);
b = bsocket_new(s);
Modified: bsockets/trunk/test.c
===================================================================
--- bsockets/trunk/test.c 2006-08-15 04:50:33 UTC (rev 7065)
+++ bsockets/trunk/test.c 2006-08-15 09:39:36 UTC (rev 7066)
@@ -1590,7 +1590,6 @@
s = socket(AF_INET,SOCK_STREAM,0);
msg = 666;
-
SILENT_TEST(s != INVALID_SOCKET);
r = bind(s,(struct sockaddr*) &localhost,sizeof(localhost));
@@ -1785,6 +1784,7 @@
SILENT_TEST(r == sizeof(msg));
SILENT_TEST(msg == 667);
+ //todo -- SO_LINGER might raise an issue here
SILENT_TEST(bclose(fd) == 0);
return 0;
@@ -1834,6 +1834,11 @@
r = WaitForSingleObject(h, INFINITE);
TEST(r == WAIT_OBJECT_0);
+ TEST(GetExitCodeThread(h,(DWORD*)&r));
+ TEST(r == 0);
+
+ CloseHandle(h);
+
TEST(bsocket_shutdown(NULL) == 0);
return 0;