Mercurial > repos > rhope
comparison net.rhope @ 165:47ab97730865
Fix a couple of issues in networking lib
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 10 Mar 2011 04:15:37 +0000 |
parents | e9a8269384bb |
children | 1bfc19076f1b |
comparison
equal
deleted
inserted
replaced
161:f5095855c878 | 165:47ab97730865 |
---|---|
17 Foreign C:runtime | 17 Foreign C:runtime |
18 { | 18 { |
19 _internal_bindnewsocket[port(Int32,Naked),setreuse(Int32,Naked):socket(Int32,Naked)] | 19 _internal_bindnewsocket[port(Int32,Naked),setreuse(Int32,Naked):socket(Int32,Naked)] |
20 _internal_accept[sockfd(Int32,Naked),addrbuf(Array,Raw Pointer,Mutable),buflen(Int32,Naked):consock(Int32,Naked),addrbuf] | 20 _internal_accept[sockfd(Int32,Naked),addrbuf(Array,Raw Pointer,Mutable),buflen(Int32,Naked):consock(Int32,Naked),addrbuf] |
21 _internal_connectnewsocket[addr(Array,Raw Pointer),port(Int32,Naked):sockfd(Int32,Naked)] | 21 _internal_connectnewsocket[addr(Array,Raw Pointer),port(Int32,Naked):sockfd(Int32,Naked)] |
22 _internal_ignoresigpipe[:out(Int32,Naked)] | |
22 } | 23 } |
23 | 24 |
24 Blueprint epoll_event | 25 Blueprint epoll_event |
25 { | 26 { |
26 events(UInt32,Naked) | 27 events(UInt32,Naked) |
67 { | 68 { |
68 If[[[event]events >>]&[8216u32]] | 69 If[[[event]events >>]&[8216u32]] |
69 { res <- No } | 70 { res <- No } |
70 { res <- Yes } | 71 { res <- Yes } |
71 ct,cont <- _Get IO Context[activefd] | 72 ct,cont <- _Get IO Context[activefd] |
72 { | 73 { |
73 }{ Print["Could not find context for IO event"] } | 74 }{ Print["Could not find context for IO event"] } |
75 | |
74 ,cont <- Resume[ct,res] | 76 ,cont <- Resume[ct,res] |
75 { | 77 { |
76 cont <- Yield[] | 78 cont <- Yield[] |
77 }{ | 79 }{ |
78 Print["could not resume context for IO event"] | 80 Print["could not resume context for IO event"] |
110 } | 112 } |
111 } | 113 } |
112 | 114 |
113 _Sock Listener[pipefd] | 115 _Sock Listener[pipefd] |
114 { | 116 { |
117 _internal_ignoresigpipe[] | |
115 epfd <- epoll_create[16] | 118 epfd <- epoll_create[16] |
116 If[[epfd]=[-1]] | 119 If[[epfd]=[-1]] |
117 { | 120 { |
118 Print["Error creating epoll file descriptor"] | 121 Print["Error creating epoll file descriptor"] |
119 }{ | 122 }{ |
131 listener started <- No | 134 listener started <- No |
132 fdlookup <- () | 135 fdlookup <- () |
133 pipefd <- -1 | 136 pipefd <- -1 |
134 } | 137 } |
135 | 138 |
136 _Add FD to Listener[fd,context:pipefd,err] uses socklisten | 139 __Add FD to Listener[fd,context:pipefd,err,startpipe] uses socklisten |
137 { | 140 { |
138 If[socklisten::listener started] | 141 If[socklisten::listener started] |
139 { | 142 { |
140 pipefd <- socklisten::pipefd | 143 pipefd <- socklisten::pipefd |
141 do add <- Yes | 144 do add <- Yes |
152 //fcntl[fd, F_SETFL, O_NONBLOCK] | 155 //fcntl[fd, F_SETFL, O_NONBLOCK] |
153 //Set both ends of the pipe to non blocking | 156 //Set both ends of the pipe to non blocking |
154 fcntl[[des]Index[0], 4i32, 2048i64] | 157 fcntl[[des]Index[0], 4i32, 2048i64] |
155 fcntl[[des]Index[1], 4i32, 2048i64] | 158 fcntl[[des]Index[1], 4i32, 2048i64] |
156 socklisten::listener started <- Yes | 159 socklisten::listener started <- Yes |
157 Call Async[_Sock Listener[[des]Index[0],?]] | 160 startpipe <- [des]Index[0] |
158 do add <- Yes | 161 do add <- Yes |
159 } | 162 } |
160 } | 163 } |
161 Val[do add] | 164 Val[do add] |
162 { | 165 { |
163 socklisten::fdlookup <- [socklisten::fdlookup]Set[fd, context] | 166 socklisten::fdlookup <- [socklisten::fdlookup]Set[fd, context] |
164 } | 167 } |
168 } | |
169 | |
170 _Add FD to Listener[fd,context:pipefd,err] | |
171 { | |
172 pipefd,err <- __Add FD to Listener[fd,context] {} {} | |
173 { Call Async[_Sock Listener[~,?]] } | |
165 } | 174 } |
166 | 175 |
167 _Write to Listener Pipe[pipefd,data] | 176 _Write to Listener Pipe[pipefd,data] |
168 { | 177 { |
169 res <- write[pipefd, data, 8i64] | 178 res <- write[pipefd, data, 8i64] |
268 } | 277 } |
269 } | 278 } |
270 | 279 |
271 _Write@TCP Connection[con,buffer,wrote:out,err] | 280 _Write@TCP Connection[con,buffer,wrote:out,err] |
272 { | 281 { |
273 | |
274 new wrote <- write[[con]Filedes >>, buffer, Int64[[buffer]Length]] | 282 new wrote <- write[[con]Filedes >>, buffer, Int64[[buffer]Length]] |
275 If[[new wrote]=[-1]] | 283 If[[new wrote]<[1]] |
276 { | 284 { |
277 If[Wait for IO[[con]Filedes >>, 4]] | 285 ,doerr <- If[new wrote] |
278 { | 286 { |
279 out,err <- [con]_Write[buffer,wrote] | 287 ,doerr <- If[Wait for IO[[con]Filedes >>, 4]] |
280 }{ | 288 { |
289 out,err <- [con]_Write[buffer,wrote] | |
290 } | |
291 } | |
292 Val[doerr] | |
293 { | |
281 err <- wrote | 294 err <- wrote |
282 } | 295 } |
283 }{ | 296 }{ |
284 If[[new wrote]=[[buffer]Length]] | 297 If[[new wrote]=[[buffer]Length]] |
285 { | 298 { |
437 { | 450 { |
438 read[[con]Filedes >>, _internal_array_allocnaked[512i32, UInt8()], 512i64] | 451 read[[con]Filedes >>, _internal_array_allocnaked[512i32, UInt8()], 512i64] |
439 { numread <- Trunc Int32[~] } | 452 { numread <- Trunc Int32[~] } |
440 { outbuf <- [~]Length <<[numread] } | 453 { outbuf <- [~]Length <<[numread] } |
441 | 454 |
442 If[[numread]=[-1]] | 455 If[[numread]<[1]] |
443 { | 456 { |
444 If[Wait for IO[[con]Filedes >>, 1]] | 457 doerr <- If[[numread]=[0]] {} |
445 { | 458 { |
446 data,out con,err <- [con]_Read Delim[delim,poffset,buflist] | 459 ,doerr <- If[Wait for IO[[con]Filedes >>, 1]] |
447 }{ | 460 { |
461 data,out con,err <- [con]_Read Delim[delim,poffset,buflist] | |
462 } | |
463 } | |
464 Val[doerr] | |
465 { | |
448 err <- [Fold[_Add Len[?], 0, buflist]]+[Length[[con]Read Buffer >>]] | 466 err <- [Fold[_Add Len[?], 0, buflist]]+[Length[[con]Read Buffer >>]] |
449 } | 467 } |
450 }{ | 468 }{ |
451 ,checknew <- If[[poffset]>=[0]] | 469 ,checknew <- If[[poffset]>=[0]] |
452 { | 470 { |
542 buflist <- () | 560 buflist <- () |
543 } | 561 } |
544 poffset <- -1 | 562 poffset <- -1 |
545 | 563 |
546 } | 564 } |
547 data,out con,err <- [ncon]_Read Delim[delim,poffset,buflist] | 565 data,out con,err <- [ncon]_Read Delim[delim,poffset,buflist] {} {} |
548 } | 566 } |
549 | 567 |
550 Close@TCP Connection[con:out] | 568 Close@TCP Connection[con:out] |
551 { | 569 { |
552 out <- close[[con]Filedes >>] | 570 out <- close[[con]Filedes >>] |