Levente Uzonyi uploaded a new version of Network to project The Trunk:
http://source.squeak.org/trunk/Network-ul.174.mcz ==================== Summary ==================== Name: Network-ul.174 Author: ul Time: 26 March 2016, 4:46:36.918112 am UUID: e49a70ec-9eac-48e7-a03e-d712e2fcd12d Ancestors: Network-eem.173 Socket changes - use the instance variables for the semaphores, since it's clear now which semaphore is responsible for reading and writing (it might as well been done that way originally by assigning the same value to all three variables) - removed the max: 0 checks when the wait time is passed to the semaphores via #waitTimeoutMSecs:, because that method will do the same check =============== Diff against Network-eem.173 =============== Item was changed: ----- Method: Socket>>waitForDataFor:ifClosed:ifTimedOut: (in category 'waiting') ----- waitForDataFor: timeout ifClosed: closedBlock ifTimedOut: timedOutBlock "Wait for the given nr of seconds for data to arrive." | startTime msecsDelta | startTime := Time millisecondClockValue. msecsDelta := (timeout * 1000) truncated. [(Time millisecondsSince: startTime) < msecsDelta] whileTrue: [ (self primSocketReceiveDataAvailable: socketHandle) ifTrue: [^self]. self isConnected ifFalse: [^closedBlock value]. "Providing a maximum for the time for waiting is a workaround for a VM bug which causes sockets waiting for data forever in some rare cases, because the semaphore doesn't get signaled. Remove the ""min: self class maximumReadSemaphoreWaitTimeout"" part when the bug is fixed." + readSemaphore waitTimeoutMSecs: + (msecsDelta - (Time millisecondsSince: startTime) min: self class maximumReadSemaphoreWaitTimeout). - self readSemaphore waitTimeoutMSecs: - ((msecsDelta - (Time millisecondsSince: startTime) max: 0) min: self class maximumReadSemaphoreWaitTimeout). ]. (self primSocketReceiveDataAvailable: socketHandle) ifFalse: [ self isConnected ifTrue: [^timedOutBlock value] ifFalse: [^closedBlock value]].! Item was changed: ----- Method: Socket>>waitForDataIfClosed: (in category 'waiting') ----- waitForDataIfClosed: closedBlock "Wait indefinitely for data to arrive. This method will block until data is available or the socket is closed." [(socketHandle ~~ nil and: [self primSocketReceiveDataAvailable: socketHandle]) ifTrue: [^self]. self isConnected ifFalse: [^closedBlock value]. "ul 8/13/2014 21:16 Providing a maximum for the time for waiting is a workaround for a VM bug which causes sockets waiting for data forever in some rare cases, because the semaphore doesn't get signaled. Replace the ""waitTimeoutMSecs: self class maximumReadSemaphoreWaitTimeout"" part with ""wait"" when the bug is fixed." + readSemaphore waitTimeoutMSecs: self class maximumReadSemaphoreWaitTimeout] repeat! - self readSemaphore waitTimeoutMSecs: self class maximumReadSemaphoreWaitTimeout] repeat! Item was changed: ----- Method: Socket>>waitForDisconnectionFor: (in category 'waiting') ----- waitForDisconnectionFor: timeout "Wait for the given nr of seconds for the connection to be broken. Return true if it is broken by the deadline, false if not. The client should know the connection is really going to be closed (e.g., because he has called 'close' to send a close request to the other end) before calling this method." | startTime msecsDelta status | startTime := Time millisecondClockValue. msecsDelta := (timeout * 1000) truncated. status := self primSocketConnectionStatus: socketHandle. [((status == Connected) or: [(status == ThisEndClosed)]) and: [(Time millisecondsSince: startTime) < msecsDelta]] whileTrue: [ self discardReceivedData. "Providing a maximum for the time for waiting is a workaround for a VM bug which causes sockets waiting for data forever in some rare cases, because the semaphore doesn't get signaled. Remove the ""min: self class maximumReadSemaphoreWaitTimeout"" part when the bug is fixed." + readSemaphore waitTimeoutMSecs: + (msecsDelta - (Time millisecondsSince: startTime) min: self class maximumReadSemaphoreWaitTimeout). - self readSemaphore waitTimeoutMSecs: - ((msecsDelta - (Time millisecondsSince: startTime) max: 0) min: self class maximumReadSemaphoreWaitTimeout). status := self primSocketConnectionStatus: socketHandle]. ^ status ~= Connected! Item was changed: ----- Method: Socket>>waitForSendDoneFor: (in category 'waiting') ----- waitForSendDoneFor: timeout "Wait up until the given deadline for the current send operation to complete. Return true if it completes by the deadline, false if not." | startTime msecsDelta msecsEllapsed sendDone | startTime := Time millisecondClockValue. msecsDelta := (timeout * 1000) truncated. [(sendDone := self primSocketSendDone: socketHandle) not and: [ self isConnected "Connection end and final data can happen fast, so test in this order" and: [(msecsEllapsed := Time millisecondsSince: startTime) < msecsDelta]]] whileTrue: [ + writeSemaphore waitTimeoutMSecs: msecsDelta - msecsEllapsed]. - self writeSemaphore waitTimeoutMSecs: msecsDelta - msecsEllapsed]. ^ sendDone! |
Free forum by Nabble | Edit this page |