1 /* assuan-io.c - Wraps the read and write functions.
2 * Copyright (C) 2002, 2004, 2006 Free Software Foundation, Inc.
4 * This file is part of Assuan.
6 * Assuan is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
11 * Assuan is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
27 #include <sys/types.h>
28 #ifdef HAVE_SYS_SOCKET_H
29 # include <sys/socket.h>
33 #ifdef HAVE_W32_SYSTEM
36 # include <sys/wait.h>
39 #include "assuan-defs.h"
42 #ifndef HAVE_W32_SYSTEM
44 _assuan_waitpid (pid_t pid, int *status, int options)
46 return waitpid (pid, status, options);
52 _assuan_simple_read (assuan_context_t ctx, void *buffer, size_t size)
54 #ifdef HAVE_W32_SYSTEM
55 /* Due to the peculiarities of the W32 API we can't use read for a
56 network socket and thus we try to use recv first and fallback to
57 read if recv detects that it is not a network socket. */
60 n = recv (ctx->inbound.fd, buffer, size, 0);
61 if (n == -1 && WSAGetLastError () == WSAENOTSOCK)
65 n = ReadFile ((HANDLE)ctx->inbound.fd, buffer, size, &nread, NULL);
68 errno = EIO; /* FIXME: We should have a proper mapping. */
75 #else /*!HAVE_W32_SYSTEM*/
76 return read (ctx->inbound.fd, buffer, size);
77 #endif /*!HAVE_W32_SYSTEM*/
81 _assuan_simple_write (assuan_context_t ctx, const void *buffer, size_t size)
83 #ifdef HAVE_W32_SYSTEM
84 /* Due to the peculiarities of the W32 API we can't use write for a
85 network socket and thus we try to use send first and fallback to
86 write if send detects that it is not a network socket. */
89 n = send (ctx->outbound.fd, buffer, size, 0);
90 if (n == -1 && WSAGetLastError () == WSAENOTSOCK)
94 n = WriteFile ((HANDLE)ctx->outbound.fd, buffer, size, &nwrite, NULL);
97 errno = EIO; /* FIXME: We should have a proper mapping. */
104 #else /*!HAVE_W32_SYSTEM*/
105 return write (ctx->outbound.fd, buffer, size);
106 #endif /*!HAVE_W32_SYSTEM*/
110 #ifdef HAVE_W32_SYSTEM
112 _assuan_simple_sendmsg (assuan_context_t ctx, void *msg)
115 _assuan_simple_sendmsg (assuan_context_t ctx, struct msghdr *msg)
118 #ifdef HAVE_W32_SYSTEM
119 return _assuan_error (ASSUAN_Not_Implemented);
122 while ( (ret = sendmsg (ctx->outbound.fd, msg, 0)) == -1 && errno == EINTR)
129 #ifdef HAVE_W32_SYSTEM
131 _assuan_simple_recvmsg (assuan_context_t ctx, void *msg)
134 _assuan_simple_recvmsg (assuan_context_t ctx, struct msghdr *msg)
137 #ifdef HAVE_W32_SYSTEM
138 return _assuan_error (ASSUAN_Not_Implemented);
141 while ( (ret = recvmsg (ctx->inbound.fd, msg, 0)) == -1 && errno == EINTR)