-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmwrite.c
98 lines (76 loc) · 2.09 KB
/
mwrite.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "marignotti.h"
#include <gno/kerntool.h>
#include <sys/signal.h>
#include <sys/socket.h>
#include <errno.h>
#include "s16debug.h"
#pragma noroot
#pragma optimize 79
// WriteGS, send, or sendto
int mwrite(Entry *e, void *p1, void *p2, void *p3, void *p4, void *p5)
{
Word terr;
Word t;
int xerrno;
char *buffer = (char *)p1;
LongWord nbytes = *(LongWord *)p2;
xsockaddr *addr = (xsockaddr *)p3;
int addrlen = p4 ? *(int *)p4 : 0;
LongWord *outbytes = (LongWord *)p2;
*outbytes = 0;
if (Debug > 0)
{
s16_debug_printf("write nbytes = %ld", nbytes);
if (addr)
{
s16_debug_puts(" to address...");
s16_debug_dump(addr, addrlen);
}
}
if (Debug > 1)
{
s16_debug_puts("");
s16_debug_dump(buffer, (Word)nbytes);
}
if (e->_SHUT_WR) return EPIPE;
if (e->_TYPE == SOCK_DGRAM)
{
// TCPIPSendUDP builds a header
// using the source port, my ip address,
// destination port and destination ip address.
// mconnect should probably just set the destination
// address/port and exit.
// if an address was specified, we would need to
// build the udp header here.
IncBusy();
TCPIPSendUDP(e->ipid, buffer, nbytes);
t = _toolErr;
DecBusy();
if (t) return ENETDOWN;
*outbytes = nbytes;
return 0;
}
// todo -- queue up if pending >= _SNDLOWAT?
// todo -- push?
IncBusy();
terr = TCPIPWriteTCP(e->ipid, buffer, nbytes, 0, 0);
t = _toolErr;
if (t) terr = t;
e->terr = terr;
DecBusy();
if (t || terr == tcperrBadConnection)
return ENOTCONN;
if (terr == tcperrNoResources)
return ENOMEM;
if (terr == tcperrConClosing)
{
if (!e->_NOSIGPIPE)
{
int xerrno;
Kkill(Kgetpid(), SIGPIPE, &xerrno);
}
return EPIPE;
}
*outbytes = nbytes;
return 0;
}