diff options
author | Jeffrey Stedfast <fejj@ximian.com> | 2004-01-03 07:46:40 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2004-01-03 07:46:40 +0800 |
commit | b554670684a2a45f46b681e9dfbb27f3e0f199c7 (patch) | |
tree | ea22b436da2c46ab9b21de158dad48060f24923e /camel/camel-tcp-stream-raw.c | |
parent | 8baeb6bb0ab1eb49493ad95238f6c02a11254144 (diff) | |
download | gsoc2013-evolution-b554670684a2a45f46b681e9dfbb27f3e0f199c7.tar.gz gsoc2013-evolution-b554670684a2a45f46b681e9dfbb27f3e0f199c7.tar.zst gsoc2013-evolution-b554670684a2a45f46b681e9dfbb27f3e0f199c7.zip |
Save errno and check the return of the socket() call.
2003-12-27 Jeffrey Stedfast <fejj@ximian.com>
* camel-tcp-stream-raw.c (socket_connect): Save errno and check
the return of the socket() call.
svn path=/trunk/; revision=24028
Diffstat (limited to 'camel/camel-tcp-stream-raw.c')
-rw-r--r-- | camel/camel-tcp-stream-raw.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/camel/camel-tcp-stream-raw.c b/camel/camel-tcp-stream-raw.c index 819647cff6..d2cee82c0a 100644 --- a/camel/camel-tcp-stream-raw.c +++ b/camel/camel-tcp-stream-raw.c @@ -277,6 +277,7 @@ socket_connect (struct hostent *h, int port) struct timeval tv; socklen_t len; int cancel_fd; + int errnosav; int ret, fd; /* see if we're cancelled yet */ @@ -304,13 +305,15 @@ socket_connect (struct hostent *h, int port) } #endif - fd = socket (h->h_addrtype, SOCK_STREAM, 0); + if ((fd = socket (h->h_addrtype, SOCK_STREAM, 0) == -1)) + return -1; cancel_fd = camel_operation_cancel_fd (NULL); if (cancel_fd == -1) { - ret = connect (fd, saddr, len); - if (ret == -1) { + if (connect (fd, saddr, len) == -1) { + errnosav = errno; close (fd); + errno = errnosav; return -1; } @@ -322,14 +325,15 @@ socket_connect (struct hostent *h, int port) flags = fcntl (fd, F_GETFL); fcntl (fd, F_SETFL, flags | O_NONBLOCK); - ret = connect (fd, saddr, len); - if (ret == 0) { + if (connect (fd, saddr, len) == 0) { fcntl (fd, F_SETFL, flags); return fd; } if (errno != EINPROGRESS) { + errnosav = errno; close (fd); + errno = errnosav; return -1; } @@ -359,7 +363,9 @@ socket_connect (struct hostent *h, int port) len = sizeof (int); if (getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &len) == -1) { + errnosav = errno; close (fd); + errno = errnosav; return -1; } |