aboutsummaryrefslogtreecommitdiffstats
path: root/src/system-w32.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/system-w32.c')
-rw-r--r--src/system-w32.c45
1 files changed, 11 insertions, 34 deletions
diff --git a/src/system-w32.c b/src/system-w32.c
index c49d485..cfc1d61 100644
--- a/src/system-w32.c
+++ b/src/system-w32.c
@@ -147,10 +147,15 @@ __assuan_pipe (assuan_context_t ctx, assuan_fd_t fd[2], int inherit_idx)
int
__assuan_close (assuan_context_t ctx, assuan_fd_t fd)
{
- int rc = closesocket (HANDLE2SOCKET(fd));
- if (rc)
- gpg_err_set_errno ( _assuan_sock_wsa2errno (WSAGetLastError ()) );
- if (rc && WSAGetLastError () == WSAENOTSOCK)
+ int rc;
+
+ if (ctx->flags.is_socket)
+ {
+ rc = closesocket (HANDLE2SOCKET(fd));
+ if (rc)
+ gpg_err_set_errno ( _assuan_sock_wsa2errno (WSAGetLastError ()) );
+ }
+ else
{
rc = CloseHandle (fd);
if (rc)
@@ -162,41 +167,13 @@ __assuan_close (assuan_context_t ctx, assuan_fd_t fd)
-/* Return true if HD refers to a socket. */
-static int
-is_socket (HANDLE hd)
-{
- /* We need to figure out whether we are working on a socket or on a
- handle. A trivial way would be to check for the return code of
- recv and see if it is WSAENOTSOCK. However the recv may block
- after the server process died and thus the destroy_reader will
- hang. Another option is to use getsockopt to test whether it is
- a socket. The bug here is that once a socket with a certain
- values has been opened, closed and later a CreatePipe returned
- the same value (i.e. handle), getsockopt still believes it is a
- socket. What we do now is to use a combination of GetFileType
- and GetNamedPipeInfo. The specs say that the latter may be used
- on anonymous pipes as well. Note that there are claims that
- since winsocket version 2 ReadFile may be used on a socket but
- only if it is supported by the service provider. Tests on a
- stock XP using a local TCP socket show that it does not work. */
- DWORD dummyflags, dummyoutsize, dummyinsize, dummyinst;
- if (GetFileType (hd) == FILE_TYPE_PIPE
- && !GetNamedPipeInfo (hd, &dummyflags, &dummyoutsize,
- &dummyinsize, &dummyinst))
- return 1; /* Function failed; thus we assume it is a socket. */
- else
- return 0; /* Success; this is not a socket. */
-}
-
-
ssize_t
__assuan_read (assuan_context_t ctx, assuan_fd_t fd, void *buffer, size_t size)
{
int res;
int ec = 0;
- if (is_socket (fd))
+ if (ctx->flags.is_socket)
{
int tries = 3;
@@ -265,7 +242,7 @@ __assuan_write (assuan_context_t ctx, assuan_fd_t fd, const void *buffer,
int res;
int ec = 0;
- if (is_socket (fd))
+ if (ctx->flags.is_socket)
{
int tries = 3;