Mercurial > repos > rhope
comparison net.rhope @ 143:ff00538cd818
Add TCP Connection type and implement Write and Close methods
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 21 Nov 2010 17:10:49 -0500 |
parents | 7bbdc034e347 |
children | 65ebd1ce2611 |
comparison
equal
deleted
inserted
replaced
142:7bbdc034e347 | 143:ff00538cd818 |
---|---|
221 out <- _Port Wait[fd,tocall] | 221 out <- _Port Wait[fd,tocall] |
222 }{ | 222 }{ |
223 Print["Error waiting for connection"] | 223 Print["Error waiting for connection"] |
224 } | 224 } |
225 }{ | 225 }{ |
226 Call Async[_Do Con Call[con,address,tocall,?]] | 226 fcntl[con, 4i32, 2048i64] |
227 { | 227 { Call Async[_Do Con Call[TCP Connection[con],address,tocall,?]] |
228 out <- _Port Wait[fd,tocall] | 228 { out <- _Port Wait[fd,tocall] }} |
229 } | |
230 } | 229 } |
231 } | 230 } |
232 | 231 |
233 Listen on Port[port(Int32),tocall:out] | 232 Listen on Port[port(Int32),tocall:out] |
234 { | 233 { |
242 { listen[fd,8] | 241 { listen[fd,8] |
243 { out <- Call Async[_Port Wait[fd,tocall,?]] }} | 242 { out <- Call Async[_Port Wait[fd,tocall,?]] }} |
244 } | 243 } |
245 } | 244 } |
246 | 245 |
246 Blueprint TCP Connection | |
247 { | |
248 Filedes | |
249 Read Buffer | |
250 Read Offset | |
251 } | |
252 | |
253 TCP Connection[fd:out] | |
254 { | |
255 out <- [[[Build[TCP Connection()] | |
256 ]Filedes <<[fd] | |
257 ]Read Buffer <<[Array[]] | |
258 ]Read Offset <<[0] | |
259 } | |
260 | |
261 _Write@TCP Connection[con,buffer,wrote:out,err] | |
262 { | |
263 | |
264 new wrote <- write[[con]Filedes >>, buffer, Int64[[buffer]Length]] | |
265 If[[new wrote]=[-1]] | |
266 { | |
267 If[Wait for IO[[con]Filedes >>, 2]] | |
268 { | |
269 out,err <- [con]_Write[buffer,wrote] | |
270 }{ | |
271 err <- wrote | |
272 } | |
273 }{ | |
274 If[[new wrote]=[[buffer]Length]] | |
275 { | |
276 out <- con | |
277 }{ | |
278 remaining <- [[buffer]Length]-[new wrote] | |
279 next buf <- [_internal_array_copychunk[buffer, new wrote, _internal_array_allocnaked[remaining,UInt8()], 0, remaining]]Length <<[remaining] | |
280 out,err <- [con]_Write[next buf,[wrote]+[new wrote]] | |
281 } | |
282 } | |
283 } | |
284 | |
285 Write@TCP Connection[con,buffer(Array):out,err] | |
286 { | |
287 If[[buffer]Length] | |
288 { | |
289 out,err <- [con]_Write[buffer,0] | |
290 }{ | |
291 out <- con | |
292 } | |
293 } | |
294 | |
295 Close@TCP Connection[con:out] | |
296 { | |
297 out <- close[[con]Filedes >>] | |
298 } | |
299 | |
247 //This effectively leaks a context and thus any data on the stack of that context | 300 //This effectively leaks a context and thus any data on the stack of that context |
248 //Need either handle cleanup of contexts or find a better way to accomplish this | 301 //Need either handle cleanup of contexts or find a better way to accomplish this |
249 Wait Forever[] | 302 Wait Forever[] |
250 { | 303 { |
251 Pause[Val[?]] | 304 Pause[Val[?]] |