--- a/Socket.st Thu Jul 25 20:11:24 1996 +0200
+++ b/Socket.st Sat Jul 27 11:05:54 1996 +0200
@@ -196,268 +196,268 @@
TODO: cleanup historic leftovers, implement other than inet domain stuff.
[author:]
- Claus Gittinger
+ Claus Gittinger
"
!
examples
"
example (get help info from an nntp server):
- [exBegin]
- |sock host|
+ [exBegin]
+ |sock host|
- host := OperatingSystem getEnvironment:'NNTPSERVER'.
+ host := OperatingSystem getEnvironment:'NNTPSERVER'.
- sock := Socket newTCPclientToHost:host port:'nntp'.
- Transcript showCR:sock nextLine.
- sock buffered:false.
+ sock := Socket newTCPclientToHost:host port:'nntp'.
+ Transcript showCR:sock nextLine.
+ sock buffered:false.
- sock nextPutAll:'HELP'; cr.
- [:exit |
- |line|
+ sock nextPutAll:'HELP'; cr.
+ [:exit |
+ |line|
- line := sock nextLine.
- line = '.' ifTrue:[exit value:nil].
- Transcript showCR:line.
- ] loopWithExit.
- sock close
- [exEnd]
+ line := sock nextLine.
+ line = '.' ifTrue:[exit value:nil].
+ Transcript showCR:line.
+ ] loopWithExit.
+ sock close
+ [exEnd]
example (connect to finger daemon, get users entry):
- [exBegin]
- |sock host entry|
+ [exBegin]
+ |sock host entry|
- host := OperatingSystem getHostName.
+ host := OperatingSystem getHostName.
- sock := Socket newTCPclientToHost:host port:'finger'.
- sock useCRLF:true.
- sock buffered:false.
- sock isNil ifTrue:[
- Transcript showCR:'cannot connect to local finger daemon'
- ] ifFalse:[
- sock nextPutAll:(OperatingSystem getLoginName).
- sock cr.
+ sock := Socket newTCPclientToHost:host port:'finger'.
+ sock useCRLF:true.
+ sock buffered:false.
+ sock isNil ifTrue:[
+ Transcript showCR:'cannot connect to local finger daemon'
+ ] ifFalse:[
+ sock nextPutAll:(OperatingSystem getLoginName).
+ sock cr.
- entry := sock nextLine.
- Transcript showCR:entry.
+ entry := sock nextLine.
+ Transcript showCR:entry.
- sock close
- ]
- [exEnd]
+ sock close
+ ]
+ [exEnd]
example (connect to an ftp server):
- [exBegin]
- |sock host|
+ [exBegin]
+ |sock host|
- host := OperatingSystem getHostName.
- sock := Socket newTCPclientToHost:host port:'ftp'.
+ host := OperatingSystem getHostName.
+ sock := Socket newTCPclientToHost:host port:'ftp'.
- sock buffered:false.
- Transcript showCR:sock nextLine.
- sock nextPutAll:('USER ' , 'anonymous'); cr.
- Transcript showCR:sock nextLine.
- sock nextPutAll:('PASS ' , 'fooBar'); cr.
- Transcript showCR:sock nextLine.
- sock nextPutAll:'LIST'; cr.
- Transcript showCR:sock nextLine.
- sock close.
+ sock buffered:false.
+ Transcript showCR:sock nextLine.
+ sock nextPutAll:('USER ' , 'anonymous'); cr.
+ Transcript showCR:sock nextLine.
+ sock nextPutAll:('PASS ' , 'fooBar'); cr.
+ Transcript showCR:sock nextLine.
+ sock nextPutAll:'LIST'; cr.
+ Transcript showCR:sock nextLine.
+ sock close.
- 'dont know enough of the ftp protocol to continue here ...'
- [exEnd]
+ 'dont know enough of the ftp protocol to continue here ...'
+ [exEnd]
example (connect to an snmp server [UDP]):
- [exBegin]
- |sock port|
+ [exBegin]
+ |sock port|
- sock := Socket newUDP.
- port := Socket portOfService:'snmp'.
- sock connectTo:(OperatingSystem getHostName) port:port.
- sock buffered:false.
- Transcript showCR:'got it'.
- sock close.
- [exEnd]
+ sock := Socket newUDP.
+ port := Socket portOfService:'snmp'.
+ sock connectTo:(OperatingSystem getHostName) port:port.
+ sock buffered:false.
+ Transcript showCR:'got it'.
+ sock close.
+ [exEnd]
example (await connection from a client and read some data):
- |connectSock sock|
+ |connectSock sock|
- connectSock := Socket newTCPserverAtPort:9998.
- connectSock isNil ifTrue:[
- Transcript showCR:'socket setup failed.'.
- ] ifFalse:[
- Transcript showCR:'listen ..'.
- (connectSock listenFor:5) ifFalse:[
- Transcript showCR:'listen failed.'.
- ] ifTrue:[
- Transcript showCR:'wait'.
- connectSock readWait.
- Transcript showCR:'accept'.
- sock := connectSock accept.
- sock isNil ifTrue:[
- Transcript showCR:'accept failed.'.
- ] ifFalse:[
- sock buffered:false.
- Transcript showCR:'server: got it'.
- 'can now do transfer via sock'.
- Transcript showCR:'read'.
- Transcript showCR:('got: ' , sock nextLine).
+ connectSock := Socket newTCPserverAtPort:9998.
+ connectSock isNil ifTrue:[
+ Transcript showCR:'socket setup failed.'.
+ ] ifFalse:[
+ Transcript showCR:'listen ..'.
+ (connectSock listenFor:5) ifFalse:[
+ Transcript showCR:'listen failed.'.
+ ] ifTrue:[
+ Transcript showCR:'wait'.
+ connectSock readWait.
+ Transcript showCR:'accept'.
+ sock := connectSock accept.
+ sock isNil ifTrue:[
+ Transcript showCR:'accept failed.'.
+ ] ifFalse:[
+ sock buffered:false.
+ Transcript showCR:'server: got it'.
+ 'can now do transfer via sock'.
+ Transcript showCR:'read'.
+ Transcript showCR:('got: ' , sock nextLine).
- Transcript showCR:'close'.
- sock close
- ].
- connectSock close.
- ]
- ]
+ Transcript showCR:'close'.
+ sock close
+ ].
+ connectSock close.
+ ]
+ ]
example (connect to above server and send some data):
- |sock|
+ |sock|
- sock := Socket newTCPclientToHost:(OperatingSystem getHostName) port:9998.
- sock isNil ifTrue:[
- Transcript showCR:'nope'
- ] ifFalse:[
- sock buffered:false.
- Transcript showCR:'client: got it'.
- 'can now do transfer via sock'.
- Transcript showCR:'sending <hello>'.
- sock nextPutLine:'hello'.
- sock close
- ]
+ sock := Socket newTCPclientToHost:(OperatingSystem getHostName) port:9998.
+ sock isNil ifTrue:[
+ Transcript showCR:'nope'
+ ] ifFalse:[
+ sock buffered:false.
+ Transcript showCR:'client: got it'.
+ 'can now do transfer via sock'.
+ Transcript showCR:'sending <hello>'.
+ sock nextPutLine:'hello'.
+ sock close
+ ]
example: UNIX domain socket (await connection from a client and read some data):
- |connectSock sock|
+ |connectSock sock|
- '/tmp/ud_socket' asFilename remove.
- connectSock := Socket newUNIXserverAt:'/tmp/ud_socket'.
- connectSock isNil ifTrue:[
- Transcript showCR:'socket setup failed.'.
- ] ifFalse:[
- Transcript showCR:'listen ..'.
- (connectSock listenFor:5) ifFalse:[
- Transcript showCR:'listen failed.'.
- ] ifTrue:[
- Transcript showCR:'wait'.
- connectSock buffered:false.
- connectSock readWait.
- Transcript showCR:'accept'.
- sock := connectSock accept.
- sock isNil ifTrue:[
- Transcript showCR:'accept failed.'.
- ] ifFalse:[
- sock buffered:false.
- Transcript showCR:'server: got it'.
- 'can now do transfer via sock'.
- Transcript showCR:'read'.
- Transcript showCR:('got: ' , sock nextLine).
+ '/tmp/ud_socket' asFilename remove.
+ connectSock := Socket newUNIXserverAt:'/tmp/ud_socket'.
+ connectSock isNil ifTrue:[
+ Transcript showCR:'socket setup failed.'.
+ ] ifFalse:[
+ Transcript showCR:'listen ..'.
+ (connectSock listenFor:5) ifFalse:[
+ Transcript showCR:'listen failed.'.
+ ] ifTrue:[
+ Transcript showCR:'wait'.
+ connectSock buffered:false.
+ connectSock readWait.
+ Transcript showCR:'accept'.
+ sock := connectSock accept.
+ sock isNil ifTrue:[
+ Transcript showCR:'accept failed.'.
+ ] ifFalse:[
+ sock buffered:false.
+ Transcript showCR:'server: got it'.
+ 'can now do transfer via sock'.
+ Transcript showCR:'read'.
+ Transcript showCR:('got: ' , sock nextLine).
- Transcript showCR:'close'.
- sock close
- ].
- connectSock close.
- ]
- ]
+ Transcript showCR:'close'.
+ sock close
+ ].
+ connectSock close.
+ ]
+ ]
example (connect to above server and send some data;
- Notice, this fails, if above server code is executed in the same ST/X image
- (at least on LINUX), since the OS does not correctly handle
- a connect from within an interrupted accept system call
- On SGI's SVR4, this works ok
+ Notice, this fails, if above server code is executed in the same ST/X image
+ (at least on LINUX), since the OS does not correctly handle
+ a connect from within an interrupted accept system call
+ On SGI's SVR4, this works ok
- |sock|
+ |sock|
- sock := Socket newUNIXclientTo:'/tmp/ud_socket'.
- sock isNil ifTrue:[
- Transcript showCR:'nope'
- ] ifFalse:[
- sock buffered:false.
- Transcript showCR:'client: got it'.
- 'can now do transfer via sock'.
- Transcript showCR:'sending <hello>'.
- sock nextPutLine:'hello'.
- sock close
- ]
+ sock := Socket newUNIXclientTo:'/tmp/ud_socket'.
+ sock isNil ifTrue:[
+ Transcript showCR:'nope'
+ ] ifFalse:[
+ sock buffered:false.
+ Transcript showCR:'client: got it'.
+ 'can now do transfer via sock'.
+ Transcript showCR:'sending <hello>'.
+ sock nextPutLine:'hello'.
+ sock close
+ ]
example: pingWalk (try to ping hosts on the local network)
- [exBegin]
- |myName myAddress list top hosts walkProcess port|
+ [exBegin]
+ |myName myAddress list top hosts walkProcess port|
- myName := OperatingSystem getHostName.
- myAddress := Socket ipAddressOfHost:myName.
+ myName := OperatingSystem getHostName.
+ myAddress := Socket ipAddressOfHost:myName.
- port := Socket portOfService:'echo'.
- port isNil ifTrue:[
- self error:'dont know echo port'.
- ^ self
- ].
+ port := Socket portOfService:'echo'.
+ port isNil ifTrue:[
+ self error:'dont know echo port'.
+ ^ self
+ ].
- top := StandardSystemView new.
- top label:'PING net walk'.
+ top := StandardSystemView new.
+ top label:'PING net walk'.
- list := ScrollableView for:ListView in:top.
- list origin:0.0@0.0 corner:1.0@1.0.
+ list := ScrollableView for:ListView in:top.
+ list origin:0.0@0.0 corner:1.0@1.0.
- top openAndWait.
+ top openAndWait.
- walkProcess := [
- |l low hi direction tryHostID dottedName hostName conn addr|
+ walkProcess := [
+ |l low hi direction tryHostID dottedName hostName conn addr|
- l := SortedCollection new.
+ l := SortedCollection new.
- ' only works with type C-net
- the code below could simply do 1 to:254 do:[:hostID }
- but, to probe likely hosts earlier, the probing is done
- ping-pong like around my ip-address (assuming, that other machines
- have numbers around my own)'.
+ ' only works with type C-net
+ the code below could simply do 1 to:254 do:[:hostID }
+ but, to probe likely hosts earlier, the probing is done
+ ping-pong like around my ip-address (assuming, that other machines
+ have numbers around my own)'.
- low := hi := (myAddress at:4).
- direction := 1.
+ low := hi := (myAddress at:4).
+ direction := 1.
- [low > 0 or:[hi < 255]] whileTrue:[
- direction > 0 ifTrue:[
- hi := hi + 1.
- tryHostID := hi.
- direction := -1.
- ] ifFalse:[
- low := low - 1.
- tryHostID := low.
- direction := 1.
- ].
- (tryHostID between:1 and:254) ifTrue:[
- dottedName := (myAddress at:1) printString
- , '.' , (myAddress at:2) printString
- , '.' , (myAddress at:3) printString
- , '.' , tryHostID printString.
+ [low > 0 or:[hi < 255]] whileTrue:[
+ direction > 0 ifTrue:[
+ hi := hi + 1.
+ tryHostID := hi.
+ direction := -1.
+ ] ifFalse:[
+ low := low - 1.
+ tryHostID := low.
+ direction := 1.
+ ].
+ (tryHostID between:1 and:254) ifTrue:[
+ dottedName := (myAddress at:1) printString
+ , '.' , (myAddress at:2) printString
+ , '.' , (myAddress at:3) printString
+ , '.' , tryHostID printString.
- top label:'PING net walk - trying ' , dottedName.
+ top label:'PING net walk - trying ' , dottedName.
- top windowGroup withCursor:Cursor wait do:[
- conn := Socket newTCPclientToHost:dottedName port:port withTimeout:1000.
- conn notNil ifTrue:[
- addr := Socket ipAddressOfHost:dottedName.
- hostName := Socket hostWithIpAddress:addr.
- hostName isNil ifTrue:[
- hostName :='?'
- ].
- l add:(dottedName paddedTo:15 with:Character space)
- , ' '
- , (hostName paddedTo:15 with:Character space)
- , ' up & reachable'.
- list list:l.
- conn close.
- ]
- ].
- ].
- ].
- top label:'PING reachable hosts'.
- ] forkAt:(Processor userBackgroundPriority).
- walkProcess name:'ping net walker'.
- [exEnd]
+ top windowGroup withCursor:Cursor wait do:[
+ conn := Socket newTCPclientToHost:dottedName port:port withTimeout:1000.
+ conn notNil ifTrue:[
+ addr := Socket ipAddressOfHost:dottedName.
+ hostName := Socket hostWithIpAddress:addr.
+ hostName isNil ifTrue:[
+ hostName :='?'
+ ].
+ l add:(dottedName paddedTo:15 with:Character space)
+ , ' '
+ , (hostName paddedTo:15 with:Character space)
+ , ' up & reachable'.
+ list list:l.
+ conn close.
+ ]
+ ].
+ ].
+ ].
+ top label:'PING reachable hosts'.
+ ] forkAt:(Processor userBackgroundPriority).
+ walkProcess name:'ping net walker'.
+ [exEnd]
"
! !
@@ -1422,18 +1422,19 @@
!
bindTo:aSocketAddress
- "ST80 compatible bind:
- the socketAddress object is supposed to respond to
- portOrName and address requests."
+ "ST80 compatible bind, expecting a socketAddress argument.
+ The socketAddress object (an instance of SocketAddress)
+ is supposed to respond to #portOrName and #address requests."
^ self bindTo:(aSocketAddress portOrName)
address:(aSocketAddress address)
+ reuseAddress:true
!
-bindTo:portNrOrName address:address
+bindTo:portNrOrNameString address:addressString
"low level bind - returns true if ok, false otherwise.
Currently only non-address binding is supported;
- i.e. address must always be nil.
+ i.e. the address must always be nil.
The interpretation of portNrOrName depends on the domain:
inet domain uses (4byte) byteArray like internet numbers,
@@ -1441,7 +1442,10 @@
others use whatever will come up in the future
"
- ^ self bindTo:portNrOrName address:address reuseAddress:true
+ ^ self
+ bindTo:portNrOrNameString
+ address:addressString
+ reuseAddress:true
!
bindTo:portNrOrName address:address reuseAddress:reuse
@@ -1453,7 +1457,10 @@
inet domain uses (4byte) byteArray like internet numbers,
unix domain uses pathname strings,
others use whatever will come up in the future
- "
+
+ The reuse boolean argument controls if the SO_REUSEADDR socket option
+ is to be set (to avoid the 'bind: address in use' error).
+ "
filePointer isNil ifTrue:[
^ self error:'not a valid socket'
@@ -1601,22 +1608,22 @@
Return the true if ok; false if not.
NOTICE: this method will block, if no connection is already pending.
- use readWait or Socket>>accept."
+ use readWait or Socket>>accept."
|serverSocketFd|
filePointer notNil ifTrue:[
- ^ self error:'already connected'
+ ^ self error:'already connected'
].
domain := aSocket domain.
socketType := aSocket type.
serverSocketFd := aSocket fileDescriptor.
serverSocketFd isNil ifTrue:[
- ^ self error:'invalid server socket'
+ ^ self error:'invalid server socket'
].
(serverSocketFd isMemberOf:SmallInteger) ifFalse:[
- ^ self error:'invalid server socket'
+ ^ self error:'invalid server socket'
].
%{
#ifndef NO_SOCKET
@@ -1624,8 +1631,8 @@
int flags;
int sock, newSock;
union {
- struct sockaddr_in in ;
- struct sockaddr_un un ;
+ struct sockaddr_in in ;
+ struct sockaddr_un un ;
} sa;
int alen;
struct hostent *he ;
@@ -1639,8 +1646,8 @@
#endif
__BEGIN_INTERRUPTABLE__
do {
- alen = sizeof(sa) ;
- newSock = accept(sock, (struct sockaddr *) &sa, &alen);
+ alen = sizeof(sa) ;
+ newSock = accept(sock, (struct sockaddr *) &sa, &alen);
} while ((newSock < 0) && (errno == EINTR));
__END_INTERRUPTABLE__
@@ -1649,9 +1656,9 @@
#endif
if (newSock < 0) {
- DBGPRINTF(("SOCKET: accept call failed errno=%d\n", errno));
- __INST(lastErrorNumber) = __MKSMALLINT(errno);
- RETURN (false);
+ DBGPRINTF(("SOCKET: accept call failed errno=%d\n", errno));
+ __INST(lastErrorNumber) = __MKSMALLINT(errno);
+ RETURN (false);
}
/*
@@ -1659,26 +1666,26 @@
*/
#ifdef AF_INET
if (__INST(domain) == @symbol(inet)) {
- he = gethostbyaddr((char *) &sa.in.sin_addr.s_addr, alen, AF_INET) ;
- if (! he) {
- unsigned long norder;
+ he = gethostbyaddr((char *) &sa.in.sin_addr.s_addr, alen, AF_INET) ;
+ if (! he) {
+ unsigned long norder;
- norder = htonl(sa.in.sin_addr.s_addr) ;
- sprintf(dotted, "%d.%d.%d.%d",
- (norder >> 24) & 0xFF,
- (norder >> 16) & 0xFF,
- (norder >> 8) & 0xFF,
- norder & 0xFF);
- }
- DBGPRINTF(("SOCKET: accepted connection from host %s\n", (he ? he->h_name : dotted))) ;
- __INST(peerName) = __MKSTRING((he ? he->h_name : dotted) COMMA_CON);
- __STORESELF(peerName);
+ norder = htonl(sa.in.sin_addr.s_addr) ;
+ sprintf(dotted, "%d.%d.%d.%d",
+ (norder >> 24) & 0xFF,
+ (norder >> 16) & 0xFF,
+ (norder >> 8) & 0xFF,
+ norder & 0xFF);
+ }
+ DBGPRINTF(("SOCKET: accepted connection from host %s\n", (he ? he->h_name : dotted))) ;
+ __INST(peerName) = __MKSTRING((he ? he->h_name : dotted) COMMA_CON);
+ __STORESELF(peerName);
}
#endif
#ifdef AF_UNIX
if (__INST(domain) == @symbol(unix)) {
- DBGPRINTF(("SOCKET: accepted connection on unix socket\n")) ;
- /* nothing to be done here */
+ DBGPRINTF(("SOCKET: accepted connection on unix socket\n")) ;
+ /* nothing to be done here */
}
#endif
@@ -1687,17 +1694,17 @@
*/
fp = fdopen(newSock, "r+");
if (! fp) {
- DBGPRINTF(("SOCKET: fdopen call failed\n"));
- __INST(lastErrorNumber) = __MKSMALLINT(errno);
- close(newSock);
- RETURN (false);
+ DBGPRINTF(("SOCKET: fdopen call failed\n"));
+ __INST(lastErrorNumber) = __MKSMALLINT(errno);
+ close(newSock);
+ RETURN (false);
} else {
#ifdef NO_BUFFER
- setbuf(fp, NULL);
- __INST(buffered) = false;
+ setbuf(fp, NULL);
+ __INST(buffered) = false;
#endif
- __INST(filePointer) = __MKOBJ(fp);
- __STORESELF(filePointer);
+ __INST(filePointer) = __MKOBJ(fp);
+ __STORESELF(filePointer);
}
#endif
%}.
@@ -2073,7 +2080,7 @@
|errorNr|
filePointer notNil ifTrue:[
- ^ self error:'already created'
+ ^ self error:'already created'
].
%{
#ifndef NO_SOCKET
@@ -2081,19 +2088,19 @@
int dom, typ, pf, proto = 0, sock;
if (! __isSymbol(domainArg)) {
- DBGPRINTF(("SOCKET: bad domain\n"));
- RETURN ( nil );
+ DBGPRINTF(("SOCKET: bad domain\n"));
+ RETURN ( nil );
}
if (! __isSymbol(typeArg)) {
- DBGPRINTF(("SOCKET: bad type\n"));
- RETURN ( nil );
+ DBGPRINTF(("SOCKET: bad type\n"));
+ RETURN ( nil );
}
if (protocolNumber != nil) {
- if (!__isSmallInteger(protocolNumber)) {
- DBGPRINTF(("SOCKET: bad protocol\n"));
- RETURN ( nil );
- }
- proto = __intVal(protocolNumber);
+ if (!__isSmallInteger(protocolNumber)) {
+ DBGPRINTF(("SOCKET: bad protocol\n"));
+ RETURN ( nil );
+ }
+ proto = __intVal(protocolNumber);
}
@@ -2102,117 +2109,117 @@
*/
#ifdef AF_UNIX
if (domainArg == @symbol(unix)) {
- dom = AF_UNIX;
+ dom = AF_UNIX;
} else
#endif
#ifdef AF_INET
if (domainArg == @symbol(inet)) {
- dom = AF_INET;
+ dom = AF_INET;
} else
#endif
#ifdef AF_DECnet
if (domainArg == @symbol(DECnet)) {
- dom = AF_DECnet;
+ dom = AF_DECnet;
} else
#endif
#ifdef AF_APPLETALK
if (domainArg == @symbol(appletalk)) {
- dom = AF_APPLETALK;
+ dom = AF_APPLETALK;
} else
#endif
#ifdef AF_X25
if (domainArg == @symbol(x25)) {
- dom = AF_X25;
+ dom = AF_X25;
} else
#endif
#ifdef AF_NS
if (domainArg == @symbol(xns)) {
- dom = AF_NS;
+ dom = AF_NS;
} else
#endif
#ifdef AF_SNA
if (domainArg == @symbol(sna)) {
- dom = AF_SNA;
+ dom = AF_SNA;
} else
#endif
#ifdef AF_RAW
if (domainArg == @symbol(raw)) {
- dom = AF_RAW;
+ dom = AF_RAW;
} else
#endif
{
- DBGPRINTF(("SOCKET: unknown domain <%s>\n", _stringVal(domainArg)));
- RETURN ( nil );
+ DBGPRINTF(("SOCKET: unknown domain <%s>\n", _stringVal(domainArg)));
+ RETURN ( nil );
}
#ifdef SOCK_STREAM
if (typeArg == @symbol(stream)) {
- typ = SOCK_STREAM;
+ typ = SOCK_STREAM;
} else
#endif
#ifdef SOCK_DGRAM
if (typeArg == @symbol(datagram)) {
- typ = SOCK_DGRAM;
+ typ = SOCK_DGRAM;
} else
#endif
#ifdef SOCK_RAW
if (typeArg == @symbol(raw))
- typ = SOCK_RAW;
+ typ = SOCK_RAW;
else
#endif
#ifdef SOCK_SEQPACKET
if (typeArg == @symbol(seqPacket))
- typ = SOCK_SEQPACKET;
+ typ = SOCK_SEQPACKET;
else
#endif
{
- DBGPRINTF(("SOCKET: bad type <%s>\n", _stringVal(typeArg)));
- RETURN ( nil );
+ DBGPRINTF(("SOCKET: bad type <%s>\n", _stringVal(typeArg)));
+ RETURN ( nil );
}
__BEGIN_INTERRUPTABLE__
do {
- DBGPRINTF(("SOCKET: opening socket domain=%d type=%d proto=%d\n", dom, typ, proto));
- sock = socket(dom, typ, proto);
+ DBGPRINTF(("SOCKET: opening socket domain=%d type=%d proto=%d\n", dom, typ, proto));
+ sock = socket(dom, typ, proto);
#if defined(EPROTONOSUPPORT) /* for SGI */
- if ((proto != 0) && (sock < 0) && (errno == EPROTONOSUPPORT)) {
- DBGPRINTF(("SOCKET: retry with UNSPEC protocol\n"));
- proto = 0;
- sock = socket(dom, typ, 0);
- }
+ if ((proto != 0) && (sock < 0) && (errno == EPROTONOSUPPORT)) {
+ DBGPRINTF(("SOCKET: retry with UNSPEC protocol\n"));
+ proto = 0;
+ sock = socket(dom, typ, 0);
+ }
#endif
} while ((sock < 0) && (errno == EINTR));
__END_INTERRUPTABLE__
if (sock < 0) {
- DBGPRINTF(("SOCKET: socket(dom=%d typ=%d proto=%d) call failed errno=%d\n", dom, typ, proto, errno));
- __INST(lastErrorNumber) = __MKSMALLINT(errno);
+ DBGPRINTF(("SOCKET: socket(dom=%d typ=%d proto=%d) call failed errno=%d\n", dom, typ, proto, errno));
+ __INST(lastErrorNumber) = __MKSMALLINT(errno);
} else {
- /*
- * make it a FILE *
- */
- fp = fdopen(sock, "r+");
- if (! fp) {
- DBGPRINTF(("SOCKET: fdopen call failed\n"));
- __INST(lastErrorNumber) = __MKSMALLINT(errno);
- __BEGIN_INTERRUPTABLE__
- close(sock);
- __END_INTERRUPTABLE__
- } else {
- __INST(filePointer) = __MKOBJ(fp);
- __STORESELF(filePointer);
- }
+ /*
+ * make it a FILE *
+ */
+ fp = fdopen(sock, "r+");
+ if (! fp) {
+ DBGPRINTF(("SOCKET: fdopen call failed\n"));
+ __INST(lastErrorNumber) = __MKSMALLINT(errno);
+ __BEGIN_INTERRUPTABLE__
+ close(sock);
+ __END_INTERRUPTABLE__
+ } else {
+ __INST(filePointer) = __MKOBJ(fp);
+ __STORESELF(filePointer);
+ }
}
#endif
%}.
"all ok?"
filePointer notNil ifTrue:[
- domain := domainArg.
- socketType := typeArg.
- Lobby register:self.
+ domain := domainArg.
+ socketType := typeArg.
+ Lobby register:self.
] ifFalse:[
- ^ nil
+ ^ nil
].
"
@@ -2334,7 +2341,7 @@
__INST(buffered) = false;
#endif
__INST(filePointer) = __MKOBJ(fp);
- __STORESELF(filePointer);
+ __STORESELF(filePointer);
}
}
}
@@ -2463,7 +2470,7 @@
__INST(buffered) = false;
#endif
__INST(filePointer) = __MKOBJ(fp);
- __STORESELF(filePointer);
+ __STORESELF(filePointer);
}
}
}
@@ -2548,5 +2555,5 @@
!Socket class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.66 1996-07-22 19:46:21 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.67 1996-07-27 09:05:54 cg Exp $'
! !