annotate net.rhope @ 165:47ab97730865

Fix a couple of issues in networking lib
author Mike Pavone <pavone@retrodev.com>
date Thu, 10 Mar 2011 04:15:37 +0000
parents e9a8269384bb
children 1bfc19076f1b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
142
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
2 Foreign C:libc
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
3 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
4 setsockopt[sockfd(Int32,Naked),level(Int32,Naked),optname(Int32,Naked),optval(Int32,Raw Pointer),optlen(Int32,Naked):out(Int32,Naked)]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
5 listen[sockfd(Int32,Naked),backlog(Int32,Naked):out(Int32,Naked)]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
6 send[sockfd(Int32,Naked),data(Array,Raw Pointer),datalen(Int64,Naked):out(Int32,Naked)]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
7 recv[sockfd(Int32,Naked),data(Array,Raw Pointer,Mutable),maxlen(Int64,Naked):out(Int32,Naked),data]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
8 fcntl[fd(Int32,Naked),command(Int32,Naked),value(Int64,Naked):out(Int32,Naked)]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
9 pipe[descriptors(Array,Raw Pointer,Mutable):out(Int32,Naked),descriptors]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
10 epoll_create[size(Int32,Naked):status(Int32,Naked)]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
11 epoll_ctl[epfd(Int32,Naked),operation(Int32,Naked),fd(Int32,Naked),event(epoll_event,Raw Pointer):status(Int32,Naked)]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
12 epoll_wait[epfd(Int32,Naked),events(Array,Raw Pointer,Mutable),maxevents(Int32,Naked),timeout(Int32,Naked):out(Int32,Naked),events]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
13 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
14
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
15
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
16 //Note: port numbers would more properly be UInt16, think about changing later
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
17 Foreign C:runtime
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
18 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
19 _internal_bindnewsocket[port(Int32,Naked),setreuse(Int32,Naked):socket(Int32,Naked)]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
20 _internal_accept[sockfd(Int32,Naked),addrbuf(Array,Raw Pointer,Mutable),buflen(Int32,Naked):consock(Int32,Naked),addrbuf]
152
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
21 _internal_connectnewsocket[addr(Array,Raw Pointer),port(Int32,Naked):sockfd(Int32,Naked)]
165
47ab97730865 Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
22 _internal_ignoresigpipe[:out(Int32,Naked)]
142
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
23 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
24
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
25 Blueprint epoll_event
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
26 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
27 events(UInt32,Naked)
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
28 data(Int64,Naked)
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
29 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
30
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
31 //EPOLLIN 1
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
32 //EPOLLOUT 4
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
33 //EPOLLPRI 2
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
34 //EPOLL_CTL_ADD 1
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
35 //EPOLL_CTL_DEL 2
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
36 //EPOLL_CTL_MOD 3
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
37
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
38 _Add New FDs[epfd,pipefd:out]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
39 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
40 count,rdata <- read[pipefd, _internal_array_allocnaked[2,Int32()], 8i64]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
41 ,out <- If[[count]=[8i64]]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
42 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
43 data <- [rdata]Length <<[2]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
44 epoll_ctl[epfd, 1i32, [data]Index[0], [[Build[epoll_event()]]events <<[Abs UInt[[data]Index[1]]]]data <<[Int64[[data]Index[0]]]]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
45 { out <- _Add New FDs[epfd,pipefd] }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
46 }{
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
47 //TODO: Properly deal with the case when count > 0 but < 8
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
48 If[[count]>[0i64]]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
49 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
50 Print[["read of listener pipe returned unexpected number of bytes: "]Append[String[count]]]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
51 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
52 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
53 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
54
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
55 _Get IO Context[fd:out,notfound] uses socklisten
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
56 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
57 out,notfound <- [socklisten::fdlookup]Index[fd]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
58 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
59
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
60 _Handle Events[epfd,pipefd,buf,cur:out]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
61 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
62 event,out <- [buf]Index[cur]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
63 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
64 If[[event]data >>]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
65 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
66 activefd <- Trunc Int32[[event]data >>]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
67 epoll_ctl[epfd, 2, activefd, Build[epoll_event()]]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
68 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
69 If[[[event]events >>]&[8216u32]]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
70 { res <- No }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
71 { res <- Yes }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
72 ct,cont <- _Get IO Context[activefd]
165
47ab97730865 Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
73 {
142
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
74 }{ Print["Could not find context for IO event"] }
165
47ab97730865 Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
75
142
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
76 ,cont <- Resume[ct,res]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
77 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
78 cont <- Yield[]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
79 }{
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
80 Print["could not resume context for IO event"]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
81 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
82 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
83 }{
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
84 cont <- _Add New FDs[epfd,pipefd]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
85 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
86 Val[cont]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
87 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
88 out <- _Handle Events[epfd,pipefd,buf,[cur]+[1]]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
89 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
90 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
91 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
92
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
93 _Wait Active[epfd,pipefd,buf]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
94 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
95 workaround <- Yield[]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
96 Val[workaround]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
97 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
98 count,newbuf <- epoll_wait[epfd,buf,[buf]Storage >>,-1]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
99 If[[count]=[-1]]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
100 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
101 Print["epoll_wait returned error"]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
102 }{
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
103 If[[count]=[0]]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
104 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
105 //Shouldn't happen normally, but perhaps if there was a signal
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
106 _Wait Active[epfd,pipefd,buf]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
107 }{
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
108 _Handle Events[epfd,pipefd,[newbuf]Length <<[count],0]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
109 { _Wait Active[epfd,pipefd,buf] }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
110 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
111 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
112 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
113 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
114
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
115 _Sock Listener[pipefd]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
116 {
165
47ab97730865 Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
117 _internal_ignoresigpipe[]
142
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
118 epfd <- epoll_create[16]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
119 If[[epfd]=[-1]]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
120 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
121 Print["Error creating epoll file descriptor"]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
122 }{
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
123 If[[epoll_ctl[epfd,1i32,pipefd,[[Build[epoll_event()]]events <<[1u32]]data <<[0i64]]]=[-1]]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
124 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
125 Print["Error adding pipe to epoll fd"]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
126 }{
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
127 _Wait Active[epfd, pipefd, _internal_array_allocnaked[8,epoll_event()]]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
128 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
129 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
130 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
131
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
132 Globals socklisten
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
133 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
134 listener started <- No
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
135 fdlookup <- ()
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
136 pipefd <- -1
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
137 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
138
165
47ab97730865 Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
139 __Add FD to Listener[fd,context:pipefd,err,startpipe] uses socklisten
142
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
140 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
141 If[socklisten::listener started]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
142 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
143 pipefd <- socklisten::pipefd
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
144 do add <- Yes
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
145 }{
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
146 //Calling a function with side effects inside a transaction is BAD
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
147 //Need to do something about this
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
148 ret,des <- pipe[[Array[]]Set[1, 0i32]]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
149 If[[ret]=[-1]]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
150 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
151 err <- "Error creating pipe for waking up socket listener"
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
152 }{
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
153 socklisten::pipefd <- [des]Index[1]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
154 pipefd <- [des]Index[1]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
155 //fcntl[fd, F_SETFL, O_NONBLOCK]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
156 //Set both ends of the pipe to non blocking
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
157 fcntl[[des]Index[0], 4i32, 2048i64]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
158 fcntl[[des]Index[1], 4i32, 2048i64]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
159 socklisten::listener started <- Yes
165
47ab97730865 Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
160 startpipe <- [des]Index[0]
142
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
161 do add <- Yes
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
162 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
163 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
164 Val[do add]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
165 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
166 socklisten::fdlookup <- [socklisten::fdlookup]Set[fd, context]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
167 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
168 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
169
165
47ab97730865 Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
170 _Add FD to Listener[fd,context:pipefd,err]
47ab97730865 Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
171 {
47ab97730865 Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
172 pipefd,err <- __Add FD to Listener[fd,context] {} {}
47ab97730865 Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
173 { Call Async[_Sock Listener[~,?]] }
47ab97730865 Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
174 }
47ab97730865 Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
175
142
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
176 _Write to Listener Pipe[pipefd,data]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
177 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
178 res <- write[pipefd, data, 8i64]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
179 If[[res]!=[8i32]]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
180 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
181 workaround <- Yield[]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
182 Val[workaround]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
183 { _Write to Listener Pipe[pipefd,data] }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
184 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
185 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
186
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
187 _Wait for IO[fd,type,context]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
188 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
189 _Add FD to Listener[fd,context]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
190 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
191 _Write to Listener Pipe[~,[[Array[]]Append[fd]]Append[type]]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
192 }{
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
193 Print[~]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
194 { Resume[context,No] }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
195 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
196 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
197
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
198 Wait for IO[fd,type:out]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
199 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
200 out <- Pause[_Wait for IO[fd,type,?]]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
201 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
202
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
203 _Do Con Call[newfd,address,tocall]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
204 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
205 [tocall]Call[newfd,address]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
206 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
207
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
208 _Null Term[raw str,cur:out]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
209 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
210 [raw str]Index[cur]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
211 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
212 If[[~]=[0u8]]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
213 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
214 out <- String[[raw str]Length <<[cur]]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
215 }{
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
216 out <- _Null Term[raw str, [cur]+[1]]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
217 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
218 }{
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
219 out <- String[raw str]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
220 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
221 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
222
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
223 _Port Wait[fd,tocall:out]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
224 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
225 con <- _internal_accept[fd,_internal_array_allocnaked[40,UInt8()],40] {}
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
226 { address <- _Null Term[[~]Length <<[40], 0i32] }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
227 If[[con]=[-1]]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
228 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
229 If[Wait for IO[fd, 1i32]]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
230 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
231 out <- _Port Wait[fd,tocall]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
232 }{
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
233 Print["Error waiting for connection"]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
234 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
235 }{
143
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
236 fcntl[con, 4i32, 2048i64]
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
237 { Call Async[_Do Con Call[TCP Connection[con],address,tocall,?]]
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
238 { out <- _Port Wait[fd,tocall] }}
142
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
239 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
240 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
241
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
242 Listen on Port[port(Int32),tocall:out]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
243 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
244 fd <- _internal_bindnewsocket[port,1]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
245 //fcntl[fd, F_SETFL, O_NONBLOCK]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
246 //Set listen socket to non blocking
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
247 If[[fd]=[-1]]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
248 { out <- No }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
249 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
250 fcntl[fd, 4i32, 2048i64]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
251 { listen[fd,8]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
252 { out <- Call Async[_Port Wait[fd,tocall,?]] }}
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
253 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
254 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
255
143
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
256 Blueprint TCP Connection
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
257 {
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
258 Filedes
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
259 Read Buffer
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
260 }
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
261
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
262 TCP Connection[fd:out]
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
263 {
144
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
264 out <- [[Build[TCP Connection()]
143
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
265 ]Filedes <<[fd]
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
266 ]Read Buffer <<[Array[]]
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
267 }
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
268
152
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
269 TCP Connect[address,port:out,err]
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
270 {
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
271 addrbuf <- [[Flatten[address]]Buffer >>]Append[0u8]
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
272 fd <- _internal_connectnewsocket[addrbuf, port]
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
273 err <- If[[fd]=[-1]] {}
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
274 {
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
275 fcntl[fd, 4i32, 2048i64]
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
276 out <- TCP Connection[fd]
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
277 }
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
278 }
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
279
143
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
280 _Write@TCP Connection[con,buffer,wrote:out,err]
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
281 {
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
282 new wrote <- write[[con]Filedes >>, buffer, Int64[[buffer]Length]]
165
47ab97730865 Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
283 If[[new wrote]<[1]]
143
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
284 {
165
47ab97730865 Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
285 ,doerr <- If[new wrote]
143
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
286 {
165
47ab97730865 Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
287 ,doerr <- If[Wait for IO[[con]Filedes >>, 4]]
47ab97730865 Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
288 {
47ab97730865 Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
289 out,err <- [con]_Write[buffer,wrote]
47ab97730865 Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
290 }
47ab97730865 Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
291 }
47ab97730865 Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
292 Val[doerr]
47ab97730865 Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
293 {
143
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
294 err <- wrote
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
295 }
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
296 }{
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
297 If[[new wrote]=[[buffer]Length]]
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
298 {
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
299 out <- con
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
300 }{
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
301 remaining <- [[buffer]Length]-[new wrote]
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
302 next buf <- [_internal_array_copychunk[buffer, new wrote, _internal_array_allocnaked[remaining,UInt8()], 0, remaining]]Length <<[remaining]
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
303 out,err <- [con]_Write[next buf,[wrote]+[new wrote]]
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
304 }
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
305 }
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
306 }
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
307
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
308 Write@TCP Connection[con,buffer(Array):out,err]
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
309 {
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
310 If[[buffer]Length]
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
311 {
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
312 out,err <- [con]_Write[buffer,0]
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
313 }{
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
314 out <- con
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
315 }
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
316 }
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
317
144
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
318 _Read@TCP Connection[con,toread,buflist:data,out con,err]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
319 {
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
320 read[[con]Filedes >>, _internal_array_allocnaked[toread, UInt8()], Int64[toread]]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
321 { numread <- Trunc Int32[~] }
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
322 { outbuf <- [~]Length <<[numread] }
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
323 If[[numread]=[-1]]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
324 {
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
325 If[Wait for IO[[con]Filedes >>, 1]]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
326 {
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
327 data,out con,err <- [con]_Read[toread,buflist]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
328 }{
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
329 err <- Fold[_Add Len[?], 0, buflist]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
330 }
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
331 }{
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
332 If[[numread]=[toread]]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
333 {
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
334 data <- [buflist]Append[outbuf]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
335 out con <- con
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
336 }{
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
337 data,out con,err <- [con]_Read[[toread]-[numread], [buflist]Append[outbuf]]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
338 }
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
339 }
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
340 }
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
341
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
342 _Add Len[len,buf:out]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
343 {
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
344 out <- [len]+[[buf]Length]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
345 }
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
346
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
347 _Merge One Buf[inprog,src:out]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
348 {
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
349 oldlen <- [inprog]Length
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
350 srclen <- [src]Length
145
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
351 If[srclen]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
352 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
353 out <- [_internal_array_copychunk[src, 0, inprog, oldlen, srclen]]Length <<[[oldlen]+[srclen]]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
354 }{
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
355 out <- inprog
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
356 }
144
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
357 }
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
358
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
359 _Merge Buffers[buflist:out]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
360 {
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
361 If[[[buflist]Length]=[1]]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
362 {
145
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
363 out <- [buflist]Index[0]{}
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
364 { Print["This shouldn't happen!!!!"] }
144
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
365 }{
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
366 len <- Fold[_Add Len[?], 0, buflist]
145
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
367 out <- Fold[_Merge One Buf[?], _internal_array_allocnaked[len, UInt8()], buflist]
144
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
368 }
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
369 }
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
370
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
371 Read@TCP Connection[con,toread(Int32):data,out con,err]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
372 {
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
373 buflen <- [[con]Read Buffer >>]Length
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
374 If[[toread]=[buflen]]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
375 {
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
376 data <- [con]Read Buffer >>
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
377 out con <- [con]Read Buffer <<[Array[]]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
378 }{
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
379 If[[toread]<[buflen]]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
380 {
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
381 data <- [[con]Read Buffer >>]Slice[toread] {}
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
382 { out con <- [con]Read Buffer <<[~] }
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
383 }{
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
384 If[buflen]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
385 {
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
386 buflist <- [()]Append[[con]Read Buffer >>]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
387 ntoread <- [toread]-[[[con]Read Buffer >>]Length]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
388 }{
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
389 ntoread <- Val[toread]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
390 buflist <- ()
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
391 }
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
392 ,out con,err <- [[con]Read Buffer <<[Array[]]]_Read[ntoread,buflist]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
393 { data <- _Merge Buffers[~] }
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
394 }
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
395 }
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
396 }
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
397
145
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
398 _Check Partial[buffer,delim,offset:partial,none]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
399 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
400 none <- If[[offset]=[[buffer]Length]] {}
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
401 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
402 left <- [[buffer]Length]-[offset]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
403 If[_internal_memcmp_offset[buffer, offset, delim, 0, left]]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
404 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
405 partial,none <- _Check Partial[buffer,delim,[offset]+[1]]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
406 }{
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
407 partial <- offset
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
408 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
409 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
410 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
411
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
412 _Check Buffer[buffer,delim,offset:out,partial,none]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
413 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
414 dlen <- [delim]Length
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
415 blen <- [buffer]Length
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
416 If[[[offset]+[dlen]]<=[blen]]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
417 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
418 If[_internal_memcmp_offset[buffer, offset, delim, 0, dlen]]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
419 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
420 out,partial,none <- _Check Buffer[buffer,delim,[offset]+[1]]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
421 }{
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
422 out <- offset
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
423 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
424 }{
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
425 partial,none <- _Check Partial[buffer,delim,offset]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
426 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
427 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
428
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
429 _Check Split[old,new,delim,offset:out,not split]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
430 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
431 ,not split <- If[[offset]<[[old]Length]]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
432 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
433 left <- [[old]Length]-[offset]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
434 If[_internal_memcmp_offset[old, offset, delim, 0, left]]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
435 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
436 next <- [offset]+[1]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
437 }{
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
438 If[_internal_memcmp_offset[new, 0, delim, left, [[delim]Length]-[left]]]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
439 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
440 next <- [offset]+[1]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
441 }{
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
442 out <- offset
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
443 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
444 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
445 out,not split <- _Check Split[old,new,delim,next]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
446 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
447 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
448
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
449 _Read Delim@TCP Connection[con,delim,poffset,buflist:data,out con,err]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
450 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
451 read[[con]Filedes >>, _internal_array_allocnaked[512i32, UInt8()], 512i64]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
452 { numread <- Trunc Int32[~] }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
453 { outbuf <- [~]Length <<[numread] }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
454
165
47ab97730865 Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
455 If[[numread]<[1]]
145
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
456 {
165
47ab97730865 Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
457 doerr <- If[[numread]=[0]] {}
145
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
458 {
165
47ab97730865 Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
459 ,doerr <- If[Wait for IO[[con]Filedes >>, 1]]
47ab97730865 Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
460 {
47ab97730865 Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
461 data,out con,err <- [con]_Read Delim[delim,poffset,buflist]
47ab97730865 Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
462 }
47ab97730865 Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
463 }
47ab97730865 Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
464 Val[doerr]
47ab97730865 Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
465 {
147
f3686f60985d Sort of working port of framework. Transaction bug seems to be getting in the way. Going to work around, but want the old version in the repo so I can test later.
Mike Pavone <pavone@retrodev.com>
parents: 145
diff changeset
466 err <- [Fold[_Add Len[?], 0, buflist]]+[Length[[con]Read Buffer >>]]
145
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
467 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
468 }{
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
469 ,checknew <- If[[poffset]>=[0]]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
470 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
471 If[[[delim]Length]>[[outbuf]Length]]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
472 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
473 //Avoid possibility of having to check across more than 2 buffers
147
f3686f60985d Sort of working port of framework. Transaction bug seems to be getting in the way. Going to work around, but want the old version in the repo so I can test later.
Mike Pavone <pavone@retrodev.com>
parents: 145
diff changeset
474 data,out con,err <-[[con]Read Buffer <<[
f3686f60985d Sort of working port of framework. Transaction bug seems to be getting in the way. Going to work around, but want the old version in the repo so I can test later.
Mike Pavone <pavone@retrodev.com>
parents: 145
diff changeset
475 _Merge Buffers[[[buflist]Append[[con]Read Buffer >>]]Append[outbuf]]
145
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
476 ]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
477 ]Read Delim[delim]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
478 }{
147
f3686f60985d Sort of working port of framework. Transaction bug seems to be getting in the way. Going to work around, but want the old version in the repo so I can test later.
Mike Pavone <pavone@retrodev.com>
parents: 145
diff changeset
479 ,checknew <- _Check Split[[con]Read Buffer >>, outbuf, delim ,poffset]
145
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
480 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
481 before <- [_internal_array_copychunk[[con]Read Buffer >>, 0, _internal_array_allocnaked[~, UInt8()], 0, ~]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
482 ]Length <<[~]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
483
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
484 data <- _Merge Buffers[[buflist]Append[before]]
147
f3686f60985d Sort of working port of framework. Transaction bug seems to be getting in the way. Going to work around, but want the old version in the repo so I can test later.
Mike Pavone <pavone@retrodev.com>
parents: 145
diff changeset
485 after off <- [[delim]Length]- [[[[con]Read Buffer >>]Length]-[~]]
145
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
486 rbufferlen <- [[outbuf]Length]-[after off]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
487 out con <- [con]Read Buffer <<[
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
488 [_internal_array_copychunk[outbuf, after off,
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
489 _internal_array_allocnaked[rbufferlen, UInt8()], 0, rbufferlen]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
490 ]Length <<[rbufferlen]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
491 ]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
492 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
493 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
494 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
495 Val[checknew]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
496 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
497 ,npoffset <- _Check Buffer[outbuf,delim,0]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
498 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
499 before <- [_internal_array_copychunk[outbuf, 0, _internal_array_allocnaked[~, UInt8()], 0, ~]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
500 ]Length <<[~]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
501 If[[[con]Read Buffer >>]Length]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
502 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
503
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
504 tomerge <- [[buflist]Append[[con]Read Buffer >>]]Append[before]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
505 }{
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
506 tomerge <- [buflist]Append[before]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
507 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
508 data <- _Merge Buffers[tomerge]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
509 rbufferlen <- [[outbuf]Length]-[[~]+[[delim]Length]]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
510 out con <- [con]Read Buffer <<[
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
511 [_internal_array_copychunk[outbuf, [~]+[[delim]Length],
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
512 _internal_array_allocnaked[rbufferlen, UInt8()], 0, rbufferlen]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
513 ]Length <<[rbufferlen]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
514 ]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
515 }{
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
516 If[[[con]Read Buffer >>]Length]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
517 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
518 nbuflist <- [buflist]Append[[con]Read Buffer >>]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
519 }{
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
520 nbuflist <- Val[buflist]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
521 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
522 ncon <- [con]Read Buffer <<[outbuf]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
523 }{
152
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
524 npoffset <- -1
145
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
525 If[[[con]Read Buffer >>]Length]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
526 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
527 nbuflist <- [[buflist]Append[[con]Read Buffer >>]]Append[outbuf]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
528 ncon <- [con]Read Buffer <<[Array[]]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
529 }{
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
530 nbuflist <- [buflist]Append[outbuf]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
531 ncon <- Val[con]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
532 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
533 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
534 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
535 data,out con,err <- [ncon]_Read Delim[delim,npoffset,nbuflist]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
536 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
537 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
538
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
539 Read Delim@TCP Connection[con,delim(Array):data,out con,err]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
540 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
541 ,poffset <-_Check Buffer[[con]Read Buffer >>, delim,0]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
542 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
543 data <- [_internal_array_copychunk[[con]Read Buffer >>, 0, _internal_array_allocnaked[~, UInt8()], 0, ~]]Length <<[~]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
544 rbufferlen <- [[[con]Read Buffer >>]Length]-[[~]+[[delim]Length]]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
545 out con <- [con]Read Buffer <<[
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
546 [_internal_array_copychunk[[con]Read Buffer >>, [~]+[[delim]Length],
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
547 _internal_array_allocnaked[rbufferlen, UInt8()], 0, rbufferlen]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
548 ]Length <<[rbufferlen]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
549 ]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
550 }{
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
551 buflist <- ()
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
552 ncon <- Val[con]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
553 }{
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
554 If[[[con]Read Buffer >>]Length]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
555 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
556 ncon <- [con]Read Buffer <<[Array[]]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
557 buflist <- [()]Append[[con]Read Buffer >>]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
558 }{
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
559 ncon <- Val[con]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
560 buflist <- ()
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
561 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
562 poffset <- -1
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
563
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
564 }
165
47ab97730865 Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
565 data,out con,err <- [ncon]_Read Delim[delim,poffset,buflist] {} {}
145
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
566 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
567
143
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
568 Close@TCP Connection[con:out]
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
569 {
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
570 out <- close[[con]Filedes >>]
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
571 }
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
572
152
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
573 Globals Forever
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
574 {
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
575 Wait <- No
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
576 }
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
577
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
578 _Wait Forever[context:out] uses Forever
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
579 {
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
580 Forever::Wait <- context
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
581 out <- Yes
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
582 }
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
583
142
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
584 //This effectively leaks a context and thus any data on the stack of that context
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
585 //Need either handle cleanup of contexts or find a better way to accomplish this
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
586 Wait Forever[]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
587 {
152
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
588 Pause[_Wait Forever[?]]
142
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
589 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
590
152
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
591 Stop Waiting[] uses Forever
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
592 {
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
593 Resume[Forever::Wait, Yes]
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
594 }
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
595