[Commit] nickle/builtin sockets.c,1.8,1.9
Keith Packard
commit@keithp.com
Wed, 28 May 2003 15:12:44 -0700
Committed by: keithp
Update of /local/src/CVS/nickle/builtin
In directory home.keithp.com:/tmp/cvs-serv11167/builtin
Modified Files:
sockets.c
Log Message:
Make Sockets::accept work
Index: sockets.c
===================================================================
RCS file: /local/src/CVS/nickle/builtin/sockets.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- sockets.c 17 Oct 2002 15:54:17 -0000 1.8
+++ sockets.c 28 May 2003 22:12:41 -0000 1.9
@@ -167,7 +167,13 @@
running->thread.partial = 1;
}
else
+ {
+ RaiseStandardException (exception_io_error,
+ strerror (errno),
+ 2, FileGetError (errno),
+ s);
RETURN (Void); /* FIXME: more here? */
+ }
}
}
if (s->file.flags & FileOutputBlocked)
@@ -190,6 +196,12 @@
if (!address_lookup (host, port, &addr))
RETURN (Void);
+#ifdef SO_REUSEADDR
+ {
+ int one = 1;
+ setsockopt (s->file.fd, SOL_SOCKET, SO_REUSEADDR, (char *) &one, sizeof (int));
+ }
+#endif
if (bind (s->file.fd, (struct sockaddr *) &addr, sizeof addr) == -1)
RETURN (Void); /* FIXME: more here? */
@@ -225,18 +237,26 @@
f = accept (s->file.fd, 0, 0);
if (f == -1)
{
- if (errno == EWOULDBLOCK)
- {
+ if (errno == EWOULDBLOCK || errno == EAGAIN)
+ {
FileSetBlocked (s, FileInputBlocked);
- ThreadSleep (running, s, PriorityIo);
+ running->thread.partial = 1;
+ }
+ else
+ {
+ RaiseStandardException (exception_io_error,
+ strerror (errno),
+ 2, FileGetError (errno),
+ s);
+ RETURN (Void);
}
- RaiseStandardException (exception_io_error,
- strerror (errno),
- 2, FileGetError (errno),
- s);
- RETURN (Void); /* FIXME: more here? */
}
-
+ if (s->file.flags & FileInputBlocked)
+ {
+ ThreadSleep (running, s, PriorityIo);
+ RETURN (Void);
+ }
+
complete = True;
RETURN (FileCreate (f, FileReadable|FileWritable));
}