Mercurial > repos > rhope
diff 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 |
line wrap: on
line diff
--- a/net.rhope Sun Dec 05 18:04:19 2010 -0500 +++ b/net.rhope Sun Dec 05 18:04:54 2010 -0500 @@ -18,6 +18,7 @@ { _internal_bindnewsocket[port(Int32,Naked),setreuse(Int32,Naked):socket(Int32,Naked)] _internal_accept[sockfd(Int32,Naked),addrbuf(Array,Raw Pointer,Mutable),buflen(Int32,Naked):consock(Int32,Naked),addrbuf] + _internal_connectnewsocket[addr(Array,Raw Pointer),port(Int32,Naked):sockfd(Int32,Naked)] } Blueprint epoll_event @@ -256,6 +257,17 @@ ]Read Buffer <<[Array[]] } +TCP Connect[address,port:out,err] +{ + addrbuf <- [[Flatten[address]]Buffer >>]Append[0u8] + fd <- _internal_connectnewsocket[addrbuf, port] + err <- If[[fd]=[-1]] {} + { + fcntl[fd, 4i32, 2048i64] + out <- TCP Connection[fd] + } +} + _Write@TCP Connection[con,buffer,wrote:out,err] { @@ -483,7 +495,6 @@ ]Length <<[rbufferlen] ] }{ - If[[[con]Read Buffer >>]Length] { nbuflist <- [buflist]Append[[con]Read Buffer >>] @@ -492,6 +503,7 @@ } ncon <- [con]Read Buffer <<[outbuf] }{ + npoffset <- -1 If[[[con]Read Buffer >>]Length] { nbuflist <- [[buflist]Append[[con]Read Buffer >>]]Append[outbuf] @@ -540,10 +552,26 @@ out <- close[[con]Filedes >>] } +Globals Forever +{ + Wait <- No +} + +_Wait Forever[context:out] uses Forever +{ + Forever::Wait <- context + out <- Yes +} + //This effectively leaks a context and thus any data on the stack of that context //Need either handle cleanup of contexts or find a better way to accomplish this Wait Forever[] { - Pause[Val[?]] + Pause[_Wait Forever[?]] } +Stop Waiting[] uses Forever +{ + Resume[Forever::Wait, Yes] +} +