annotate net.rhope @ 152:e9a8269384bb

Add support for opening a new TCP connection and fix bug in Read Delim
author Mike Pavone <pavone@retrodev.com>
date Sun, 05 Dec 2010 18:04:54 -0500
parents f3686f60985d
children 429afd920a23 47ab97730865
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
142
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
2 Foreign C:libc
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
3 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
4 setsockopt[sockfd(Int32,Naked),level(Int32,Naked),optname(Int32,Naked),optval(Int32,Raw Pointer),optlen(Int32,Naked):out(Int32,Naked)]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
5 listen[sockfd(Int32,Naked),backlog(Int32,Naked):out(Int32,Naked)]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
6 send[sockfd(Int32,Naked),data(Array,Raw Pointer),datalen(Int64,Naked):out(Int32,Naked)]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
7 recv[sockfd(Int32,Naked),data(Array,Raw Pointer,Mutable),maxlen(Int64,Naked):out(Int32,Naked),data]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
8 fcntl[fd(Int32,Naked),command(Int32,Naked),value(Int64,Naked):out(Int32,Naked)]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
9 pipe[descriptors(Array,Raw Pointer,Mutable):out(Int32,Naked),descriptors]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
10 epoll_create[size(Int32,Naked):status(Int32,Naked)]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
11 epoll_ctl[epfd(Int32,Naked),operation(Int32,Naked),fd(Int32,Naked),event(epoll_event,Raw Pointer):status(Int32,Naked)]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
12 epoll_wait[epfd(Int32,Naked),events(Array,Raw Pointer,Mutable),maxevents(Int32,Naked),timeout(Int32,Naked):out(Int32,Naked),events]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
13 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
14
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
15
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
16 //Note: port numbers would more properly be UInt16, think about changing later
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
17 Foreign C:runtime
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
18 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
19 _internal_bindnewsocket[port(Int32,Naked),setreuse(Int32,Naked):socket(Int32,Naked)]
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
20 _internal_accept[sockfd(Int32,Naked),addrbuf(Array,Raw Pointer,Mutable),buflen(Int32,Naked):consock(Int32,Naked),addrbuf]
152
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
21 _internal_connectnewsocket[addr(Array,Raw Pointer),port(Int32,Naked):sockfd(Int32,Naked)]
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
22 }
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 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
25 {
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 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
27 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
28 }
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 //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
31 //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
32 //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
33 //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
34 //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
35 //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
36
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 _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
38 {
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 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
40 ,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
41 {
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 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
43 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
44 { 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
45 }{
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 //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
47 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
48 {
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 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
50 }
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 _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
55 {
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 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
57 }
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 _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
60 {
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 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
62 {
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 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
64 {
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 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
66 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
67 {
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 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
69 { 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
70 { 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
71 ct,cont <- _Get IO Context[activefd]
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 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
73 }{ Print["Could not find 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
74 ,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
75 {
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 <- 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
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 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
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 }
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 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
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 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
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 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
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 }
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 _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
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 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
94 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
95 {
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 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
97 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
98 {
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 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
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 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
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 //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
104 _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
105 }{
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 _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
107 { _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
108 }
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 }
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 _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
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 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
116 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
117 {
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 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
119 }{
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 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
121 {
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 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
123 }{
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 _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
125 }
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 }
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 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
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 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
132 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
133 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
134 }
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
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 _Add FD to Listener[fd,context:pipefd,err] 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
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 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
139 {
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 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
141 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
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 //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
144 //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
145 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
146 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
147 {
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 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
149 }{
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 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
151 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
152 //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
153 //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
154 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
155 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
156 socklisten::listener started <- 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
157 Call Async[_Sock Listener[[des]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
158 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
159 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
160 }
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 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
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 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
164 }
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
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 _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
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 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
170 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
171 {
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
172 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
173 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
174 { _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
175 }
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 }
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 _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
179 {
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 _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
181 {
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 _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
183 }{
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 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
185 { 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
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 }
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 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
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 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
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
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 _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
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 [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
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
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 _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
200 {
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 [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
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 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
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 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
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 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
208 }
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 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
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 }
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 _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
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 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
217 { 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
218 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
219 {
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 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
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 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
223 }{
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 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
225 }
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 }{
143
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
227 fcntl[con, 4i32, 2048i64]
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
228 { 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
229 { 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
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 }
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 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
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 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
236 //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
237 //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
238 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
239 { 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
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 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
242 { 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
243 { 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
244 }
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 }
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
143
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
247 Blueprint TCP Connection
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
248 {
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
249 Filedes
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
250 Read Buffer
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
251 }
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
252
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
253 TCP Connection[fd:out]
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
254 {
144
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
255 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
256 ]Filedes <<[fd]
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
257 ]Read Buffer <<[Array[]]
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
258 }
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
259
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
260 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
261 {
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
262 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
263 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
264 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
265 {
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
266 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
267 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
268 }
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 }
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
143
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
271 _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
272 {
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
273
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
274 new wrote <- write[[con]Filedes >>, buffer, Int64[[buffer]Length]]
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
275 If[[new wrote]=[-1]]
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
276 {
144
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
277 If[Wait for IO[[con]Filedes >>, 4]]
143
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
278 {
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
279 out,err <- [con]_Write[buffer,wrote]
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
280 }{
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
281 err <- wrote
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
282 }
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
283 }{
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
284 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
285 {
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
286 out <- con
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
287 }{
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
288 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
289 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
290 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
291 }
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
292 }
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
293 }
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
294
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
295 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
296 {
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
297 If[[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,err <- [con]_Write[buffer,0]
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
300 }{
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
301 out <- con
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
302 }
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
303 }
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
304
144
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
305 _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
306 {
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
307 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
308 { numread <- Trunc Int32[~] }
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
309 { outbuf <- [~]Length <<[numread] }
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
310 If[[numread]=[-1]]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
311 {
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
312 If[Wait for IO[[con]Filedes >>, 1]]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
313 {
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
314 data,out con,err <- [con]_Read[toread,buflist]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
315 }{
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
316 err <- Fold[_Add Len[?], 0, buflist]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
317 }
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
318 }{
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
319 If[[numread]=[toread]]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
320 {
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
321 data <- [buflist]Append[outbuf]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
322 out con <- con
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
323 }{
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
324 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
325 }
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
326 }
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
327 }
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
328
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
329 _Add Len[len,buf:out]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
330 {
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
331 out <- [len]+[[buf]Length]
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
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
334 _Merge One Buf[inprog,src:out]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
335 {
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
336 oldlen <- [inprog]Length
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
337 srclen <- [src]Length
145
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
338 If[srclen]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
339 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
340 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
341 }{
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
342 out <- inprog
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
343 }
144
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
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
346 _Merge Buffers[buflist:out]
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 If[[[buflist]Length]=[1]]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
349 {
145
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
350 out <- [buflist]Index[0]{}
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
351 { Print["This shouldn't happen!!!!"] }
144
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
352 }{
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
353 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
354 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
355 }
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
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
358 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
359 {
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
360 buflen <- [[con]Read Buffer >>]Length
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
361 If[[toread]=[buflen]]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
362 {
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
363 data <- [con]Read Buffer >>
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
364 out con <- [con]Read Buffer <<[Array[]]
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 If[[toread]<[buflen]]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
367 {
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
368 data <- [[con]Read Buffer >>]Slice[toread] {}
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
369 { out con <- [con]Read Buffer <<[~] }
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
370 }{
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
371 If[buflen]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
372 {
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
373 buflist <- [()]Append[[con]Read Buffer >>]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
374 ntoread <- [toread]-[[[con]Read Buffer >>]Length]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
375 }{
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
376 ntoread <- Val[toread]
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
377 buflist <- ()
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 ,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
380 { data <- _Merge Buffers[~] }
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
381 }
65ebd1ce2611 Add Read method to TCP connection
Mike Pavone <pavone@retrodev.com>
parents: 143
diff changeset
382 }
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
145
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
385 _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
386 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
387 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
388 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
389 left <- [[buffer]Length]-[offset]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
390 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
391 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
392 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
393 }{
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
394 partial <- offset
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
395 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
396 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
397 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
398
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
399 _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
400 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
401 dlen <- [delim]Length
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
402 blen <- [buffer]Length
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
403 If[[[offset]+[dlen]]<=[blen]]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
404 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
405 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
406 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
407 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
408 }{
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
409 out <- offset
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
410 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
411 }{
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
412 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
413 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
414 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
415
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
416 _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
417 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
418 ,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
419 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
420 left <- [[old]Length]-[offset]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
421 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
422 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
423 next <- [offset]+[1]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
424 }{
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
425 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
426 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
427 next <- [offset]+[1]
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 out <- offset
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 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
432 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
433 }
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
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
436 _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
437 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
438 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
439 { numread <- Trunc Int32[~] }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
440 { outbuf <- [~]Length <<[numread] }
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 If[[numread]=[-1]]
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 If[Wait for IO[[con]Filedes >>, 1]]
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 data,out con,err <- [con]_Read Delim[delim,poffset,buflist]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
447 }{
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
448 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
449 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
450 }{
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
451 ,checknew <- If[[poffset]>=[0]]
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 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
454 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
455 //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
456 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
457 _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
458 ]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
459 ]Read Delim[delim]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
460 }{
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
461 ,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
462 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
463 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
464 ]Length <<[~]
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 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
467 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
468 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
469 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
470 [_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
471 _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
472 ]Length <<[rbufferlen]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
473 ]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
474 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
475 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
476 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
477 Val[checknew]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
478 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
479 ,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
480 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
481 before <- [_internal_array_copychunk[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
482 ]Length <<[~]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
483 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
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 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
487 }{
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
488 tomerge <- [buflist]Append[before]
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 data <- _Merge Buffers[tomerge]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
491 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
492 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
493 [_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
494 _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
495 ]Length <<[rbufferlen]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
496 ]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
497 }{
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
498 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
499 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
500 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
501 }{
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
502 nbuflist <- Val[buflist]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
503 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
504 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
505 }{
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
506 npoffset <- -1
145
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
507 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
508 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
509 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
510 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
511 }{
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
512 nbuflist <- [buflist]Append[outbuf]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
513 ncon <- Val[con]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
514 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
515 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
516 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
517 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
518 }
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 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
522 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
523 ,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
524 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
525 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
526 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
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[[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
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 buflist <- ()
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
534 ncon <- Val[con]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
535 }{
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
536 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
537 {
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
538 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
539 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
540 }{
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
541 ncon <- Val[con]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
542 buflist <- ()
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 poffset <- -1
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
545
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 data,out con,err <- [ncon]_Read Delim[delim,poffset,buflist]
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
548 }
357f4ce3ca6d Add incredibly ugly implementation of Read Delim to TCP Connection
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
549
143
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
550 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
551 {
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
552 out <- close[[con]Filedes >>]
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
553 }
ff00538cd818 Add TCP Connection type and implement Write and Close methods
Mike Pavone <pavone@retrodev.com>
parents: 142
diff changeset
554
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
555 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
556 {
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
557 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
558 }
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
559
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
560 _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
561 {
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
562 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
563 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
564 }
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
565
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
566 //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
567 //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
568 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
569 {
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
570 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
571 }
7bbdc034e347 Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
572
152
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
573 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
574 {
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
575 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
576 }
e9a8269384bb Add support for opening a new TCP connection and fix bug in Read Delim
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
577