Mercurial > repos > rhope
annotate net.rhope @ 180:c40e0faa1c92
Add Call to Dict and List
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 19 Jun 2011 10:43:11 -0700 |
parents | 1bfc19076f1b |
children |
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 { |
164
429afd920a23
Allow sending and receiving arrays of arbitrary objects rather than just UInt8s
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
312 If[[Raw Size[[buffer]Eltype >>]] > [1]] |
429afd920a23
Allow sending and receiving arrays of arbitrary objects rather than just UInt8s
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
313 { |
429afd920a23
Allow sending and receiving arrays of arbitrary objects rather than just UInt8s
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
314 bytelen <- [[buffer]Length]*[Raw Size[[buffer]Eltype >>]] |
429afd920a23
Allow sending and receiving arrays of arbitrary objects rather than just UInt8s
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
315 //Copy to a byte buffer until we have a better way of writing from an arbitrary byte offset |
429afd920a23
Allow sending and receiving arrays of arbitrary objects rather than just UInt8s
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
316 bbuffer <- [_internal_array_copychunk[buffer, 0, _internal_array_allocnaked[bytelen, UInt8()], 0, [buffer]Length]]Length <<[bytelen] |
429afd920a23
Allow sending and receiving arrays of arbitrary objects rather than just UInt8s
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
317 }{ |
429afd920a23
Allow sending and receiving arrays of arbitrary objects rather than just UInt8s
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
318 bbuffer <- Val[buffer] |
429afd920a23
Allow sending and receiving arrays of arbitrary objects rather than just UInt8s
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
319 } |
429afd920a23
Allow sending and receiving arrays of arbitrary objects rather than just UInt8s
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
320 out,err <- [con]_Write[bbuffer,0] |
143
ff00538cd818
Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents:
142
diff
changeset
|
321 }{ |
ff00538cd818
Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents:
142
diff
changeset
|
322 out <- con |
ff00538cd818
Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents:
142
diff
changeset
|
323 } |
ff00538cd818
Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents:
142
diff
changeset
|
324 } |
ff00538cd818
Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents:
142
diff
changeset
|
325 |
144
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
326 _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
|
327 { |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
328 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
|
329 { numread <- Trunc Int32[~] } |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
330 { outbuf <- [~]Length <<[numread] } |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
331 If[[numread]=[-1]] |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
332 { |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
333 If[Wait for IO[[con]Filedes >>, 1]] |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
334 { |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
335 data,out con,err <- [con]_Read[toread,buflist] |
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 err <- Fold[_Add Len[?], 0, buflist] |
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 If[[numread]=[toread]] |
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 data <- [buflist]Append[outbuf] |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
343 out con <- con |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
344 }{ |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
345 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
|
346 } |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
347 } |
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 |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
350 _Add Len[len,buf:out] |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
351 { |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
352 out <- [len]+[[buf]Length] |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
353 } |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
354 |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
355 _Merge One Buf[inprog,src:out] |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
356 { |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
357 oldlen <- [inprog]Length |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
358 srclen <- [src]Length |
145
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
359 If[srclen] |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
360 { |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
361 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
|
362 }{ |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
363 out <- inprog |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
364 } |
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 |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
367 _Merge Buffers[buflist:out] |
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 If[[[buflist]Length]=[1]] |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
370 { |
145
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
371 out <- [buflist]Index[0]{} |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
372 { Print["This shouldn't happen!!!!"] } |
144
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
373 }{ |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
374 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
|
375 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
|
376 } |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
377 } |
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 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
|
380 { |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
381 buflen <- [[con]Read Buffer >>]Length |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
382 If[[toread]=[buflen]] |
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 data <- [con]Read Buffer >> |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
385 out con <- [con]Read Buffer <<[Array[]] |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
386 }{ |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
387 If[[toread]<[buflen]] |
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 data <- [[con]Read Buffer >>]Slice[toread] {} |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
390 { out con <- [con]Read Buffer <<[~] } |
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 If[buflen] |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
393 { |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
394 buflist <- [()]Append[[con]Read Buffer >>] |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
395 ntoread <- [toread]-[[[con]Read Buffer >>]Length] |
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 ntoread <- Val[toread] |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
398 buflist <- () |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
399 } |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
400 ,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
|
401 { data <- _Merge Buffers[~] } |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
402 } |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
403 } |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
404 } |
65ebd1ce2611
Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents:
143
diff
changeset
|
405 |
164
429afd920a23
Allow sending and receiving arrays of arbitrary objects rather than just UInt8s
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
406 Read Type@TCP Connection[con,toread(Int32),type(Blueprint):data,out con,err] |
429afd920a23
Allow sending and receiving arrays of arbitrary objects rather than just UInt8s
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
407 { |
429afd920a23
Allow sending and receiving arrays of arbitrary objects rather than just UInt8s
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
408 toreadbytes <- [toread]*[Raw Size[type]] |
429afd920a23
Allow sending and receiving arrays of arbitrary objects rather than just UInt8s
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
409 ,out con,err <- [con]Read[toreadbytes] |
429afd920a23
Allow sending and receiving arrays of arbitrary objects rather than just UInt8s
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
410 { |
429afd920a23
Allow sending and receiving arrays of arbitrary objects rather than just UInt8s
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
411 data <- [_internal_array_copychunk[~, 0, _internal_array_allocnaked[toread, type], 0, toreadbytes]]Length <<[toread] |
429afd920a23
Allow sending and receiving arrays of arbitrary objects rather than just UInt8s
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
412 } |
429afd920a23
Allow sending and receiving arrays of arbitrary objects rather than just UInt8s
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
413 } |
429afd920a23
Allow sending and receiving arrays of arbitrary objects rather than just UInt8s
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
414 |
145
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
415 _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
|
416 { |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
417 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
|
418 { |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
419 left <- [[buffer]Length]-[offset] |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
420 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
|
421 { |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
422 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
|
423 }{ |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
424 partial <- offset |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
425 } |
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 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
|
430 { |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
431 dlen <- [delim]Length |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
432 blen <- [buffer]Length |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
433 If[[[offset]+[dlen]]<=[blen]] |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
434 { |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
435 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
|
436 { |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
437 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
|
438 }{ |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
439 out <- offset |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
440 } |
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 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
|
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 |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
446 _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
|
447 { |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
448 ,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
|
449 { |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
450 left <- [[old]Length]-[offset] |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
451 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
|
452 { |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
453 next <- [offset]+[1] |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
454 }{ |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
455 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
|
456 { |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
457 next <- [offset]+[1] |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
458 }{ |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
459 out <- offset |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
460 } |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
461 } |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
462 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
|
463 } |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
464 } |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
465 |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
466 _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
|
467 { |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
468 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
|
469 { numread <- Trunc Int32[~] } |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
470 { outbuf <- [~]Length <<[numread] } |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
471 |
165
47ab97730865
Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
472 If[[numread]<[1]] |
145
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
473 { |
165
47ab97730865
Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
474 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
|
475 { |
165
47ab97730865
Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
476 ,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
|
477 { |
47ab97730865
Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
478 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
|
479 } |
47ab97730865
Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
480 } |
47ab97730865
Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
481 Val[doerr] |
47ab97730865
Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
482 { |
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
|
483 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
|
484 } |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
485 }{ |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
486 ,checknew <- If[[poffset]>=[0]] |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
487 { |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
488 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
|
489 { |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
490 //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
|
491 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
|
492 _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
|
493 ] |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
494 ]Read Delim[delim] |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
495 }{ |
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
|
496 ,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
|
497 { |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
498 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
|
499 ]Length <<[~] |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
500 |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
501 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
|
502 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
|
503 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
|
504 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
|
505 [_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
|
506 _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
|
507 ]Length <<[rbufferlen] |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
508 ] |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
509 } |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
510 } |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
511 } |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
512 Val[checknew] |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
513 { |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
514 ,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
|
515 { |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
516 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
|
517 ]Length <<[~] |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
518 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
|
519 { |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
520 |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
521 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
|
522 }{ |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
523 tomerge <- [buflist]Append[before] |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
524 } |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
525 data <- _Merge Buffers[tomerge] |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
526 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
|
527 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
|
528 [_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
|
529 _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
|
530 ]Length <<[rbufferlen] |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
531 ] |
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 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
|
534 { |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
535 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
|
536 }{ |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
537 nbuflist <- Val[buflist] |
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 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
|
540 }{ |
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
|
541 npoffset <- -1 |
145
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
542 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
|
543 { |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
544 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
|
545 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
|
546 }{ |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
547 nbuflist <- [buflist]Append[outbuf] |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
548 ncon <- Val[con] |
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 } |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
552 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
|
553 } |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
554 } |
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 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
|
557 { |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
558 ,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
|
559 { |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
560 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
|
561 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
|
562 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
|
563 [_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
|
564 _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
|
565 ]Length <<[rbufferlen] |
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 }{ |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
568 buflist <- () |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
569 ncon <- Val[con] |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
570 }{ |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
571 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
|
572 { |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
573 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
|
574 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
|
575 }{ |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
576 ncon <- Val[con] |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
577 buflist <- () |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
578 } |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
579 poffset <- -1 |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
580 |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
581 } |
165
47ab97730865
Fix a couple of issues in networking lib
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
582 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
|
583 } |
357f4ce3ca6d
Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
584 |
143
ff00538cd818
Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents:
142
diff
changeset
|
585 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
|
586 { |
ff00538cd818
Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents:
142
diff
changeset
|
587 out <- close[[con]Filedes >>] |
ff00538cd818
Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents:
142
diff
changeset
|
588 } |
ff00538cd818
Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents:
142
diff
changeset
|
589 |
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
|
590 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
|
591 { |
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 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
|
593 } |
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 _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
|
596 { |
e9a8269384bb
Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
597 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
|
598 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
|
599 } |
e9a8269384bb
Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
600 |
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
|
601 //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
|
602 //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
|
603 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
|
604 { |
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
|
605 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
|
606 } |
7bbdc034e347
Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
607 |
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
|
608 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
|
609 { |
e9a8269384bb
Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
610 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
|
611 } |
e9a8269384bb
Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents:
147
diff
changeset
|
612 |