[svn] assuan - r271 - trunk/src
svn author marcus
cvs at cvs.gnupg.org
Fri Oct 5 18:01:23 CEST 2007
Author: marcus
Date: 2007-10-05 18:01:12 +0200 (Fri, 05 Oct 2007)
New Revision: 271
Modified:
trunk/src/ChangeLog
trunk/src/assuan-buffer.c
trunk/src/assuan-defs.h
trunk/src/assuan-socket.c
trunk/src/assuan-uds.c
Log:
2007-10-05 Marcus Brinkmann <marcus at g10code.de>
* assuan-defs.h (_assuan_sock_wsa2errno) [HAVE_W32_SYSTEM]: Add prototype.
* assuan-uds.c (wsa2errno) [HAVE_W32_SYSTEM]: Move and rename to ...
* assuan-socket.c (_assuan_sock_wsa2errno) [HAVE_W32_SYSTEM]: ... this.
(_assuan_close, _assuan_sock_new, _assuan_sock_connect, _assuan_sock_bind):
Always set errno on error.
Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog 2007-10-05 12:24:01 UTC (rev 270)
+++ trunk/src/ChangeLog 2007-10-05 16:01:12 UTC (rev 271)
@@ -1,5 +1,11 @@
2007-10-05 Marcus Brinkmann <marcus at g10code.de>
+ * assuan-defs.h (_assuan_sock_wsa2errno) [HAVE_W32_SYSTEM]: Add prototype.
+ * assuan-uds.c (wsa2errno) [HAVE_W32_SYSTEM]: Move and rename to ...
+ * assuan-socket.c (_assuan_sock_wsa2errno) [HAVE_W32_SYSTEM]: ... this.
+ (_assuan_close, _assuan_sock_new, _assuan_sock_connect, _assuan_sock_bind):
+ Always set errno on error.
+
* assuan-uds.c (wsa2errno) [HAVE_W32_SYSTEM]: New function.
(uds_reader, uds_writer) [HAVE_W32_SYSTEM]: Set errno.
Modified: trunk/src/assuan-buffer.c
===================================================================
--- trunk/src/assuan-buffer.c 2007-10-05 12:24:01 UTC (rev 270)
+++ trunk/src/assuan-buffer.c 2007-10-05 16:01:12 UTC (rev 271)
@@ -51,9 +51,10 @@
return 0; /* okay */
}
-/* Read an entire line. Returns 0 on success or -1 and ERRNo on
+/* Read an entire line. Returns 0 on success or -1 and ERRNO on
failure. EOF is indictated by setting the integer at address
- R_EOF. */
+ R_EOF. Note: BUF, R_NREAD and R_EOF contain a valid result even if
+ an error is returned. */
static int
readline (assuan_context_t ctx, char *buf, size_t buflen,
int *r_nread, int *r_eof)
@@ -132,12 +133,23 @@
&nread, &ctx->inbound.eof);
if (rc)
{
+ int saved_errno = errno;
+
if (ctx->log_fp)
- fprintf (ctx->log_fp, "%s[%u.%d] DBG: <- [Error: %s]\n",
+ fprintf (ctx->log_fp, "%s[%u.%d] DBG: <- [Error: %s]\n",
assuan_get_assuan_log_prefix (),
(unsigned int)getpid (), (int)ctx->inbound.fd,
strerror (errno));
-
+
+ if (saved_errno == EAGAIN)
+ {
+ /* We have to save a partial line. */
+ memcpy (ctx->inbound.attic.line, line, atticlen + nread);
+ ctx->inbound.attic.pending = 0;
+ ctx->inbound.attic.linelen = atticlen + nread;
+ }
+
+ errno = saved_errno;
return _assuan_error (ASSUAN_Read_Error);
}
if (!nread)
Modified: trunk/src/assuan-defs.h
===================================================================
--- trunk/src/assuan-defs.h 2007-10-05 12:24:01 UTC (rev 270)
+++ trunk/src/assuan-defs.h 2007-10-05 16:01:12 UTC (rev 271)
@@ -305,8 +305,10 @@
int _assuan_sock_get_nonce (struct sockaddr *addr, int addrlen,
assuan_sock_nonce_t *nonce);
int _assuan_sock_check_nonce (assuan_fd_t fd, assuan_sock_nonce_t *nonce);
+#ifdef HAVE_W32_SYSTEM
+int _assuan_sock_wsa2errno (int err);
+#endif
-
#ifdef HAVE_FOPENCOOKIE
/* We have to implement funopen in terms of glibc's fopencookie. */
FILE *_assuan_funopen(void *cookie,
Modified: trunk/src/assuan-socket.c
===================================================================
--- trunk/src/assuan-socket.c 2007-10-05 12:24:01 UTC (rev 270)
+++ trunk/src/assuan-socket.c 2007-10-05 16:01:12 UTC (rev 271)
@@ -57,8 +57,25 @@
#ifdef HAVE_W32_SYSTEM
+int
+_assuan_sock_wsa2errno (int err)
+{
+ switch (err)
+ {
+ case WSAENOTSOCK:
+ return EINVAL;
+ case WSAEWOULDBLOCK:
+ return EAGAIN;
+ case ERROR_BROKEN_PIPE:
+ return EPIPE;
+ default:
+ return EIO;
+ }
+}
+
+
/* W32: Fill BUFFER with LENGTH bytes of random. Returns -1 on
- failure, 0 on success. */
+ failure, 0 on success. Sets errno on failure. */
static int
get_nonce (char *buffer, size_t nbytes)
{
@@ -81,7 +98,7 @@
/* W32: The buffer for NONCE needs to be at least 16 bytes. Returns 0 on
- success. */
+ success and sets errno on failure. */
static int
read_port_and_nonce (const char *fname, unsigned short *port, char *nonce)
{
@@ -128,9 +145,14 @@
{
#ifdef HAVE_W32_SYSTEM
int rc = closesocket (HANDLE2SOCKET(fd));
+ if (rc)
+ errno = _assuan_sock_wsa2errno (WSAGetLastError ());
if (rc && WSAGetLastError () == WSAENOTSOCK)
{
rc = CloseHandle (fd);
+ if (rc)
+ /* FIXME. */
+ errno = EIO;
}
return rc;
#else
@@ -146,9 +168,13 @@
_assuan_sock_new (int domain, int type, int proto)
{
#ifdef HAVE_W32_SYSTEM
+ int res;
if (domain == AF_UNIX || domain == AF_LOCAL)
domain = AF_INET;
- return SOCKET2HANDLE(socket (domain, type, proto));
+ res = SOCKET2HANDLE(socket (domain, type, proto));
+ if (res < 0)
+ errno = _assuan_sock_wsa2errno (WSAGetLastError ());
+ return res;
#else
return socket (domain, type, proto);
#endif
@@ -195,7 +221,13 @@
return ret;
}
else
- return connect (HANDLE2SOCKET (sockfd), addr, addrlen);
+ {
+ int res;
+ res = connect (HANDLE2SOCKET (sockfd), addr, addrlen);
+ if (res < 0)
+ errno = _assuan_sock_wsa2errno (WSAGetLastError ());
+ return res;
+ }
#else
return connect (sockfd, addr, addrlen);
#endif
@@ -262,7 +294,12 @@
return 0;
}
else
- return bind (HANDLE2SOCKET(sockfd), addr, addrlen);
+ {
+ int res = bind (HANDLE2SOCKET(sockfd), addr, addrlen);
+ if (res < 0)
+ errno = _assuan_sock_wsa2errno (WSAGetLastError ());
+ return res;
+ }
#else
return bind (sockfd, addr, addrlen);
#endif
Modified: trunk/src/assuan-uds.c
===================================================================
--- trunk/src/assuan-uds.c 2007-10-05 12:24:01 UTC (rev 270)
+++ trunk/src/assuan-uds.c 2007-10-05 16:01:12 UTC (rev 271)
@@ -63,25 +63,6 @@
#endif /*USE_DESCRIPTOR_PASSING*/
-#ifdef HAVE_W32_SYSTEM
-int
-wsa2errno (int err)
-{
- switch (err)
- {
- case WSAENOTSOCK:
- return EINVAL;
- case WSAEWOULDBLOCK:
- return EAGAIN;
- case ERROR_BROKEN_PIPE:
- return EPIPE;
- default:
- return EIO;
- }
-}
-#endif
-
-
/* Read from a unix domain socket using sendmsg.
FIXME: We don't need the buffering. It is a leftover from the time
@@ -173,7 +154,7 @@
#else /*HAVE_W32_SYSTEM*/
int res = recvfrom (HANDLE2SOCKET(ctx->inbound.fd), buf, buflen, 0, NULL, NULL);
if (res < 0)
- errno = wsa2errno (WSAGetLastError ());
+ errno = _assuan_sock_wsa2errno (WSAGetLastError ());
return res;
#endif /*HAVE_W32_SYSTEM*/
}
@@ -205,7 +186,7 @@
(struct sockaddr *)&ctx->serveraddr,
sizeof (struct sockaddr_in));
if (res < 0)
- errno = wsa2errno (WSAGetLastError ());
+ errno = _assuan_sock_wsa2errno (WSAGetLastError ());
return res;
#endif /*HAVE_W32_SYSTEM*/
}
More information about the Gnupg-commits
mailing list