attempted to fix some socket class issues

This commit is contained in:
hyunghwan.chung 2017-12-17 15:38:38 +00:00
parent e63596688a
commit 63e34ccf71
3 changed files with 25 additions and 14 deletions

View File

@ -45,7 +45,7 @@ extend Socket
method asyncConnect: connectBlock
{
| s1 s2 sg sa |
| s1 s2 sa |
s1 := Semaphore new.
s2 := Semaphore new.
@ -61,14 +61,15 @@ extend Socket
s1 signalAction: sa.
s2 signalAction: sa.
## TODO: unsignal s1 s2, remove them from System when exception occurs.
System signal: s1 onOutput: self.handle.
System signal: s2 after: 10.
System addAsyncSemaphore: s1.
System addAsyncSemaphore: s2.
self connect(1, 2, 3).
[
System signal: s1 onOutput: self.handle.
System signal: s2 afterSecs: 10.
System addAsyncSemaphore: s1.
System addAsyncSemaphore: s2.
self connect(1, 2, 3).
] ifCurtailed: [
sa value: s2.
]
}
method asyncRead: readBlock
@ -81,7 +82,7 @@ extend Socket
s2 signalAction: [:sem | readBlock value: false].
System signal: s1 onInput: self.handle.
System signal: s2 after: 10.
System signal: s2 afterSecs: 10.
}
(*
@ -95,7 +96,7 @@ extend Socket
s2 signalAction: [:sem | writeBlock value: false].
System signal: s1 onOutput: self.handle.
System signal: s2 after: 10.
System signal: s2 afterSecs: 10.
}
*)
@ -109,12 +110,21 @@ class MyObject(Object)
| 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.
if (result)
{
'CONNECTED NOW.............' dump.
s asyncRead: [:data |
data dump.
]
}
else
{
'UNABLE TO CONNECT............' dump.
}
].
while (true)

View File

@ -21,6 +21,7 @@ class System(Apex)
{
^self.asyncsg removeSemaphore: sem
}
method(#class) handleAsyncEvent
{
^self.asyncsg wait.

View File

@ -134,7 +134,7 @@ struct sockaddr_in sin;
memset (&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = inet_addr ("1.234.53.142");
sin.sin_port = htons(80);
sin.sin_port = htons(12345);
do
{
n = connect(fd, (struct sockaddr*)&sin, sizeof(sin));