[Commit] nickle/builtin sockets.c,1.11,1.12
Keith Packard
commit at keithp.com
Fri Jan 9 22:20:05 PST 2004
- Previous message: [Commit] nickle file.c, 1.56, 1.57 value.h, 1.94, 1.95 version.m4,
1.5, 1.6
- Next message: [Commit] librr .cvsignore,1.2,1.3 ChangeLog,1.4,1.5
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Committed by: keithp
Update of /local/src/CVS/nickle/builtin
In directory home.keithp.com:/local/src/nickle/builtin
Modified Files:
sockets.c
Log Message:
Switch fds to nonblocking for connect/accept calls
Index: sockets.c
===================================================================
RCS file: /local/src/CVS/nickle/builtin/sockets.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- sockets.c 11 Jun 2003 05:01:56 -0000 1.11
+++ sockets.c 10 Jan 2004 06:20:02 -0000 1.12
@@ -13,6 +13,7 @@
*/
#include <unistd.h>
+#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
@@ -183,9 +184,17 @@
if (!running->thread.partial)
{
- if (connect (s->file.fd, (struct sockaddr *) &addr, sizeof addr) == -1)
+ int flags = fcntl (s->file.fd, F_GETFL);
+ int n, err;
+ flags |= O_NONBLOCK;
+ fcntl (s->file.fd, F_SETFL, flags);
+ n = connect (s->file.fd, (struct sockaddr *) &addr, sizeof addr);
+ flags &= ~O_NONBLOCK;
+ fcntl (s->file.fd, F_SETFL, flags);
+ err = errno;
+ if (n == -1)
{
- if (errno == EWOULDBLOCK || errno == EINPROGRESS)
+ if (err == EWOULDBLOCK || err == EINPROGRESS)
{
FileSetBlocked (s, FileOutputBlocked);
running->thread.partial = 1;
@@ -193,8 +202,8 @@
else
{
RaiseStandardException (exception_io_error,
- FileGetErrorMessage (errno),
- 2, FileGetError (errno),
+ FileGetErrorMessage (err),
+ 2, FileGetError (err),
s);
RETURN (Void);
}
@@ -262,12 +271,17 @@
do_Socket_accept (Value s)
{
ENTER ();
- int f;
-
+ int f, err;
+ int flags = fcntl (s->file.fd, F_GETFL);
+ flags |= O_NONBLOCK;
+ fcntl (s->file.fd, F_SETFL, flags);
f = accept (s->file.fd, 0, 0);
+ flags &= ~O_NONBLOCK;
+ fcntl (s->file.fd, F_SETFL, flags);
+ err = errno;
if (f == -1)
{
- if (errno == EWOULDBLOCK || errno == EAGAIN)
+ if (err == EWOULDBLOCK || err == EAGAIN)
{
FileSetBlocked (s, FileInputBlocked);
running->thread.partial = 1;
@@ -275,8 +289,8 @@
else
{
RaiseStandardException (exception_io_error,
- FileGetErrorMessage (errno),
- 2, FileGetError (errno),
+ FileGetErrorMessage (err),
+ 2, FileGetError (err),
s);
RETURN (Void);
}
- Previous message: [Commit] nickle file.c, 1.56, 1.57 value.h, 1.94, 1.95 version.m4,
1.5, 1.6
- Next message: [Commit] librr .cvsignore,1.2,1.3 ChangeLog,1.4,1.5
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Commit
mailing list