revert between 56095 -> 55830 in arch
[AROS.git] / arch / all-mingw32 / bsdsocket / sendto.c
blob282f7ae2ca25c81f7331946544a8fcf81c743a8f
1 /*
2 Copyright © 2000-2010, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 #define DEBUG 1
11 #include <proto/exec.h>
13 #include <sys/errno.h>
14 #include <sys/socket.h>
16 #include "bsdsocket_intern.h"
17 #include "bsdsocket_util.h"
18 #include "socket_intern.h"
20 /* FIXME: AROS libc has incorrect values in errno.h */
21 #undef EWOULDBLOCK
22 #define EWOULDBLOCK 35
24 /*****************************************************************************
26 NAME */
28 AROS_LH6(int, sendto,
30 /* SYNOPSIS */
31 AROS_LHA(int, s, D0),
32 AROS_LHA(const void *, msg, A0),
33 AROS_LHA(int, len, D1),
34 AROS_LHA(int, flags, D2),
35 AROS_LHA(const struct sockaddr *, to, A1),
36 AROS_LHA(int, tolen, D3),
38 /* LOCATION */
39 struct TaskBase *, taskBase, 12, BSDSocket)
41 /* FUNCTION
43 INPUTS
45 RESULT
47 NOTES
49 EXAMPLE
51 BUGS
53 SEE ALSO
55 INTERNALS
57 HISTORY
59 *****************************************************************************/
61 AROS_LIBFUNC_INIT
63 struct bsdsocketBase *SocketBase = taskBase->glob;
64 int res;
65 int err = 0;
66 struct WSsockaddr *sa;
67 struct Socket *sd;
69 D(bug("[sendto] Sending %u bytes to socket %u\n", len, s));
70 sd = GetSocket(s, taskBase);
71 if (!sd)
72 return -1;
74 D(bug("[sendto] Descriptor 0x%p, Windows socket %d\n", sd, sd->s));
75 sa = MakeSockAddr(to, tolen, taskBase);
76 if (!sa)
77 return -1;
79 Forbid();
81 res = WSsendto(sd->s, msg, len, flags, sa, tolen);
82 if (res == -1)
83 err = WSAGetLastError() - WSABASEERR;
85 Permit();
86 FreePooled(taskBase->pool, sa, tolen);
87 D(bug("[sendto] Result: %d, Error: %u\n", res, err));
89 /* From Windows side all sockets are asynchronous, but from AROS side
90 not all are. So if AROS socket is synchronous and Windows returned us
91 EWOULDBLOCK, we need to wait for completion */
92 if ((err == EWOULDBLOCK) && (!(sd->flags & SOF_NBIO)))
94 D(bug("[sendto] Waiting for the completion\n"));
98 if (res == -1)
99 SetError(err, taskBase);
101 return res;
103 AROS_LIBFUNC_EXIT
105 } /* sendto */