added MOO_EBADHND
This commit is contained in:
@ -52,9 +52,11 @@ class Semaphore(Object)
|
||||
{
|
||||
var waiting_head := nil,
|
||||
waiting_tail := nil,
|
||||
count := 0,
|
||||
heapIndex := -1,
|
||||
fireTimeSec := 0,
|
||||
count := 0.
|
||||
|
||||
var(#get,#set) heapIndex := -1.
|
||||
|
||||
var fireTimeSec := 0,
|
||||
fireTimeNsec := 0,
|
||||
ioIndex := -1,
|
||||
ioHandle := nil,
|
||||
@ -81,16 +83,6 @@ class Semaphore(Object)
|
||||
|
||||
## ==================================================================
|
||||
|
||||
method heapIndex
|
||||
{
|
||||
^heapIndex
|
||||
}
|
||||
|
||||
method heapIndex: anIndex
|
||||
{
|
||||
heapIndex := anIndex
|
||||
}
|
||||
|
||||
method fireTime
|
||||
{
|
||||
^fireTimeSec
|
||||
@ -221,6 +213,13 @@ method(#class,#abstract) xxx. => method(#class) xxx { self subclassResponsibilit
|
||||
method(#primitive) _removeSemaphore: sem.
|
||||
method(#primitive) _wait.
|
||||
|
||||
method addSemaphore: sem
|
||||
{
|
||||
| x |
|
||||
x := self _addSemaphore: sem.
|
||||
if (x isError) { thisProcess primError dump. Exception signal: ('Cannot add a semaphore - ' & thisProcess primError) }.
|
||||
^x
|
||||
}
|
||||
method wait
|
||||
{
|
||||
| r |
|
||||
|
@ -3,8 +3,9 @@ class Socket(Object) from 'sck'
|
||||
var handle := -1.
|
||||
|
||||
method(#primitive) _open(domain, type, proto).
|
||||
method(#primitive) _connect(a,b,c).
|
||||
method(#primitive) _close.
|
||||
|
||||
method(#primitive) _connect(a,b,c).
|
||||
}
|
||||
|
||||
(* TODO: generate these domain and type from the C header *)
|
||||
@ -22,27 +23,113 @@ pooldic Socket.Type
|
||||
|
||||
extend Socket
|
||||
{
|
||||
method(#class) domain: domain type: type
|
||||
method(#class) new { self messageProhibited: #new }
|
||||
method(#class) new: size { self messageProhibited: #new: }
|
||||
|
||||
method(#class) _domain: domain _type: type
|
||||
{
|
||||
^super new _open(domain, type, 0).
|
||||
}
|
||||
|
||||
method beginConnect
|
||||
method(#class) domain: domain type: type
|
||||
{
|
||||
(*
|
||||
| s1 s1 |
|
||||
s1 = Semaphore new.
|
||||
s2 = Semaphore new.
|
||||
| s |
|
||||
s := super new _open(domain, type, 0).
|
||||
if (s isError) { Exception signal: 'Cannot open socket' }.
|
||||
^s.
|
||||
}
|
||||
|
||||
s1 signalHandler: [xxxxx].
|
||||
s2 signalHandler: [xxxxxx].
|
||||
method close
|
||||
{
|
||||
if (self.handle >= 0)
|
||||
{
|
||||
## this primitive method may return failure.
|
||||
## but ignore it in this normal method.
|
||||
self _close.
|
||||
self.handle := -1.
|
||||
}
|
||||
}
|
||||
|
||||
fcntl (nonblock);
|
||||
method asyncConnect: connectBlock
|
||||
{
|
||||
| s1 s2 sg |
|
||||
s1 := Semaphore new.
|
||||
s2 := Semaphore new.
|
||||
|
||||
s1 signalAction: [:sem | Processor unsignal: s1. connectBlock value: true].
|
||||
s2 signalAction: [:sem | Processor unsignal: s2. connectBlock value: false].
|
||||
|
||||
Processor signal: s1 onOutput: self.handle.
|
||||
Processor signal: s2 after: timeout.
|
||||
Processor signal: s2 after: 10.
|
||||
|
||||
connect ();
|
||||
*)
|
||||
sg := SemaphoreGroup new.
|
||||
sg addSemaphore: s1.
|
||||
sg addSemaphore: s2.
|
||||
sg addSemaphore: s1.
|
||||
sg addSemaphore: 10.
|
||||
sg addSemaphore: s1.
|
||||
|
||||
if (self _connect(1, 2, 3) isError)
|
||||
{
|
||||
Exception signal: 'Cannot connect to 1,2,3'.
|
||||
}.
|
||||
|
||||
sg wait.
|
||||
}
|
||||
|
||||
method asyncRead: readBlock
|
||||
{
|
||||
| s1 s2 |
|
||||
s1 := Semaphore new.
|
||||
s2 := Semaphore new.
|
||||
|
||||
s1 signalAction: [:sem | readBlock value: true].
|
||||
s2 signalAction: [:sem | readBlock value: false].
|
||||
|
||||
Processor signal: s1 onInput: self.handle.
|
||||
Processor signal: s2 after: 10.
|
||||
}
|
||||
|
||||
(*
|
||||
method asyncWrite:
|
||||
{
|
||||
| s1 s2 |
|
||||
s1 := Semaphore new.
|
||||
s2 := Semaphore new.
|
||||
|
||||
s1 signalAction: [:sem | writeBlock value: true].
|
||||
s2 signalAction: [:sem | writeBlock value: false].
|
||||
|
||||
Processor signal: s1 onOutput: self.handle.
|
||||
Processor signal: s2 after: 10.
|
||||
}
|
||||
*)
|
||||
|
||||
}
|
||||
|
||||
|
||||
(****
|
||||
class MyObject(Object)
|
||||
{
|
||||
|
||||
method(#class) main
|
||||
{
|
||||
| s |
|
||||
[
|
||||
s := Socket domain: Socket.Domain.INET type: Socket.Type.STREAM.
|
||||
s dump.
|
||||
|
||||
s asyncConnect: [:result |
|
||||
##s endConnect: result.
|
||||
##s beginRead: xxx.
|
||||
'CONNECTED NOW.............' dump.
|
||||
].
|
||||
|
||||
s close dump.
|
||||
] on: Exception do: [:ex | ('Exception - ' & ex messageText) dump ].
|
||||
|
||||
'----- END OF MAIN ------' dump.
|
||||
}
|
||||
}
|
||||
*****)
|
||||
|
||||
|
@ -27,6 +27,7 @@ class MyObject(Object)
|
||||
'interrupted'
|
||||
'pipe error'
|
||||
'resource temporarily unavailable'
|
||||
'bad system handle'
|
||||
|
||||
'data too large'
|
||||
'message receiver error'
|
||||
|
@ -132,12 +132,27 @@ class MyObject(Object)
|
||||
s1 := TcpSocket new.
|
||||
|
||||
s1 onEvent: #connected do: [
|
||||
s1 write: C'GET / HTTP/1.0\n\r'.
|
||||
s1 waitToRead.
|
||||
##s1 beginWrite: C'GET / HTTP/1.0\n\r'.
|
||||
]
|
||||
s1 onEvent: #written do: [
|
||||
]
|
||||
].
|
||||
|
||||
s1 on: #read do:
|
||||
s1 connectTo: '1.2.3.4:45'.
|
||||
s1 onEvent: #readyToRead do: [
|
||||
|
||||
].
|
||||
|
||||
s1 beginConnect: '1.2.3.4:45' onConnected: [ :result | xxxx].
|
||||
|
||||
|
||||
####
|
||||
s1 beginConnect: destination onConnected:
|
||||
s1 endConnect --> return what?
|
||||
s1 endReceive
|
||||
s1 beginReceive: buffer callback: [xxxx].
|
||||
s1 beginSend: data onEnd: [do this].
|
||||
s1 endSend
|
||||
|
||||
s1 beginAccept: [callback]
|
||||
s1 endAccept -> returns the actual socket
|
||||
*)
|
||||
|
Reference in New Issue
Block a user