2 Unix SMB/CIFS implementation.
4 Copyright (C) Stefan Metzmacher 2009
6 ** NOTE! The following LGPL license applies to the tevent
7 ** library. This does NOT imply that all of Samba is released
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 3 of the License, or (at your option) any later version.
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public
21 License along with this library; if not, see <http://www.gnu.org/licenses/>.
25 #include "system/network.h"
26 #include "system/filesys.h"
28 #include "tsocket_internal.h"
30 int tsocket_error_from_errno(int ret
,
48 if (sys_errno
== EINTR
) {
53 if (sys_errno
== EINPROGRESS
) {
58 if (sys_errno
== EAGAIN
) {
64 if (sys_errno
== EWOULDBLOCK
) {
73 int tsocket_simple_int_recv(struct tevent_req
*req
, int *perrno
)
75 enum tevent_req_state state
;
78 if (!tevent_req_is_error(req
, &state
, &error
)) {
83 case TEVENT_REQ_NO_MEMORY
:
86 case TEVENT_REQ_TIMED_OUT
:
89 case TEVENT_REQ_USER_ERROR
:
101 int tsocket_common_prepare_fd(int fd
, bool high_fd
)
114 /* first make a fd >= 3 */
124 for (i
=0; i
<num_fds
; i
++) {
133 /* fd should be nonblocking. */
136 #define FLAG_TO_SET O_NONBLOCK
139 #define FLAG_TO_SET O_NDELAY
141 #define FLAG_TO_SET FNDELAY
145 if ((flags
= fcntl(fd
, F_GETFL
)) == -1) {
149 flags
|= FLAG_TO_SET
;
150 if (fcntl(fd
, F_SETFL
, flags
) == -1) {
156 /* fd should be closed on exec() */
158 result
= flags
= fcntl(fd
, F_GETFD
, 0);
161 result
= fcntl(fd
, F_SETFD
, flags
);