Squeak Socket Primitives

Stephen Pair spair at advantive.com
Wed Nov 10 15:00:47 UTC 1999


------=_NextPart_000_0005_01BF2B62.7622BA40
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit


On our project (at Advantive), we have re-written the Socket interface code
on the WinNT platform.  We've done it in a pluggable primitive fashion and
called it XSockets (for the moment).  This allows us to use both the old
socket code and XSockets simultaneously.

What we did in a nutshell is eliminate polling in the VM, made use of NT's
overlapped I/O and I/O completion ports to avoid unnecessary creation of
threads (using only one thread per CPU).  Each IO call is passed a unique
external Semaphore to signal completion and a handle to an IO object is
answered by the primitive.  After the semaphore is signaled, the IO object
can be queried for results of the call.  It works very nice, it makes the
code cleaner, and I *think* it is more scalable (we'll soon find out).  We
have not yet added an ability to connect these XSockets (only works for
accepting incoming connections).

Thus, our two primary classes are:

XSocket, and
XSocketIO

We plan to use a similar scheme for asynchronous file IO as well.  So far
the performance and reliability is very good.

The following is XSocket>>getData (to provide an illustration):

----
getData
	| buf io |
	"Get some data"

	io _ XSocketIO new.
	io ioHandle: (self
		primSocket: socketHandle
		receiveBufSize: 2000
		sema: io semaIndex).
	io ioHandle isNull ifTrue: [ ^self error: 'IO failed' ].

	io waitOnIO.
	buf _ io ioBuffer.
	io destroy. "Finalization will also do this for us."
	^buf
----

I would like to release this stuff soon (we don't want to be the proud
owner's of dead code), however, we have some other deadlines to take care of
first, and I would like to do a bit of documentation and cleanup work.  I'm
interested to find out what kind of effort would be required to port to
other platforms.  I'm also anxious to get some feedback on the design.  A
realistic time frame is probably about 4 weeks from now.

- Stephen

P.S. I've attached a quick and dirty SocketStream implementation (may only
work with XSocket though)


------=_NextPart_000_0005_01BF2B62.7622BA40
Content-Type: text/plain; name="SocketStream.st"
 ; x-mac-type="65417070"
 ; x-mac-creator="43534F6D"
Content-Disposition: attachment; filename="SocketStream.st"
Content-Transfer-Encoding: imap_stub

0,973,2,4887,0,

------=_NextPart_000_0005_01BF2B62.7622BA40--





More information about the Squeak-dev mailing list