[squeak-dev] The Trunk: Network-ul.114.mcz
commits at source.squeak.org
commits at source.squeak.org
Fri Apr 22 22:14:03 UTC 2011
Levente Uzonyi uploaded a new version of Network to project The Trunk:
http://source.squeak.org/trunk/Network-ul.114.mcz
==================== Summary ====================
Name: Network-ul.114
Author: ul
Time: 20 April 2011, 2:00:42.697 am
UUID: 6d5a1d3d-1749-a646-a7be-72d65cb73dd6
Ancestors: Network-nice.113
- removed support for single semaphore sockets
- use [ ... ] repeat instead of [ true ] whileTrue: [ ... ]
=============== Diff against Network-nice.113 ===============
Item was changed:
Object subclass: #Socket
+ instanceVariableNames: 'semaphore socketHandle readSemaphore writeSemaphore'
- instanceVariableNames: 'semaphore socketHandle readSemaphore writeSemaphore primitiveOnlySupportsOneSemaphore'
classVariableNames: 'Connected DeadServer InvalidSocket OtherEndClosed Registry RegistryThreshold TCPSocketType ThisEndClosed UDPSocketType Unconnected WaitingForConnection'
poolDictionaries: ''
category: 'Network-Kernel'!
!Socket commentStamp: 'gk 12/13/2005 00:43' prior: 0!
A Socket represents a network connection point. Current sockets are designed to support the TCP/IP and UDP protocols. Sockets are the lowest level of networking object in Squeak and are not normally used directly. SocketStream is a higher level object wrapping a Socket in a stream like protocol.
ProtocolClient and subclasses are in turn wrappers around a SocketStream to provide support for specific network protocols such as POP, NNTP, HTTP, and FTP.!
Item was changed:
----- Method: Socket>>acceptFrom: (in category 'initialize-destroy') -----
acceptFrom: aSocket
"Initialize a new socket handle from an accept call"
| semaIndex readSemaIndex writeSemaIndex |
- primitiveOnlySupportsOneSemaphore := false.
semaphore := Semaphore new.
readSemaphore := Semaphore new.
writeSemaphore := Semaphore new.
semaIndex := Smalltalk registerExternalObject: semaphore.
readSemaIndex := Smalltalk registerExternalObject: readSemaphore.
writeSemaIndex := Smalltalk registerExternalObject: writeSemaphore.
socketHandle := self primAcceptFrom: aSocket socketHandle
receiveBufferSize: 8000
sendBufSize: 8000
semaIndex: semaIndex
readSemaIndex: readSemaIndex
writeSemaIndex: writeSemaIndex.
socketHandle
ifNotNil: [ self register ]
ifNil: [ "socket creation failed"
Smalltalk unregisterExternalObject: semaphore.
Smalltalk unregisterExternalObject: readSemaphore.
Smalltalk unregisterExternalObject: writeSemaphore.
readSemaphore := writeSemaphore := semaphore := nil ]
!
Item was changed:
----- Method: Socket>>initialize: (in category 'initialize-destroy') -----
initialize: socketType
"Initialize a new socket handle. If socket creation fails, socketHandle will be set to nil."
| semaIndex readSemaIndex writeSemaIndex |
- primitiveOnlySupportsOneSemaphore := false.
semaphore := Semaphore new.
readSemaphore := Semaphore new.
writeSemaphore := Semaphore new.
semaIndex := Smalltalk registerExternalObject: semaphore.
readSemaIndex := Smalltalk registerExternalObject: readSemaphore.
writeSemaIndex := Smalltalk registerExternalObject: writeSemaphore.
socketHandle :=
self primSocketCreateNetwork: 0
type: socketType
receiveBufferSize: 8000
sendBufSize: 8000
semaIndex: semaIndex
readSemaIndex: readSemaIndex
writeSemaIndex: writeSemaIndex.
socketHandle
ifNotNil: [ self register ]
ifNil: [ "socket creation failed"
Smalltalk unregisterExternalObject: semaphore.
Smalltalk unregisterExternalObject: readSemaphore.
Smalltalk unregisterExternalObject: writeSemaphore.
readSemaphore := writeSemaphore := semaphore := nil ]
!
Item was changed:
----- Method: Socket>>primAcceptFrom:receiveBufferSize:sendBufSize:semaIndex:readSemaIndex:writeSemaIndex: (in category 'primitives') -----
primAcceptFrom: aHandle receiveBufferSize: rcvBufSize sendBufSize: sndBufSize semaIndex: semaIndex readSemaIndex: aReadSema writeSemaIndex: aWriteSema
"Create and return a new socket handle based on accepting the connection from the given listening socket"
+
<primitive: 'primitiveSocketAccept3Semaphores' module: 'SocketPlugin'>
+ self primitiveFailed!
- primitiveOnlySupportsOneSemaphore := true.
- ^self primAcceptFrom: aHandle receiveBufferSize: rcvBufSize sendBufSize: sndBufSize semaIndex: semaIndex !
Item was changed:
----- Method: Socket>>primSocketCreateNetwork:type:receiveBufferSize:sendBufSize:semaIndex:readSemaIndex:writeSemaIndex: (in category 'primitives') -----
primSocketCreateNetwork: netType type: socketType receiveBufferSize: rcvBufSize sendBufSize: sendBufSize semaIndex: semaIndex readSemaIndex: aReadSema writeSemaIndex: aWriteSema
+ "See comment in primSocketCreateNetwork: with one semaIndex. However you should know that some implementations ignore the buffer size and this interface supports three semaphores, one for open/close/listen and the other two for reading and writing"
- "See comment in primSocketCreateNetwork: with one semaIndex. However you should know that some implementations
- ignore the buffer size and this interface supports three semaphores, one for open/close/listen and the other two for
- reading and writing"
<primitive: 'primitiveSocketCreate3Semaphores' module: 'SocketPlugin'>
+ self primitiveFailed!
- primitiveOnlySupportsOneSemaphore := true.
- ^ self primSocketCreateNetwork: netType
- type: socketType
- receiveBufferSize: rcvBufSize
- sendBufSize: sendBufSize
- semaIndex: semaIndex!
Item was changed:
----- Method: Socket>>primitiveOnlySupportsOneSemaphore (in category 'accessing') -----
primitiveOnlySupportsOneSemaphore
+
+ self deprecated: 'All sockets have 3 semaphores.'.
+ ^false!
- ^primitiveOnlySupportsOneSemaphore!
Item was changed:
----- Method: Socket>>readSemaphore (in category 'accessing') -----
readSemaphore
+
- primitiveOnlySupportsOneSemaphore ifTrue: [^semaphore].
^readSemaphore!
Item was changed:
----- Method: Socket>>receiveDataInto:fromHost:port: (in category 'datagrams') -----
receiveDataInto: aStringOrByteArray fromHost: hostAddress port: portNumber
| datagram |
"Receive a UDP packet from the given hostAddress/portNumber, storing the data in the given buffer, and return the number of bytes received. Note the given buffer may be only partially filled by the received data."
+ [
+ datagram := self receiveUDPDataInto: aStringOrByteArray.
- primitiveOnlySupportsOneSemaphore ifTrue:
- [self setPeer: hostAddress port: portNumber.
- ^self receiveDataInto: aStringOrByteArray].
- [true] whileTrue:
- [datagram := self receiveUDPDataInto: aStringOrByteArray.
((datagram at: 2) = hostAddress and: [(datagram at: 3) = portNumber])
ifTrue: [^datagram at: 1]
+ ifFalse: [^0]] repeat!
- ifFalse: [^0]]!
Item was changed:
----- Method: Socket>>sendData:toHost:port: (in category 'datagrams') -----
sendData: aStringOrByteArray toHost: hostAddress port: portNumber
"Send a UDP packet containing the given data to the specified host/port."
- primitiveOnlySupportsOneSemaphore ifTrue:
- [self setPeer: hostAddress port: portNumber.
- ^self sendData: aStringOrByteArray].
^self sendUDPData: aStringOrByteArray toHost: hostAddress port: portNumber!
Item was changed:
----- Method: Socket>>writeSemaphore (in category 'accessing') -----
writeSemaphore
+
- primitiveOnlySupportsOneSemaphore ifTrue: [^semaphore].
^writeSemaphore!
More information about the Squeak-dev
mailing list
|