-
Notifications
You must be signed in to change notification settings - Fork 0
/
syssock.c
77 lines (63 loc) · 1.24 KB
/
syssock.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
#include "types.h"
#include "defs.h"
#include "param.h"
#include "memlayout.h"
#include "mmu.h"
#include "x86.h"
#include "proc.h"
#include "signalcodes.h"
int
sys_listen(void) {
int port = 0;
if (argint(0, &port) < 0)
return E_MISSING_ARG;
#ifdef SO_ARG_DEBUG
cprintf(">> %d\n", port);
#endif
return listen(port);
}
int
sys_connect(void) {
int port = 0;
char *host = 0;
if (argint(0, &port) < 0 || argstr(1, &host) < 0)
return E_MISSING_ARG;
#ifdef SO_ARG_DEBUG
cprintf(">> %d %s\n", port, host);
#endif
return connect(port, host);
}
int
sys_send(void) {
int port = 0;
char *buf = 0;
int n = 0;
if (argint(0, &port) < 0 || argstr(1, &buf) < 0 || argint(0, &n) < 0)
return E_MISSING_ARG;
#ifdef SO_ARG_DEBUG
cprintf(">> %d %s %d\n", port, buf, n);
#endif
return send(port, buf, n);
}
int
sys_recv(void) {
int port = 0;
char *buf = 0;
int n = 0;
if (argint(0, &port) < 0 || argptr(1, &buf, sizeof(char *)) < 0 || argint(2, &n) < 0)
return E_MISSING_ARG;
#ifdef SO_ARG_DEBUG
cprintf(">> %d %s %d\n", port, buf, n);
#endif
return recv(port, buf, n);
}
int
sys_disconnect(void) {
int port = 0;
if (argint(0, &port) < 0)
return E_MISSING_ARG;
#ifdef SO_ARG_DEBUG
cprintf(">> %d\n", port);
#endif
return disconnect(port);
}