[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r7056: forgot to add files last time (bsockets/trunk)
Author: chiussi
Date: 2006-08-14 07:48:47 -0400 (Mon, 14 Aug 2006)
New Revision: 7056
Added:
bsockets/trunk/accept.c
bsockets/trunk/accept.h
Log:
forgot to add files last time
Added: bsockets/trunk/accept.c
===================================================================
--- bsockets/trunk/accept.c 2006-08-14 11:45:44 UTC (rev 7055)
+++ bsockets/trunk/accept.c 2006-08-14 11:48:47 UTC (rev 7056)
@@ -0,0 +1,146 @@
+#include <windows.h>
+
+#include "accept.h"
+#include "socket.h"
+#include "misc.h"
+#include "select.h"
+#include "event.h"
+#include "list.h"
+#include "callback.h"
+
+int bind_win32(int fd, struct sockaddr *name, int len, struct socket_env *env) {
+
+ struct bsocket *b;
+
+ int out;
+ int r;
+
+ out = 0;
+
+ b = bsocket_get(fd,AS_WRITE,env);
+ CHECK(b != NULL,0);
+
+ r = bind(b->s,name,len);
+
+ CHECK_(r != SOCKET_ERROR);
+
+ fail:
+
+ if (b != NULL) {
+ bsocket_release(fd,AS_WRITE,env);
+ }
+
+ return out;
+
+}
+
+int listen_win32(int fd, int backlog, struct socket_env *env) {
+
+ struct bsocket *b;
+ int out;
+ int r;
+ int z;
+ int err;
+
+ out = 0;
+
+ b = bsocket_get(fd,AS_WRITE,env);
+ CHECK(b != NULL,0);
+
+ r = post_listen(b,backlog,&z,&err,env);
+
+ CHECK(r == 0,0);
+ CHECK(z == 0,err);
+
+ fail:
+
+ if (b != NULL) {
+ bsocket_release(fd,AS_WRITE,env);
+ }
+
+ return out;
+}
+
+void socket_client_in(int fd, struct socket_env *env) {
+
+ struct bsocket *b;
+
+ b = bsocket_get(fd,AS_READ,env);
+ if (b == NULL) {
+ ASSERT(errno == ECLOSED);
+ } else {
+ list_enqueue(NULL,b->in_q);
+ socket_raise(fd,IS_READABLE,TRUE,env);
+ bsocket_release(fd,AS_READ,env);
+ }
+
+}
+
+int accept_win32(int fd, struct sockaddr *name, int *namelen, struct socket_env *env) {
+
+ SOCKET s;
+
+ struct bsocket **l;
+ struct bsocket *b;
+ struct bsocket *c;
+
+ int c_fd;
+
+ int out;
+ int r;
+ int err;
+
+ out = 0;
+
+ b = bsocket_get(fd,AS_READ,env);
+ CHECK(b != NULL,0);
+
+ if (list_is_empty(b->in_q)) {
+
+ CHECK(b->blocking,EAGAIN);
+ bsocket_release(fd,AS_READ,env);
+
+ r = wait_until(b,IS_READABLE,env);
+ CHECK(r == 0,0);
+
+ b = bsocket_get(fd,AS_READ,env);
+ CHECK(b != NULL,0);
+
+ }
+
+ //todo -- should we raise exception if accept() fails?
+ s = accept(b->s,name,namelen);
+ CHECK(s != INVALID_SOCKET,0);
+
+ c = bsocket_new(s);
+
+ c_fd = claim_free_fd(c,env);
+
+ if (c_fd == -1) {
+ err = errno;
+ bsocket_free(c);
+ CHECK(FALSE,err);
+ }
+
+ l = bsocket_list_get(env);
+
+ if (l != NULL) {
+ make_connected(env->b[c_fd],-1,env);
+ bsocket_list_release(env);
+ out = c_fd;
+ } else {
+ close_win32(c_fd,env);
+ }
+
+ fail:
+
+ if (b != NULL) {
+ bsocket_release(fd,AS_READ,env);
+ }
+
+
+ return out;
+
+}
+
+
Property changes on: bsockets/trunk/accept.c
___________________________________________________________________
Name: svn:executable
+ *
Added: bsockets/trunk/accept.h
===================================================================
--- bsockets/trunk/accept.h 2006-08-14 11:45:44 UTC (rev 7055)
+++ bsockets/trunk/accept.h 2006-08-14 11:48:47 UTC (rev 7056)
@@ -0,0 +1,12 @@
+#ifndef _ACCEPT_H_
+#define _ACCEPT_H_
+
+#include "socket.h"
+
+void socket_client_in(int,struct socket_env *env);
+
+int bind_win32(int,struct sockaddr *, int, struct socket_env *);
+int listen_win32(int, int, struct socket_env*);
+int accept_win32(int, struct sockaddr*, int*, struct socket_env*);
+
+#endif
Property changes on: bsockets/trunk/accept.h
___________________________________________________________________
Name: svn:executable
+ *