From: <wda...@us...> - 2007-11-17 19:42:43
|
Revision: 1265 http://oorexx.svn.sourceforge.net/oorexx/?rev=1265&view=rev Author: wdashley Date: 2007-11-17 11:42:47 -0800 (Sat, 17 Nov 2007) Log Message: ----------- ArtifactID: None Comment: Modified the streamsocket class so that it can accrpt a socket class instance as the base for instantiation. Modified Paths: -------------- incubator/orxutils/internet/streamsocket.cls incubator/orxutils/internet/teststreamsocket.rex Modified: incubator/orxutils/internet/streamsocket.cls =================================================================== --- incubator/orxutils/internet/streamsocket.cls 2007-11-17 14:10:36 UTC (rev 1264) +++ incubator/orxutils/internet/streamsocket.cls 2007-11-17 19:42:47 UTC (rev 1265) @@ -214,6 +214,8 @@ /*----------------------------------------------------------------------------*/ /* Method: init */ /* Description: instance initialization */ +/* If only one argument is supplied it is assumed to be a */ +/* Socket class instance. */ /* Arguments: */ /* host - the hostname or ip address */ /* port - the port number */ @@ -222,16 +224,27 @@ ::method init expose state description s hostname port opened bufsize rcvbuf -use strict arg hostname, port, bufsize = 4096 -opened = .false +if arg() = 1 then do + use strict arg s + if \s~isA(.Socket) then , + raise syntax 93.914 array (1, 'a Socket class instance', address) + hostname = 'unknown' + port = 'unknown' + bufsize = 4096 + opened = .true + end +else do + use strict arg hostname, port, bufsize = 4096 + opened = .false + s = .Socket~new('AF_INET', 'SOCK_STREAM', 0) + if s~errno <> '' then do + state = 'ERROR' + description = s~errno + raise error 5 array('Socket') return + return + end + end rcvbuf = .mutablebuffer~new(, bufsize) -s = .Socket~new('AF_INET', 'SOCK_STREAM', 0) -if s~errno <> '' then do - state = 'ERROR' - description = s~errno - raise error 5 array('Socket') return - return - end state = 'READY' description = '' return @@ -318,6 +331,11 @@ ::method open expose state description s opened hostname port +if opened then do + state = 'READY' + description = '' + return self~description + end use strict arg if opened = .true then do state = 'READY' Modified: incubator/orxutils/internet/teststreamsocket.rex =================================================================== --- incubator/orxutils/internet/teststreamsocket.rex 2007-11-17 14:10:36 UTC (rev 1264) +++ incubator/orxutils/internet/teststreamsocket.rex 2007-11-17 19:42:47 UTC (rev 1265) @@ -76,14 +76,14 @@ say 'Error accepting new socket' iterate end + -- turn it into an open streamsocket + css = .StreamSocket~new(cs) -- receive the command from the client - cmd = cs~recv(4096) + cmd = css~linein() -- echo the command back to the client - cs~send(cmd) + css~lineout(cmd) -- close the client connection socket - cs~close() - -- we received this from an ooRexx stream so strip the CRLF - cmd = cmd~substr(1, cmd~pos('0D0A'x) - 1) + css~close() -- if the command was stop then stop the server if cmd~upper() = 'STOP' then do stop = .true This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |