Socket.st
author Claus Gittinger <cg@exept.de>
Mon, 03 Sep 2012 22:23:42 +0200
changeset 2818 94d67df5c00d
parent 2773 ab3049f4a351
child 2823 10179ccfae5d
permissions -rw-r--r--
compilable with tcc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     1
"
4
1f66800df351 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1992 by Claus Gittinger
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
     3
	      All Rights Reserved
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     4
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    11
"
888
a868b0e54a2b ipAddress stuff
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
    12
"{ Package: 'stx:libbasic2' }"
a868b0e54a2b ipAddress stuff
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
    13
63
7dd3d5b7877e *** empty log message ***
claus
parents: 58
diff changeset
    14
NonPositionableExternalStream subclass:#Socket
1505
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
    15
	instanceVariableNames:'domain socketType protocol port serviceName peer peerName
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
    16
		listening'
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
    17
	classVariableNames:''
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
    18
	poolDictionaries:''
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
    19
	category:'Streams-External'
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    20
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    21
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    22
!Socket primitiveDefinitions!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    23
%{
444
9ba31a1fba38 always unbuffered on linux
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
    24
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
    25
/* #define DGRAM_DEBUG /* */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
    26
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
    27
#include "stxOSDefs.h"
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    28
1503
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
    29
#ifdef WIN32
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
    30
2818
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2773
diff changeset
    31
/* this is to catch uses of those - there should be none */
1503
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
    32
# undef __BEGIN_INTERRUPTABLE__
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
    33
# undef __END_INTERRUPTABLE__
2818
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2773
diff changeset
    34
# ifdef __TCC__
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2773
diff changeset
    35
#  define __BEGIN_INTERRUPTABLE__ xxxx
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2773
diff changeset
    36
#  define __END_INTERRUPTABLE__ yyyy
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2773
diff changeset
    37
# else
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2773
diff changeset
    38
#  define __BEGIN_INTERRUPTABLE__ ..
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2773
diff changeset
    39
#  define __END_INTERRUPTABLE__ ..
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2773
diff changeset
    40
# endif
1503
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
    41
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
    42
# define WRAP_STDIO
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    43
# define SET_LINGER_WHEN_CREATING_SOCKET
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    44
1845
df4d79bfba9d closesocket is still tricky
Claus Gittinger <cg@exept.de>
parents: 1844
diff changeset
    45
/*
df4d79bfba9d closesocket is still tricky
Claus Gittinger <cg@exept.de>
parents: 1844
diff changeset
    46
 * mhmh - WIN32-fclose  has a problem in trying to close() the socket
df4d79bfba9d closesocket is still tricky
Claus Gittinger <cg@exept.de>
parents: 1844
diff changeset
    47
 * instead of closesocket()'ing it
df4d79bfba9d closesocket is still tricky
Claus Gittinger <cg@exept.de>
parents: 1844
diff changeset
    48
 */
df4d79bfba9d closesocket is still tricky
Claus Gittinger <cg@exept.de>
parents: 1844
diff changeset
    49
# ifdef WIN32
df4d79bfba9d closesocket is still tricky
Claus Gittinger <cg@exept.de>
parents: 1844
diff changeset
    50
#  define CLOSESOCKET_AFTER_FCLOSE
df4d79bfba9d closesocket is still tricky
Claus Gittinger <cg@exept.de>
parents: 1844
diff changeset
    51
#  define xxCLOSESOCKET_BEFORE_FCLOSE
df4d79bfba9d closesocket is still tricky
Claus Gittinger <cg@exept.de>
parents: 1844
diff changeset
    52
# endif
df4d79bfba9d closesocket is still tricky
Claus Gittinger <cg@exept.de>
parents: 1844
diff changeset
    53
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
    54
#  ifdef __BORLANDC__
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    55
# define SOCKET_FROM_FD(fd)               (_get_osfhandle(fd))
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
    56
#  else
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
    57
# define SOCKET_FROM_FD(fd)               (fd)
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
    58
#  endif
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
    59
#else /* not WIN32 */
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
    60
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    61
# define SOCKET_FROM_FD(fd)               (fd)
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    62
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
    63
#endif /* WIN32 */
1503
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
    64
1843
8ee90d243b49 closeSocket after fclose: no longer (Q: is this the right thing)
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
    65
#define SOCKET_FROM_FILE(f)             (SOCKET_FROM_FD(fileno(f)))
8ee90d243b49 closeSocket after fclose: no longer (Q: is this the right thing)
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
    66
#define SOCKET_FROM_FILE_OBJECT(f)      (SOCKET_FROM_FILE(__FILEVal(f)))
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
    67
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    68
#ifndef WIN32
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    69
# define closesocket(sock)    close(sock)
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
    70
# define SOCKET               int
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    71
#endif
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    72
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    73
#include <stdio.h>
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    74
#include <errno.h>
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    75
2516
592619f82885 Add setsockopt for Multicast stuff
Stefan Vogel <sv@exept.de>
parents: 2465
diff changeset
    76
#ifdef WIN32
2818
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2773
diff changeset
    77
# ifdef __BORLANDC__
2579
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
    78
#  include <Ws2tcpip.h>
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
    79
# endif
2516
592619f82885 Add setsockopt for Multicast stuff
Stefan Vogel <sv@exept.de>
parents: 2465
diff changeset
    80
#else
592619f82885 Add setsockopt for Multicast stuff
Stefan Vogel <sv@exept.de>
parents: 2465
diff changeset
    81
# include <netinet/ip.h>
592619f82885 Add setsockopt for Multicast stuff
Stefan Vogel <sv@exept.de>
parents: 2465
diff changeset
    82
#endif
592619f82885 Add setsockopt for Multicast stuff
Stefan Vogel <sv@exept.de>
parents: 2465
diff changeset
    83
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
    84
#ifdef WANT__TCP_DOT_H
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
    85
# include <netinet/tcp.h>
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
    86
#endif
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
    87
1344
70d73917ac78 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1343
diff changeset
    88
#ifdef WANT__NETDB_DOT_H
70d73917ac78 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1343
diff changeset
    89
# include <netdb.h>
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
    90
#endif
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
    91
739
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    92
#if defined(TRY_AGAIN) || defined(HOST_NOT_FOUND)
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    93
# define USE_H_ERRNO
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    94
#endif
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    95
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    96
/*
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    97
 * on some systems errno is a macro ... check for it here
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    98
 */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    99
#ifndef errno
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   100
 extern errno;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   101
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   102
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   103
#ifdef USE_H_ERRNO
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   104
# ifndef h_errno
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   105
 extern h_errno;
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   106
# endif
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   107
#endif
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   108
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   109
#ifdef DEBUG
1839
c10cd58ec334 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
   110
# define DBGPRINTF(x)    { if (__debugging__) console_printf x; }
c10cd58ec334 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
   111
# define DBGFPRINTF(x)   { if (__debugging__) console_fprintf x; }
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   112
#else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   113
# define DBGPRINTF(x)    /* as nothing */
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
   114
# define DBGFPRINTF(x)   /* as nothing */
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   115
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   116
1531
ec98158988ca compilable under unix
Claus Gittinger <cg@exept.de>
parents: 1529
diff changeset
   117
#ifndef TRUE
1535
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
   118
# define TRUE   1
1531
ec98158988ca compilable under unix
Claus Gittinger <cg@exept.de>
parents: 1529
diff changeset
   119
#endif
ec98158988ca compilable under unix
Claus Gittinger <cg@exept.de>
parents: 1529
diff changeset
   120
#ifndef FALSE
1535
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
   121
# define FALSE  0
1531
ec98158988ca compilable under unix
Claus Gittinger <cg@exept.de>
parents: 1529
diff changeset
   122
#endif
ec98158988ca compilable under unix
Claus Gittinger <cg@exept.de>
parents: 1529
diff changeset
   123
#ifndef WIN32
ec98158988ca compilable under unix
Claus Gittinger <cg@exept.de>
parents: 1529
diff changeset
   124
typedef int BOOL;
ec98158988ca compilable under unix
Claus Gittinger <cg@exept.de>
parents: 1529
diff changeset
   125
#endif
ec98158988ca compilable under unix
Claus Gittinger <cg@exept.de>
parents: 1529
diff changeset
   126
1843
8ee90d243b49 closeSocket after fclose: no longer (Q: is this the right thing)
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   127
#ifdef WIN32
8ee90d243b49 closeSocket after fclose: no longer (Q: is this the right thing)
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   128
# undef stdout
8ee90d243b49 closeSocket after fclose: no longer (Q: is this the right thing)
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   129
# undef stderr
8ee90d243b49 closeSocket after fclose: no longer (Q: is this the right thing)
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   130
# define stdout __win32_stdout()
8ee90d243b49 closeSocket after fclose: no longer (Q: is this the right thing)
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   131
# define stderr __win32_stderr()
8ee90d243b49 closeSocket after fclose: no longer (Q: is this the right thing)
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   132
#endif
1531
ec98158988ca compilable under unix
Claus Gittinger <cg@exept.de>
parents: 1529
diff changeset
   133
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   134
%}
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   135
! !
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   136
511
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   137
!Socket primitiveVariables!
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   138
%{
1844
decc9d62520d oops - debug
Claus Gittinger <cg@exept.de>
parents: 1843
diff changeset
   139
static int __debugging__ = 0;
511
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   140
%}
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   141
! !
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   142
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   143
!Socket primitiveFunctions!
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   144
%{
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   145
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   146
static int
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   147
setupBufferParameters(aDataBuffer, startIndex, p_extPtr, p_offs, p_objSize)
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   148
    OBJ aDataBuffer, startIndex;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   149
    char **p_extPtr;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   150
    int *p_offs;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   151
    int *p_objSize;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   152
{
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   153
	char *extPtr = 0;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   154
	int sIdx = 0, objSize = 0, offs = 0;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   155
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   156
	sIdx = 0;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   157
	if (__isSmallInteger(startIndex)) {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   158
	    sIdx = __intVal(startIndex) - 1;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   159
	}
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   160
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   161
	if (__isExternalBytesLike(aDataBuffer)) {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   162
	    OBJ sz;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   163
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   164
	    extPtr = (char *)(__externalBytesAddress(aDataBuffer));
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   165
	    sz = __externalBytesSize(aDataBuffer);
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   166
	    if (__isSmallInteger(sz)) {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   167
		objSize = __intVal(sz);
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   168
	    } else {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   169
		objSize = 0; /* unknown */
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   170
	    }
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   171
	    offs = sIdx;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   172
	} else {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   173
	    OBJ oClass;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   174
	    int nInstVars, nInstBytes;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   175
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   176
	    extPtr = (char *)0;
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   177
	    oClass = __Class(aDataBuffer);
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   178
	    switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   179
		case BYTEARRAY:
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   180
		    offs = sIdx;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   181
		    break;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   182
		case WORDARRAY:
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   183
		case SWORDARRAY:
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   184
		    offs = sIdx * 2;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   185
		    break;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   186
		case LONGARRAY:
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   187
		case SLONGARRAY:
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   188
		    offs = sIdx * 4;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   189
		    break;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   190
		case LONGLONGARRAY:
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   191
		case SLONGLONGARRAY:
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   192
		    offs = sIdx * 8;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   193
# ifdef __NEED_LONGLONG_ALIGN
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   194
		    offs += 4;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   195
# endif
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   196
		    break;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   197
		case FLOATARRAY:
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   198
		    offs = sIdx * sizeof(float);
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   199
		    break;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   200
		case DOUBLEARRAY:
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   201
		    offs = sIdx * sizeof(double);
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   202
# ifdef __NEED_DOUBLE_ALIGN
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   203
		    offs += 4;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   204
# endif
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   205
		    break;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   206
		default:
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   207
		    *p_objSize = -1;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   208
		    return 0;
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   209
	    }
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   210
	    nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   211
	    nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ);
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   212
	    offs = offs + nInstBytes;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   213
	    objSize = _Size(aDataBuffer) - offs;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   214
	}
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   215
	*p_extPtr = extPtr;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   216
	*p_objSize = objSize;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   217
	*p_offs = offs;
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   218
	return 1;
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   219
}
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   220
%}
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   221
! !
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   222
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
   223
!Socket class methodsFor:'documentation'!
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   224
31
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   225
copyright
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   226
"
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   227
 COPYRIGHT (c) 1992 by Claus Gittinger
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   228
	      All Rights Reserved
31
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   229
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   230
 This software is furnished under a license and may be used
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   231
 only in accordance with the terms of that license and with the
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   232
 inclusion of the above copyright notice.   This software may not
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   233
 be provided or otherwise made available to, or used by, any
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   234
 other person.  No title to or ownership of the software is
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   235
 hereby transferred.
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   236
"
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   237
!
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   238
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   239
documentation
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   240
"
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
   241
    This class provides access to sockets for interprocess communication.
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   242
    The message protocol is preliminary, until someone tells me how
31
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   243
    other smalltalk's socket interfaces look like.
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   244
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   245
    Currently, only IP and UNIX domain sockets are really fully
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   246
    tested and supported.
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   247
    Code for appletalk is included, but was never tested ...
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   248
    More may be added in the future.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   249
    (the code is prepared for things like SNA or decNet;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   250
     however, right now, this code is empty and needs a little work.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   251
     Implementing those is pretty straight forward, once the address
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   252
     data structures are known.)
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
   253
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   254
    Due to historic reasons (I started this class, before I got hold of some
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   255
    code using ST-80 Sockets i.e. RemoteInvocation), there is some old interface
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   256
    still provided.
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
   257
    This will vanish; use the #family:type: or #newTCPxxx and #newUDPxxx interfaces,
71
claus
parents: 63
diff changeset
   258
    together with the bind/listen and accept calls,
claus
parents: 63
diff changeset
   259
    which are meant to be compatible to ST-80's UnixSocketAccessor interface.
claus
parents: 63
diff changeset
   260
claus
parents: 63
diff changeset
   261
    TODO: cleanup historic leftovers, implement other than inet domain stuff.
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
   262
	  (mhmh - how can I test those ?)
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
   263
	  change to raise more signals on errors.
529
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   264
	  Help - could someone who has a linux machine connected to an appletalk
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
   265
		 net please test this (and send bug fixes ...)
259
6d36f3ac42a2 documentation
Claus Gittinger <cg@exept.de>
parents: 220
diff changeset
   266
6d36f3ac42a2 documentation
Claus Gittinger <cg@exept.de>
parents: 220
diff changeset
   267
    [author:]
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   268
	Claus Gittinger
48
18b9353c9d07 *** empty log message ***
claus
parents: 44
diff changeset
   269
"
18b9353c9d07 *** empty log message ***
claus
parents: 44
diff changeset
   270
!
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   271
48
18b9353c9d07 *** empty log message ***
claus
parents: 44
diff changeset
   272
examples
18b9353c9d07 *** empty log message ***
claus
parents: 44
diff changeset
   273
"
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   274
    example (get help info from an nntp server):
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   275
									[exBegin]
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   276
	|sock host|
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   277
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   278
	host := OperatingSystem getEnvironment:'NNTPSERVER'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   279
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   280
	sock := Socket newTCPclientToHost:host port:'nntp'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   281
	sock isNil ifTrue:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   282
	    self warn:'no nntp daemon is running'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   283
	    ^ self
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   284
	].
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   285
	Transcript showCR:sock nextLine.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   286
	sock buffered:false.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   287
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   288
	sock nextPutAll:'HELP'; cr.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   289
	[:exit |
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   290
	    |line|
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   291
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   292
	    line := sock nextLine.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   293
	    line = '.' ifTrue:[exit value:nil].
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   294
	    Transcript showCR:line.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   295
	] loopWithExit.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   296
	sock close
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   297
									[exEnd]
209
2152fceba563 finger example
Claus Gittinger <cg@exept.de>
parents: 208
diff changeset
   298
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   299
209
2152fceba563 finger example
Claus Gittinger <cg@exept.de>
parents: 208
diff changeset
   300
    example (connect to finger daemon, get users entry):
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   301
									[exBegin]
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   302
	|sock host entry|
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   303
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   304
	host := OperatingSystem getHostName.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   305
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   306
	sock := Socket newTCPclientToHost:host port:'finger'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   307
	sock isNil ifTrue:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   308
	    self warn:'no finger daemon is running'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   309
	    ^ self
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   310
	].
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   311
	sock useCRLF:true.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   312
	sock buffered:false.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   313
	sock isNil ifTrue:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   314
	    Transcript showCR:'cannot connect to local finger daemon'
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   315
	] ifFalse:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   316
	    sock nextPutAll:(OperatingSystem getLoginName).
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   317
	    sock cr.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   318
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   319
	    entry := sock nextLine.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   320
	    Transcript showCR:entry.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   321
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   322
	    sock close
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   323
	]
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   324
									[exEnd]
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   325
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   326
    example (connect to an ftp server):
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   327
									[exBegin]
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   328
	|sock host|
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   329
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   330
	host := OperatingSystem getHostName.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   331
	sock := Socket newTCPclientToHost:host port:'ftp'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   332
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   333
	sock buffered:false.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   334
	Transcript showCR:sock nextLine.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   335
	sock nextPutAll:('USER ' , 'anonymous'); cr.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   336
	Transcript showCR:sock nextLine.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   337
	sock nextPutAll:('PASS ' , 'fooBar'); cr.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   338
	Transcript showCR:sock nextLine.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   339
	sock nextPutAll:'LIST'; cr.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   340
	Transcript showCR:sock nextLine.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   341
	sock close.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   342
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   343
	'dont know enough of the ftp protocol to continue here ...'
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   344
									[exEnd]
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   345
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   346
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
   347
    example (connect to an snmp server [UDP]):
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   348
									[exBegin]
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   349
	|sock port|
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   350
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   351
	sock := Socket newUDP.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   352
	port := Socket portOfService:'snmp'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   353
	sock connectTo:(OperatingSystem getHostName) port:port.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   354
	sock buffered:false.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   355
	Transcript showCR:'got it'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   356
	sock close.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   357
									[exEnd]
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   358
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   359
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   360
    example (await connection from a client and read some data):
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   361
									[exBegin]
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   362
	|connectSock sock|
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   363
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   364
	connectSock := Socket newTCPserverAtPort:9998.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   365
	connectSock isNil ifTrue:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   366
	    Transcript showCR:'socket setup failed.'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   367
	] ifFalse:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   368
	    Transcript showCR:'listen ..'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   369
	    (connectSock listenFor:5) ifFalse:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   370
		Transcript showCR:'listen failed.'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   371
	    ] ifTrue:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   372
		Transcript showCR:'wait'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   373
		connectSock readWait.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   374
		Transcript showCR:'accept'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   375
		sock := connectSock accept.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   376
		sock isNil ifTrue:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   377
		    Transcript showCR:'accept failed.'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   378
		] ifFalse:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   379
		    sock buffered:false.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   380
		    Transcript showCR:'server: got it'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   381
		    'can now do transfer via sock'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   382
		    Transcript showCR:'read'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   383
		    Transcript showCR:('got: ' , sock nextLine).
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   384
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   385
		    Transcript showCR:'close'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   386
		    sock close
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   387
		].
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   388
		connectSock close.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   389
	    ]
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   390
	]
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   391
									[exEnd]
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   392
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   393
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   394
    example (connect to above server and send some data):
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   395
									[exBegin]
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   396
	|sock|
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   397
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   398
	sock := Socket newTCPclientToHost:(OperatingSystem getHostName) port:9998.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   399
	sock isNil ifTrue:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   400
	    Transcript showCR:'nope'
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   401
	] ifFalse:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   402
	    sock buffered:false.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   403
	    Transcript showCR:'client: got it'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   404
	    'can now do transfer via sock'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   405
	    Transcript showCR:'sending <hello>'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   406
	    sock nextPutLine:'hello'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   407
	    sock close
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   408
	]
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   409
									[exEnd]
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
   410
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
   411
    example: UNIX domain socket (await connection from a client and read some data):
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   412
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   413
	|connectSock sock|
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   414
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   415
	'/tmp/ud_socket' asFilename remove.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   416
	connectSock := Socket newUNIXserverAt:'/tmp/ud_socket'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   417
	connectSock isNil ifTrue:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   418
	    Transcript showCR:'socket setup failed.'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   419
	] ifFalse:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   420
	    Transcript showCR:'listen ..'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   421
	    (connectSock listenFor:5) ifFalse:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   422
		Transcript showCR:'listen failed.'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   423
	    ] ifTrue:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   424
		Transcript showCR:'wait'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   425
		connectSock buffered:false.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   426
		connectSock readWait.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   427
		Transcript showCR:'accept'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   428
		sock := connectSock accept.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   429
		sock isNil ifTrue:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   430
		    Transcript showCR:'accept failed.'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   431
		] ifFalse:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   432
		    sock buffered:false.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   433
		    Transcript showCR:'server: got it'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   434
		    'can now do transfer via sock'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   435
		    Transcript showCR:'read'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   436
		    Transcript showCR:('got: ' , sock nextLine).
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   437
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   438
		    Transcript showCR:'close'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   439
		    sock close
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   440
		].
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   441
		connectSock close.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   442
	    ]
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   443
	]
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
   444
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
   445
118
142d5c273454 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 117
diff changeset
   446
    example (connect to above server and send some data;
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   447
	     Notice, this fails, if above server code is executed in the same ST/X image
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   448
		     (at least on LINUX), since the OS does not correctly handle
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   449
		     a connect from within an interrupted accept system call
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   450
		     On SGI's SVR4, this works ok
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   451
									[exBegin]
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   452
	|sock|
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   453
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   454
	sock := Socket newUNIXclientTo:'/tmp/ud_socket'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   455
	sock isNil ifTrue:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   456
	    Transcript showCR:'nope'
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   457
	] ifFalse:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   458
	    sock buffered:false.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   459
	    Transcript showCR:'client: got it'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   460
	    'can now do transfer via sock'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   461
	    Transcript showCR:'sending <hello>'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   462
	    sock nextPutLine:'hello'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   463
	    sock close
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   464
	]
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   465
									[exEnd]
1007
5267b5738779 UDP examples
Claus Gittinger <cg@exept.de>
parents: 1004
diff changeset
   466
5267b5738779 UDP examples
Claus Gittinger <cg@exept.de>
parents: 1004
diff changeset
   467
5267b5738779 UDP examples
Claus Gittinger <cg@exept.de>
parents: 1004
diff changeset
   468
    example (UDP await packet from a client and read some data):
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   469
									[exBegin]
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   470
	|udpSock sock addr n dataBuffer|
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   471
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   472
	udpSock := Socket newUDPserverAtPort:9999.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   473
	udpSock isNil ifTrue:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   474
	    Transcript showCR:'socket setup failed.'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   475
	] ifFalse:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   476
	    Transcript showCR:'wait'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   477
	    udpSock readWait.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   478
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   479
	    addr := IPSocketAddress new.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   480
	    dataBuffer := ByteArray new:1000.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   481
	    n := udpSock receiveFrom:addr buffer:dataBuffer start:1 for:dataBuffer size.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   482
	    n > 0 ifTrue:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   483
		Transcript showCR:('got: ' , n printString , 'bytes  from ' , addr printString).
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   484
		Transcript showCR:('data: ' , (dataBuffer copyTo:n) printString).
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   485
	    ] ifFalse:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   486
		Transcript showCR:'read failed'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   487
	    ].
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   488
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   489
	    Transcript showCR:'close'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   490
	    udpSock close
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   491
	]
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   492
									[exEnd]
1007
5267b5738779 UDP examples
Claus Gittinger <cg@exept.de>
parents: 1004
diff changeset
   493
    example (connect to above UDP server and send some data;
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   494
									[exBegin]
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   495
	|sock|
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   496
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   497
	sock := Socket newUDP.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   498
	sock isNil ifTrue:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   499
	    Transcript showCR:'nope'
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   500
	] ifFalse:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   501
	    sock sendTo:(IPSocketAddress new hostName:'localhost' port:9999) buffer:'hello world'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   502
	    sock close
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   503
	]
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   504
									[exEnd]
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   505
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   506
    example: pingWalk (try to ping hosts on the local network)
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   507
									[exBegin]
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   508
	|myName myAddress list top hosts walkProcess port|
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   509
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   510
	myName := OperatingSystem getHostName.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   511
	myAddress := Socket ipAddressOfHost:myName.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   512
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   513
	port := Socket portOfService:'echo'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   514
	port isNil ifTrue:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   515
	    self error:'dont know echo port'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   516
	    ^ self
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   517
	].
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   518
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   519
	top := StandardSystemView new.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   520
	top label:'PING net walk'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   521
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   522
	list := ScrollableView for:ListView in:top.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   523
	list origin:0.0@0.0 corner:1.0@1.0.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   524
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   525
	top openAndWait.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   526
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   527
	walkProcess := [
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   528
	    |l low hi direction tryHostID dottedName hostName conn addr|
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   529
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   530
	    l := SortedCollection new.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   531
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   532
	    ' only works with type C-net
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   533
	      the code below could simply do 1 to:254 do:[:hostID }
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   534
	      but, to probe likely hosts earlier, the probing is done
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   535
	      ping-pong like around my ip-address (assuming, that other machines
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   536
	      have numbers around my own)'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   537
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   538
	    low := hi := (myAddress at:4).
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   539
	    direction := 1.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   540
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   541
	    [low > 0 or:[hi < 255]] whileTrue:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   542
		direction > 0 ifTrue:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   543
		    hi := hi + 1.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   544
		    tryHostID := hi.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   545
		    direction := -1.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   546
		] ifFalse:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   547
		    low := low - 1.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   548
		    tryHostID := low.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   549
		    direction := 1.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   550
		].
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   551
		(tryHostID between:1 and:254) ifTrue:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   552
		    dottedName := (myAddress at:1) printString
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   553
				  , '.' , (myAddress at:2) printString
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   554
				  , '.' , (myAddress at:3) printString
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   555
				  , '.' , tryHostID printString.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   556
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   557
		    top label:'PING net walk - trying ' , dottedName.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   558
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   559
		    top windowGroup withCursor:Cursor wait do:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   560
			conn := Socket newTCPclientToHost:dottedName port:port withTimeout:1000.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   561
			conn notNil ifTrue:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   562
			    addr := Socket ipAddressOfHost:dottedName.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   563
			    hostName := Socket hostWithIpAddress:addr.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   564
			    hostName isNil ifTrue:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   565
				hostName :='?'
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   566
			    ].
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   567
			    l add:(dottedName paddedTo:15 with:Character space)
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   568
				   , ' '
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   569
				   , (hostName paddedTo:15 with:Character space)
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   570
				   , ' up & reachable'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   571
			    list list:l.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   572
			    conn close.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   573
			]
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   574
		    ].
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   575
		].
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   576
	    ].
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   577
	    top label:'PING reachable hosts'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   578
	] forkAt:(Processor userBackgroundPriority).
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   579
	walkProcess name:'ping net walker'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   580
									[exEnd]
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   581
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   582
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   583
	This example creates a simple UDP server that accepts
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   584
	single packets from anybody and broadcasts them to all
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   585
	clients that have connected so far.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   586
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   587
									[exBegin]
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   588
	| socket address buffer msgSize clients |
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   589
	clients := Set new.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   590
	address := IPSocketAddress new.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   591
	buffer := String new: 1024.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   592
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   593
	socket := self newUDPserverAtPort: 6666.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   594
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   595
	Transcript showCR: 'server starting'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   596
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   597
	[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   598
	    [true] whileTrue: [
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   599
		(socket readWaitWithTimeoutMs: 200) ifFalse: [
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   600
		    msgSize := socket
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   601
			    receiveFrom: address
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   602
			    buffer: buffer
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   603
			    start: 1
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   604
			    for: buffer size.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   605
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   606
		    clients add: address copy.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   607
		    clients do: [ :clientAddress |
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   608
			    socket
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   609
				    sendTo: clientAddress
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   610
				    buffer: buffer
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   611
				    start: 1
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   612
				    for: msgSize]]
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   613
	    ]
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   614
	] ensure:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   615
	    Transcript showCR: 'server shutting down'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   616
	    socket close
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   617
	]
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   618
									[exEnd]
817
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
   619
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
   620
   send a datagram to above server:
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   621
									[exBegin]
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   622
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   623
	| socket address buffer host msg |
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   624
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   625
	host := Dialog
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   626
		request: 'What is the name of the server''s host?'
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   627
		initialAnswer: 'localhost'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   628
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   629
	socket := self newUDP.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   630
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   631
	address := IPSocketAddress hostName: host port: 6666.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   632
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   633
	buffer := ByteArray new: 1000.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   634
	[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   635
	    [(msg := Dialog request: 'Say something') isEmpty] whileFalse:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   636
		| replySize stream |
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   637
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   638
		socket writeWait.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   639
		stream := buffer writeStream.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   640
		stream nextPutAll: msg.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   641
		socket sendTo:address buffer:buffer start:1 for:stream position.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   642
		socket readWait.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   643
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   644
		replySize := socket receiveFrom:address buffer:buffer.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   645
		replySize > 0 ifTrue: [
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   646
		    Transcript cr; nextPutAll: 'Server acknowledged: '.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   647
		    Transcript show: ((buffer copyFrom: 1 to: replySize) asString)
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   648
		]
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   649
	    ]
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   650
	] ensure: [socket close].
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   651
	Transcript cr
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   652
									[exEnd]
1316
ffe05bfee9b5 example
Claus Gittinger <cg@exept.de>
parents: 1313
diff changeset
   653
ffe05bfee9b5 example
Claus Gittinger <cg@exept.de>
parents: 1313
diff changeset
   654
ffe05bfee9b5 example
Claus Gittinger <cg@exept.de>
parents: 1313
diff changeset
   655
   loopBack:
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   656
									[exBegin]
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   657
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   658
	|readerTask readingSocket writingSocket|
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   659
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   660
	readingSocket := self newTCPserverAtPort:9999.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   661
	readerTask :=
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   662
	    [
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   663
		|connection|
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   664
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   665
		readingSocket listenFor:1.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   666
		connection := readingSocket accept.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   667
		readingSocket close.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   668
		[connection atEnd] whileFalse:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   669
		    Transcript showCR:(connection nextLine).
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   670
		].
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   671
		connection close.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   672
	    ] fork.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   673
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   674
	Delay waitForSeconds:1.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   675
	writingSocket := self newTCPclientToHost:(OperatingSystem getHostName) port:9999.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   676
	writingSocket nextPutLine:'Hello'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   677
	writingSocket nextPutLine:'World'.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   678
	writingSocket close.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   679
									[exEnd]
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   680
"
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   681
! !
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   682
1462
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   683
!Socket class methodsFor:'instance creation'!
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   684
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   685
domain:domainSymbol type:type
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   686
    "create a socket for domain and type -
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   687
     neither any connect nor binding is done.
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   688
     Domain must be one of the symbols:
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   689
	#inet, #unix, #appletalk, #decnet, #xns, ...;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   690
     Type must be:
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   691
	#stream, #datagram or #raw
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   692
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   693
     XXX: currently only the #inet domain is supported"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   694
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   695
    ^ self new domain:domainSymbol type:type
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   696
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   697
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   698
     Socket domain:#inet type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   699
     Socket domain:#inet type:#datagram
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   700
     Socket domain:#unix type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   701
     Socket domain:#appletalk type:#stream
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   702
     Socket domain:#decnet type:#stream
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
   703
     Socket domain:#irda type:#stream
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   704
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   705
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   706
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   707
new
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   708
    "create a TCP socket"
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   709
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   710
    ^ super new buffered:false
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   711
!
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   712
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   713
newTCP
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   714
    "create a TCP socket - no binding or other setup is done,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   715
     neither connect nor connect-wait is done."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   716
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   717
    ^ self new domain:#inet type:#stream
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   718
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   719
    "Socket newUDP"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   720
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   721
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   722
newTCP:aServiceOrNil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   723
    "create a TCP socket for a service -
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   724
     neither connect nor connect-wait is done."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   725
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   726
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   727
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   728
    newSock := self newTCP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   729
    (newSock notNil and:[aServiceOrNil notNil]) ifTrue:[
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
   730
	[
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
   731
	    newSock bindTo:(self portOfService:aServiceOrNil) address:nil.
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
   732
	] ifCurtailed:[
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
   733
	    newSock close.
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
   734
	]
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   735
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   736
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   737
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   738
1911
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
   739
    "
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
   740
	Socket newTCP:'nntp'.
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
   741
	Socket newTCP:9995.
1911
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
   742
    "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   743
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   744
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   745
newTCPclientToAddress:aHostAddress port:aService
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   746
    "create a new TCP client socket connecting to a service.
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   747
     Return a socket instance if ok, nil on failure.
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   748
     Block until a connection is established (but only the current thread;
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   749
     not the whole smalltalk).
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   750
     See also: #newTCPclientToAddress:port:withTimeout:"
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   751
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   752
    ^ self newTCPclientToAddress:aHostAddress port:aService withTimeout:nil
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   753
!
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   754
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   755
newTCPclientToAddress:aHostAddress port:aService withTimeout:millis
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   756
    "create a new TCP client socket connecting to a service.
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   757
     Return a socket instance if ok, nil on failure.
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   758
     If the millis arg is nonNil, stop trying to connect after that many milliseconds
811
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   759
     and return nil."
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   760
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   761
    ^ self newTCPclientToHost:aHostAddress port:aService withTimeout:millis
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   762
!
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   763
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   764
newTCPclientToHost:hostname port:aService
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   765
    "create a new TCP client socket connecting to a service.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   766
     Return a socket instance if ok, nil on failure.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   767
     Block until a connection is established (but only the current thread;
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   768
     not the whole smalltalk).
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   769
     See also: #newTCPclientToHost:port:withTimeout:"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   770
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   771
    ^ self newTCPclientToHost:hostname port:aService withTimeout:nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   772
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   773
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   774
      Socket newTCPclientToHost:'localhost' port:'nntp'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   775
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   776
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   777
    "Created: 31.10.1995 / 18:54:11 / cg"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   778
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   779
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   780
newTCPclientToHost:hostname port:aService withTimeout:millis
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   781
    "create a new TCP client socket connecting to a service.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   782
     Return a socket instance if ok, nil on failure.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   783
     If the millis arg is nonNil, stop trying to connect after that many milliseconds
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   784
     and return nil.."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   785
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   786
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   787
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   788
    newSock := self newTCP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   789
    newSock notNil ifTrue:[
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   790
	(newSock connectTo:hostname
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   791
		 port:(self portOfService:aService protocol:'tcp')
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   792
		 withTimeout:millis
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   793
	) ifFalse:[
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   794
	    newSock close.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   795
	    ^ nil
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   796
	]
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   797
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   798
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   799
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   800
same as:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   801
    ^ (self new) for:hostname port:(self portOfService:aPort).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   802
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   803
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   804
      Socket newTCPclientToHost:'slsv6bt' port:'nntp'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   805
      Socket newTCPclientToHost:'localhost' port:'nntp' withTimeout:1000
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   806
    "
604
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
   807
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
   808
    "Modified: / 16.1.1998 / 09:47:06 / stefan"
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   809
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   810
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   811
newTCPserverAtAnonymousPort
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   812
    "create a new TCP server socket providing service on
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   813
     a new anonymous port. The portNr is assigned by the OS."
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   814
811
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   815
    ^ self newTCPserverAtPort:0
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   816
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   817
!
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   818
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   819
newTCPserverAtPort:aService
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   820
    "create a new TCP server socket providing service."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   821
1911
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
   822
    ^ self newTCP:aService
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   823
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   824
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   825
newUDP
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   826
    "create a UDP socket - no binding or other setup is done,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   827
     neither connect nor connect-wait is done."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   828
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   829
    ^ self new domain:#inet type:#datagram
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   830
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   831
    "Socket newUDP"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   832
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   833
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   834
newUDP:aServiceOrNil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   835
    "create a UDP socket for a service -
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   836
     neither connect nor connect-wait is done."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   837
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   838
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   839
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   840
    newSock := self newUDP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   841
    (newSock notNil and:[aServiceOrNil notNil]) ifTrue:[
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
   842
	[
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
   843
	    newSock bindTo:(self portOfService:aServiceOrNil) address:nil.
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
   844
	] ifCurtailed:[
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
   845
	    newSock close.
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
   846
	]
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   847
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   848
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   849
1911
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
   850
    "
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
   851
	Socket newUDP:nil.
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
   852
	Socket newUDP:'rwho'.
1911
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
   853
    "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   854
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   855
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   856
newUDPserverAtPort:aService
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   857
    "create a new UDP server socket providing service."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   858
1911
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
   859
    ^ self newUDP:aService
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   860
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   861
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   862
newUNIX
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   863
    "create a UNIX domain socket - no binding or other setup is done,
811
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   864
     neither connect nor connect-wait is done.
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   865
     If the system does not support unix domain sockets (i.e. VMS or MSDOS),
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   866
     return nil."
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   867
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   868
    ^ self new domain:#unix type:#stream
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   869
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   870
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   871
     Socket newUNIX
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   872
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   873
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   874
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   875
newUNIXclientTo:pathName
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   876
    "create a new UNIX client socket connecting to a pathname.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   877
     Return a socket instance if ok, nil on failure.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   878
     Block until a connection is established (but only the current thread;
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   879
     not the whole smalltalk).
811
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   880
     If the system does not support unix domain sockets (i.e. VMS or MSDOS),
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   881
     return nil.
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   882
     See also: #newUNIXclientTo:withTimeout:"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   883
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   884
    ^ self newUNIXclientTo:pathName withTimeout:nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   885
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   886
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   887
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   888
newUNIXclientTo:pathName withTimeout:millis
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   889
    "create a new UNIX client socket connecting to a pathname.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   890
     Return a socket instance if ok, nil on failure.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   891
     If the millis arg is nonNil, stop trying to connect after that many milliseconds
811
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   892
     and return nil.
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   893
     If the system does not support unix domain sockets (i.e. VMS or MSDOS),
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   894
     return nil."
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   895
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   896
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   897
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   898
    newSock := self newUNIX.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   899
    newSock notNil ifTrue:[
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   900
	(newSock connectTo:'localhost' port:pathName withTimeout:millis) ifFalse:[
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   901
	    newSock close.
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   902
	    ^ nil
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   903
	]
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   904
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   905
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   906
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   907
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   908
     |s|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   909
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   910
     s := Socket newUNIXclientTo:'/tmp/foo'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   911
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   912
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   913
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   914
newUNIXserverAt:pathName
811
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   915
    "create a new UNIX server socket providing service at a pathname.
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   916
     If the system does not support unix domain sockets (i.e. VMS or MSDOS),
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   917
     return nil."
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   918
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   919
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   920
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   921
    newSock := self newUNIX.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   922
    newSock notNil ifTrue:[
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
   923
	[
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
   924
	    newSock bindTo:pathName address:nil.
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
   925
	] ifCurtailed:[
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
   926
	    newSock close.
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
   927
	]
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   928
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   929
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   930
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   931
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   932
     |s s2|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   933
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   934
     s := Socket newUNIXserverAt:'/tmp/foo'.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   935
     s listenFor:5.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   936
     s2 := s accept.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   937
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   938
! !
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   939
1462
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   940
!Socket class methodsFor:'Compatibility-ST80'!
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   941
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   942
family:domainSymbol type:typeSymbol
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   943
    "create a socket for domain and type - ST80 simply uses a different name.
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   944
     Domain must be one of the symbols: #inet, #unix, #appletalk or #ns;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   945
     Type must be #stream, #datagram or #raw."
1462
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   946
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   947
    ^ self domain:domainSymbol type:typeSymbol
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   948
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   949
    "
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   950
     Socket family:#inet type:#stream
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   951
     Socket family:#inet type:#datagram
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   952
     Socket family:#unix type:#stream
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   953
    "
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   954
!
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   955
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   956
getHostname
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   957
    "return the computers hostname string"
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   958
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   959
    ^ OperatingSystem getHostName
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   960
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   961
    "Created: / 27.2.1998 / 02:32:17 / cg"
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   962
!
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   963
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   964
sockStream
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   965
    "return the type code for stream sockets"
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   966
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   967
    ^ #stream
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   968
! !
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   969
1600
f3acd5382fa1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1584
diff changeset
   970
!Socket class methodsFor:'Compatibility-Squeak'!
f3acd5382fa1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1584
diff changeset
   971
f3acd5382fa1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1584
diff changeset
   972
initializeNetwork
f3acd5382fa1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1584
diff changeset
   973
    "/ intentionally left blank here
f3acd5382fa1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1584
diff changeset
   974
!
f3acd5382fa1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1584
diff changeset
   975
2292
c4b0b901278e added: #standardTimeout
Claus Gittinger <cg@exept.de>
parents: 1940
diff changeset
   976
standardTimeout
c4b0b901278e added: #standardTimeout
Claus Gittinger <cg@exept.de>
parents: 1940
diff changeset
   977
    ^ 30
c4b0b901278e added: #standardTimeout
Claus Gittinger <cg@exept.de>
parents: 1940
diff changeset
   978
!
c4b0b901278e added: #standardTimeout
Claus Gittinger <cg@exept.de>
parents: 1940
diff changeset
   979
1600
f3acd5382fa1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1584
diff changeset
   980
wildcardPort
f3acd5382fa1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1584
diff changeset
   981
    ^ nil
f3acd5382fa1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1584
diff changeset
   982
! !
f3acd5382fa1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1584
diff changeset
   983
1462
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   984
!Socket class methodsFor:'Compatibility-VW'!
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   985
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   986
AF_INET
1462
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   987
    ^ #AF_INET
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   988
!
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   989
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   990
SOCK_STREAM
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   991
    ^ #SOCK_STREAM
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   992
! !
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   993
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   994
!Socket class methodsFor:'Signal constants'!
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   995
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   996
brokenConnectionSignal
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   997
    "return the signal used to tell broken connections.
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   998
     Since in unix, this is the same as the broken pipe signal,
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   999
     return that one.
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1000
     (for other Operatingsystems, this may change ..)"
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1001
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1002
    ^ PipeStream brokenPipeSignal
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1003
!
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1004
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1005
invalidArgumentsSignal
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1006
    "dummy for compatibility"
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1007
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1008
    ^ self errorSignal
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1009
! !
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1010
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1011
!Socket class methodsFor:'debugging'!
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1012
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1013
debug:aBoolean
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1014
    "turn on/off internal debugprints.
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1015
     This method is for ST/X debugging only and
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1016
     may  be removed in later versions"
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1017
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1018
%{  /* NOCONTEXT */
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1019
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1020
    __debugging__ = (aBoolean == true);
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1021
%}
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1022
    "
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1023
     Socket debug:true
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1024
     Socket debug:false
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1025
    "
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1026
! !
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1027
1911
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1028
!Socket class methodsFor:'obsolete'!
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1029
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1030
connectTo:service on:host
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1031
    <resource: #obsolete>
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1032
    "standard & easy client setup:
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1033
	create new client tcp socket, bind and connect;
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1034
	return the socket.
1911
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1035
     The thread blocks (interruptable), until the connection is established."
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1036
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1037
    ^ self newTCPclientToHost:host port:(self portOfService:service).
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1038
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1039
    "
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1040
     Socket connectTo:9995 on:'clam'
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1041
     Socket connectTo:4711 on:'exept'
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1042
     Socket connectTo:'finger' on:'clam'
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1043
     Socket connectTo:'ftp' on:'exept'
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1044
     Socket connectTo:'nntp' on:(OperatingSystem getEnvironment:'NNTPSERVER')
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1045
    "
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1046
!
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1047
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1048
networkLongOrderIsMSB
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1049
    "return the well known fact, that network byte order is most significant byte first"
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1050
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1051
    <resource: #obsolete>
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1052
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1053
    ^ true
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1054
!
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1055
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1056
networkShortOrderIsMSB
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1057
    "return the well known fact, that network byte order is most significant byte first"
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1058
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1059
    <resource: #obsolete>
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1060
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1061
    ^ true
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1062
!
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1063
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1064
provide:aService
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1065
    "standard & easy server setup:
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1066
     create a new TCP server socket providing a service."
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1067
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1068
    <resource:#obsolete>
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1069
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1070
    |newSock|
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1071
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1072
    self obsoleteMethodWarning:'use #newTCPserverAtPort: / #listen'.
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1073
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1074
    newSock := self newTCPserverAtPort:(self portOfService:aService).
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1075
    newSock notNil ifTrue:[
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1076
	newSock listenFor:5.
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1077
    ].
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1078
    ^ newSock
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1079
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1080
    "
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1081
     Socket provide:9995
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1082
     (Socket provide:9996) accept
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1083
     Socket provide:'nntp'
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1084
    "
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1085
! !
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1086
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1087
!Socket class methodsFor:'obsolete host queries'!
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1088
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1089
appletalkAddressOfHost:aHostName
1911
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1090
    <resource: #obsolete>
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1091
    "return the APPLETALK address for a hostname as a byteArray,
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1092
     where the network bytes come first (no matter what the local byteorder is)
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1093
     followed by the node byte.
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1094
     If the host is unknown, return nil.
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1095
     This is the reverse operation to #hostWithAppletalkAddress:.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1096
     WARNING: untested code - I have no appletalk to test this."
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1097
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1098
    NameLookupError
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1099
	handle:[:ex |
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1100
	    ^ nil
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1101
	]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1102
	do:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1103
	    ^ (AppletalkSocketAddress hostName:aHostName) address
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1104
	]
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1105
!
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1106
1278
7251c65b8d38 use nameLookup from SocketAddress for all addr-families
Claus Gittinger <cg@exept.de>
parents: 1274
diff changeset
  1107
hostWithAppletalkAddress:addrByteArray
1911
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1108
    <resource: #obsolete>
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1109
    "return the hostname for an APPLETALK address.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1110
     The address is supposed to be a byteArray consisting of 3 bytes,
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1111
     the network bytes come first (no matter what the local byteorder is).
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1112
     The last byte is the node number.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1113
     Nil is returned for an unknown host or if its not an appletalk host.
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1114
     This is is the reverse operation to #appletalkAddressOfHost:.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1115
     WARNING: untested code - I have no appletalk to test this."
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1116
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1117
    NameLookupError
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1118
	handle:[:ex |
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1119
	    ^ nil
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1120
	]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1121
	do:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1122
	    ^ (AppletalkSocketAddress hostAddress:addrByteArray) hostName
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1123
	]
1278
7251c65b8d38 use nameLookup from SocketAddress for all addr-families
Claus Gittinger <cg@exept.de>
parents: 1274
diff changeset
  1124
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1125
    "
1278
7251c65b8d38 use nameLookup from SocketAddress for all addr-families
Claus Gittinger <cg@exept.de>
parents: 1274
diff changeset
  1126
     Socket appletalkAddressOfHost:'yourAppleHere'
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1127
     Socket hostWithAppletalkAddress:#[1 2 3]
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1128
     "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1129
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1130
1278
7251c65b8d38 use nameLookup from SocketAddress for all addr-families
Claus Gittinger <cg@exept.de>
parents: 1274
diff changeset
  1131
hostWithIpAddress:addrByteArray
1911
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1132
    <resource: #obsolete>
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1133
    "return the hostname for an IP (internet-) address.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1134
     The address is supposed to be a byteArray consisting of 4 bytes,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1135
     the network bytes come first (no matter what the local byteorder is).
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1136
     Nil is returned for an unknown host or if its not an internet host.
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1137
     This is the reverse operation to #ipAddressOfHost:."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1138
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1139
    NameLookupError
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1140
	handle:[:ex |
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1141
	    ^ nil
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1142
	]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1143
	do:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1144
	    ^ (IPSocketAddress hostAddress:addrByteArray) hostName
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1145
	]
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1146
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1147
    "
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1148
     Socket ipAddressOfHost:'clam'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1149
     Socket hostWithIpAddress:(Socket ipAddressOfHost:'clam')
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1150
     Socket ipAddressOfHost:'porty'
1278
7251c65b8d38 use nameLookup from SocketAddress for all addr-families
Claus Gittinger <cg@exept.de>
parents: 1274
diff changeset
  1151
     Socket hostWithIpAddress:(Socket ipAddressOfHost:'porty')
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1152
     Socket hostWithIpAddress:#[1 2 3 4]
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1153
     Socket hostWithIpAddress:#[127 0 0 1]
1278
7251c65b8d38 use nameLookup from SocketAddress for all addr-families
Claus Gittinger <cg@exept.de>
parents: 1274
diff changeset
  1154
     Socket hostWithIpAddress:(Socket ipAddressOfHost:'1.2.3.4')
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1155
     Socket hostWithIpAddress:(Socket ipAddressOfHost:'www.altavista.com')
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1156
     "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1157
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1158
1278
7251c65b8d38 use nameLookup from SocketAddress for all addr-families
Claus Gittinger <cg@exept.de>
parents: 1274
diff changeset
  1159
hostWithIpV6Address:addrByteArray
1911
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1160
    <resource: #obsolete>
820
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1161
    "return the hostname for an IPv6 (internet-) address.
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1162
     The address is supposed to be a byteArray consisting ??? bytes,
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1163
     the network bytes come first (no matter what the local byteorder is).
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1164
     Nil is returned for an unknown host or if its not an internet host.
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1165
     This is the reverse operation to #ipV6AddressOfHost:."
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1166
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1167
    NameLookupError
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1168
	handle:[:ex |
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1169
	    ^ nil
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1170
	]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1171
	do:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1172
	    ^ (IPv6SocketAddress hostAddress:addrByteArray) hostName
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1173
	]
820
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1174
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1175
    "
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1176
     Socket ipV6AddressOfHost:'clam'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1177
     Socket hostWithIpV6Address:(Socket ipAddressOfHost:'clam')
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1178
     Socket ipV6AddressOfHost:'porty'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1179
     Socket hostWithIpV6Address:(Socket ipAddressOfHost:'porty')
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1180
     Socket hostWithIpV6Address:#[1 2 3 4 5 6 7 8 9 10 11 12 13 14]
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1181
     Socket ipV6AddressOfHost:'www.exept.de'
820
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1182
     "
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1183
!
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1184
6
claus
parents: 4
diff changeset
  1185
ipAddressOfHost:aHostName
1911
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1186
    <resource: #obsolete>
98
5e787ba2cb31 use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
  1187
    "return the IP (internet-) number for a hostname as a byteArray,
5e787ba2cb31 use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
  1188
     where the network bytes come first (no matter what the cpus byteOrder is).
5e787ba2cb31 use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
  1189
     If the host is unknown, return nil.
5e787ba2cb31 use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
  1190
     This is the reverse operation to #hostWithIpAddress:."
6
claus
parents: 4
diff changeset
  1191
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1192
    NameLookupError
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1193
	handle:[:ex |
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1194
	    ^ nil
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1195
	]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1196
	do:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1197
	    ^ (IPSocketAddress hostName:aHostName) address
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1198
	]
21
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1199
71
claus
parents: 63
diff changeset
  1200
    "
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1201
     Socket ipAddressOfHost:'localhost'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1202
     Socket ipAddressOfHost:'exept'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1203
     Socket ipAddressOfHost:'1.2.3.4'
1274
f257a1b16b4d use naemLookup from SocketAddress for ipv6
Claus Gittinger <cg@exept.de>
parents: 1263
diff changeset
  1204
     Socket ipAddressOfHost:'193.15.16.17'
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1205
     Socket ipAddressOfHost:'josef'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1206
     Socket ipAddressOfHost:'styx.com'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1207
     Socket hostWithIpAddress:(Socket ipAddressOfHost:'localhost')
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1208
     Socket ipAddressOfHost:(Socket hostWithIpAddress:'127.0.0.1')
71
claus
parents: 63
diff changeset
  1209
    "
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1210
!
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1211
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1212
ipV6AddressOfHost:aHostName
1911
cb6a52d6944a Mark obsolete methods.
Stefan Vogel <sv@exept.de>
parents: 1887
diff changeset
  1213
    <resource: #obsolete>
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1214
    "return the IPv6 (internet-) number for a hostname as a byteArray,
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1215
     where the network bytes come first (no matter what the cpus byteOrder is).
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1216
     If the host is unknown, return nil.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1217
     This is the reverse operation to #hostWithIpV6Address:."
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1218
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1219
    NameLookupError
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1220
	handle:[:ex |
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1221
	    ^ nil
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1222
	]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1223
	do:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1224
	    ^ (IPv6SocketAddress hostName:aHostName) address
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1225
	]
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1226
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1227
    "
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1228
     Socket ipV6AddressOfHost:'localhost'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1229
     Socket ipV6AddressOfHost:'exept'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1230
     Socket ipV6AddressOfHost:'exept.exept.de'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1231
     Socket ipV6AddressOfHost:'www.google.de'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1232
     Socket ipV6AddressOfHost:'1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1233
     Socket ipV6AddressOfHost:'josef'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1234
     Socket ipV6AddressOfHost:'styx.com'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1235
     Socket hostWithIpV6Address:(Socket ipV6AddressOfHost:'localhost')
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1236
     Socket ipV6AddressOfHost:(Socket hostV6WithIpAddress:'127.0.0.1')
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1237
    "
531
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1238
! !
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1239
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1240
!Socket class methodsFor:'queries'!
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1241
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1242
domainOfProtocol:aProtocol
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1243
    "given a protocols name (i.e. tcp, udp etc) return the domain.
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1244
     This method needs more ... - or is there a way to get this from the system ?"
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1245
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1246
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1247
     tcp/ip stuff
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1248
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1249
    (aProtocol = 'tcp') ifTrue:[^ #inet].
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1250
    (aProtocol = 'udp') ifTrue:[^ #inet].
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1251
    (aProtocol = 'ip')  ifTrue:[^ #inet].
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1252
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1253
     unix domain
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1254
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1255
    (aProtocol = 'ud')  ifTrue:[^ #unix].
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1256
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1257
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1258
     add x25 stuff (if any) here ...
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1259
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1260
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1261
     add appletalk stuff (if any) here ...
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1262
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1263
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1264
     add other stuff (if any) here ...
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1265
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1266
    ^ nil
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1267
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1268
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1269
     Socket domainOfProtocol:'tcp'
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1270
     Socket domainOfProtocol:'ucp'
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1271
     Socket domainOfProtocol:(Socket protocolOfService:'nntp')
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1272
     Socket domainOfProtocol:(Socket protocolOfService:'echo')
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1273
    "
6
claus
parents: 4
diff changeset
  1274
!
claus
parents: 4
diff changeset
  1275
1260
9a8fb2391174 instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents: 1235
diff changeset
  1276
peerFromDomain:domain name:peerName port:port
9a8fb2391174 instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents: 1235
diff changeset
  1277
    |addrClass|
9a8fb2391174 instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents: 1235
diff changeset
  1278
9a8fb2391174 instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents: 1235
diff changeset
  1279
    addrClass := self socketAddressClassForDomain:domain.
1263
23161346a162 no longer callBack into sockets getHostName/getAddress code.
Claus Gittinger <cg@exept.de>
parents: 1260
diff changeset
  1280
    ^ addrClass hostName:peerName serviceName:port type:nil
1187
7e5f2f6b177d getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents: 1186
diff changeset
  1281
!
7e5f2f6b177d getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents: 1186
diff changeset
  1282
7e5f2f6b177d getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents: 1186
diff changeset
  1283
peerNameFromDomain:domain peer:peer
1260
9a8fb2391174 instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents: 1235
diff changeset
  1284
    |addrClass|
9a8fb2391174 instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents: 1235
diff changeset
  1285
9a8fb2391174 instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents: 1235
diff changeset
  1286
    addrClass := self socketAddressClassForDomain:domain.
9a8fb2391174 instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents: 1235
diff changeset
  1287
    ^ addrClass peerNameFromPeer:peer
1187
7e5f2f6b177d getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents: 1186
diff changeset
  1288
!
7e5f2f6b177d getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents: 1186
diff changeset
  1289
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1290
portOfService:aNameOrNumber
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1291
    "returns the port-number for a given IP-service
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1292
     or nil if no such service exists;
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1293
     - used to convert service names to portNumbers"
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1294
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1295
    ^ self portOfService:aNameOrNumber protocol:nil
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1296
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1297
    "
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1298
     Socket portOfService:'finger'
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1299
     Socket portOfService:'nntp'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1300
     Socket portOfService:'echo'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1301
     Socket portOfService:'snmp'
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1302
    "
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1303
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1304
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1305
portOfService:aNameOrNumber protocol:aProtocol
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1306
    "returns the port-number for a given IP-service
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1307
     or nil if no such service exists;
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1308
     - used to convert service names to portNumbers"
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1309
1499
1ff98f9bc58f Unlimitedstack for some methods which call getXXXByName().
Stefan Vogel <sv@exept.de>
parents: 1486
diff changeset
  1310
%{ /* UNLIMITEDSTACK */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1311
#ifndef NO_SOCKET
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1312
    struct servent *servent = NULL;
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1313
    char *protocol;
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1314
    int tryBoth = 0;
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1315
    short portNo;
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1316
604
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
  1317
    if (__isSmallInteger(aNameOrNumber)) {
2340
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1318
	RETURN ( aNameOrNumber );
92
Claus Gittinger <cg@exept.de>
parents: 91
diff changeset
  1319
    }
Claus Gittinger <cg@exept.de>
parents: 91
diff changeset
  1320
2331
b5280e1b3b9f changed:
Stefan Vogel <sv@exept.de>
parents: 2327
diff changeset
  1321
    if (__isStringLike(aProtocol)) {
2340
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1322
	protocol = (char *)__stringVal(aProtocol);
604
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
  1323
    } else {
2340
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1324
	protocol = "tcp";
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1325
	tryBoth = 1;
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1326
    }
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1327
2331
b5280e1b3b9f changed:
Stefan Vogel <sv@exept.de>
parents: 2327
diff changeset
  1328
    if (__isStringLike(aNameOrNumber)) {
2340
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1329
	servent = getservbyname((char *) __stringVal(aNameOrNumber), protocol);
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1330
	if (servent != NULL) {
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1331
	    RETURN ( __MKSMALLINT(ntohs(servent->s_port)) );
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1332
	}
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1333
	if (tryBoth) {
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1334
	    servent = getservbyname((char *) __stringVal(aNameOrNumber), "udp");
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1335
	    if (servent != NULL) {
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1336
		RETURN ( __MKSMALLINT(ntohs(servent->s_port)) );
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1337
	    }
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1338
	}
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1339
	RETURN ( nil );
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1340
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1341
#endif
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1342
    RETURN ( nil );
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1343
%}
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1344
    "
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1345
     Socket portOfService:'echo' protocol:'udp'
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1346
     Socket portOfService:'echo' protocol:'tcp'
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1347
    "
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1348
!
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1349
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1350
protocolOfService:aNameOrNumber
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1351
    "returns the protocol (as string) for a given IP-service
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1352
     or nil if no such service exists."
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1353
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1354
%{  /* UNLIMITEDSTACK(noWIN32) */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1355
#ifndef NO_SOCKET
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1356
    struct servent *servent = NULL;
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1357
    short portNo;
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1358
58
bd6753bf0401 *** empty log message ***
claus
parents: 51
diff changeset
  1359
    if (__isSmallInteger(aNameOrNumber)) {
2340
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1360
	portNo = __intVal(aNameOrNumber);
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1361
	servent = getservbyport(htons(portNo), "tcp") ;
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1362
	if (servent == NULL) {
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1363
	    servent = getservbyport(htons(portNo), "udp") ;
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1364
	    if (servent == NULL) {
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1365
		RETURN ( nil );
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1366
	    }
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1367
	}
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1368
    } else {
2340
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1369
	if (__isStringLike(aNameOrNumber)) {
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1370
	    servent = getservbyname((char *) __stringVal(aNameOrNumber), "tcp");
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1371
	    if (servent == NULL) {
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1372
		servent = getservbyname((char *) __stringVal(aNameOrNumber), "udp");
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1373
		if (servent == NULL) {
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1374
		    RETURN ( nil );
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1375
		}
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1376
	    }
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1377
	}
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1378
    }
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1379
    if (servent) {
2340
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1380
	RETURN ( __MKSTRING(servent->s_proto) );
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1381
    }
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1382
#endif /* !NO_SOCKET */
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1383
    RETURN ( nil );
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1384
%}
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1385
    "
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1386
     Socket protocolOfService:'finger'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1387
     Socket protocolOfService:'nntp'
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1388
     Socket protocolOfService:'xxx'
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1389
     Socket protocolOfService:79
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1390
     Socket protocolOfService:'snmp'
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1391
    "
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1392
!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1393
1187
7e5f2f6b177d getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents: 1186
diff changeset
  1394
socketAddressClassForDomain:domain
1230
2cfb8c270cb5 more functionality moved to SocketAccessor
Claus Gittinger <cg@exept.de>
parents: 1224
diff changeset
  1395
    ^ SocketAddress knownClassFromCode:domain
2cfb8c270cb5 more functionality moved to SocketAccessor
Claus Gittinger <cg@exept.de>
parents: 1224
diff changeset
  1396
2cfb8c270cb5 more functionality moved to SocketAccessor
Claus Gittinger <cg@exept.de>
parents: 1224
diff changeset
  1397
    "
2cfb8c270cb5 more functionality moved to SocketAccessor
Claus Gittinger <cg@exept.de>
parents: 1224
diff changeset
  1398
     self socketAddressClassForDomain:#inet
1260
9a8fb2391174 instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents: 1235
diff changeset
  1399
     self socketAddressClassForDomain:#unix
1230
2cfb8c270cb5 more functionality moved to SocketAccessor
Claus Gittinger <cg@exept.de>
parents: 1224
diff changeset
  1400
    "
1187
7e5f2f6b177d getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents: 1186
diff changeset
  1401
!
7e5f2f6b177d getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents: 1186
diff changeset
  1402
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1403
supportedProtocolFamilies
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1404
    "return a collection of supported protocol families.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1405
     This list specifies what the Socket class supports -
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1406
     socket creation may still fail, if your system was built
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1407
     without it."
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1408
1280
b973855bfe74 moved all socket constant queries from SocketHandle
Claus Gittinger <cg@exept.de>
parents: 1278
diff changeset
  1409
    ^ OperatingSystem supportedProtocolFamilies
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1410
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1411
    "
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1412
     Socket supportedProtocolFamilies
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1413
    "
559
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1414
!
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1415
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1416
typeOfProtocol:aProtocol
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1417
    "given a protocols name (i.e. tcp, udp etc) return the connection type.
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1418
     This method needs more ... - or is there a way to get this from the system ?"
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1419
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1420
    (aProtocol = 'tcp') ifTrue:[^ #stream].
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1421
    (aProtocol = 'udp') ifTrue:[^ #datagram].
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1422
    (aProtocol = 'ip')  ifTrue:[^ #raw].
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1423
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1424
     unix domain
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1425
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1426
    (aProtocol = 'ud')  ifTrue:[^ #stream].
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1427
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1428
     add x25 stuff (if any) here ...
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1429
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1430
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1431
     add appletalk stuff (if any) here ...
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1432
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1433
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1434
     add other stuff (if any) here ...
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1435
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1436
    ^ nil
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1437
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1438
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1439
     Socket typeOfProtocol:'tcp'
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1440
     Socket typeOfProtocol:'ucp'
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1441
     Socket typeOfProtocol:(Socket protocolOfService:'nntp')
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1442
     Socket typeOfProtocol:(Socket protocolOfService:'echo')
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1443
    "
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1444
! !
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1445
1202
c52279df60d8 method category rename
Claus Gittinger <cg@exept.de>
parents: 1187
diff changeset
  1446
!Socket methodsFor:'Compatibility-Dolphin'!
1110
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  1447
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  1448
setReceiveTimeout: milliseconds
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  1449
    self receiveTimeout:(milliseconds / 1000)
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  1450
!
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  1451
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  1452
setSendTimeout: milliseconds
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  1453
    self sendTimeout:(milliseconds / 1000)
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  1454
! !
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  1455
1202
c52279df60d8 method category rename
Claus Gittinger <cg@exept.de>
parents: 1187
diff changeset
  1456
!Socket methodsFor:'Compatibility-ST80'!
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1457
887
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  1458
acceptNonBlock
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  1459
    ^ self accept
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  1460
!
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  1461
870
452fc695de34 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  1462
connectTo:aSocketAddress
452fc695de34 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  1463
    ^ self connectTo:aSocketAddress hostAddress port:aSocketAddress port
452fc695de34 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  1464
!
452fc695de34 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  1465
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1466
errorReporter
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1467
    "ST-80 mimicry."
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1468
1535
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  1469
    ^ self class
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1470
!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1471
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1472
ioConnection
887
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  1473
    ^ self
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  1474
!
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  1475
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1476
notReadySignal
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1477
    "ST-80 mimicry.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1478
     for now - this is not yet raised"
71
claus
parents: 63
diff changeset
  1479
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1480
    ^ Signal new
486
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1481
!
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1482
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1483
readAppendStream
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1484
    "ST-80 mimicry.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1485
     In ST-80, socket is not a stream, but referes to one.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1486
     ST-80 code therefore uses 'Socket readWriteStream' to access
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1487
     the actual stream.
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1488
     In ST/X, sockets inherit from stream, so
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1489
     this method returns the receiver, for transparency"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1490
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1491
    ^ self
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1492
!
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1493
486
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1494
readStream
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1495
    "ST-80 mimicry.
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1496
     In ST-80, socket is not a stream, but referes to one.
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1497
     ST-80 code therefore uses 'Socket readStream' to access
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1498
     the actual stream.
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1499
     In ST/X, sockets inherit from stream, so
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1500
     this method returns the receiver, for transparency"
486
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1501
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1502
    ^ self
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1503
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1504
    "Created: 24.1.1997 / 23:52:57 / cg"
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1505
!
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1506
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1507
writeStream
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1508
    "ST-80 mimicry.
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1509
     In ST-80, socket is not a stream, but referes to one.
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1510
     ST-80 code therefore uses 'Socket writeStream' to access
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1511
     the actual stream.
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1512
     In ST/X, sockets inherit from stream, so
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1513
     this method returns the receiver, for transparency"
486
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1514
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1515
    ^ self
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1516
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1517
    "Created: 24.1.1997 / 10:34:35 / cg"
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1518
    "Modified: 24.1.1997 / 23:52:52 / cg"
71
claus
parents: 63
diff changeset
  1519
! !
claus
parents: 63
diff changeset
  1520
1202
c52279df60d8 method category rename
Claus Gittinger <cg@exept.de>
parents: 1187
diff changeset
  1521
!Socket methodsFor:'Compatibility-Squeak'!
771
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  1522
1462
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1523
address
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1524
    ^ self getSocketAddress
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1525
!
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1526
2308
d8b410a4f38b added: #connectToHostNamed:port:
Claus Gittinger <cg@exept.de>
parents: 2292
diff changeset
  1527
connectToHostNamed:hostName port:portNr
d8b410a4f38b added: #connectToHostNamed:port:
Claus Gittinger <cg@exept.de>
parents: 2292
diff changeset
  1528
    self connectTo:hostName port:portNr
d8b410a4f38b added: #connectToHostNamed:port:
Claus Gittinger <cg@exept.de>
parents: 2292
diff changeset
  1529
!
d8b410a4f38b added: #connectToHostNamed:port:
Claus Gittinger <cg@exept.de>
parents: 2292
diff changeset
  1530
1462
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1531
dataAvailable
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1532
    ^ self canReadWithoutBlocking
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1533
!
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1534
1886
e0d23764c809 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1885
diff changeset
  1535
destroy
e0d23764c809 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1885
diff changeset
  1536
    self close
e0d23764c809 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1885
diff changeset
  1537
e0d23764c809 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1885
diff changeset
  1538
    "Created: / 04-06-2007 / 21:29:03 / cg"
e0d23764c809 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1885
diff changeset
  1539
!
e0d23764c809 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1885
diff changeset
  1540
1462
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1541
listenOn:aPortNr
1882
6f818f33c85a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1863
diff changeset
  1542
    self listenOn:aPortNr backlogSize:5
6f818f33c85a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1863
diff changeset
  1543
6f818f33c85a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1863
diff changeset
  1544
    "Modified: / 31-05-2007 / 17:59:53 / cg"
6f818f33c85a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1863
diff changeset
  1545
!
6f818f33c85a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1863
diff changeset
  1546
6f818f33c85a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1863
diff changeset
  1547
listenOn:aPortNr backlogSize:aNumber
1462
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1548
    self bindTo:aPortNr address:nil.
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1549
    self listenFor:aNumber
1882
6f818f33c85a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1863
diff changeset
  1550
6f818f33c85a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1863
diff changeset
  1551
    "Created: / 31-05-2007 / 17:59:47 / cg"
1462
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1552
!
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1553
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1554
peerName
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1555
    "return my peer (i.e. ipAddr + port);
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1556
     May return nil if not yet setup completely."
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1557
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1558
    ^ self getPeer
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1559
!
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1560
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1561
primSocketLocalPort:aSocket
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1562
    ^ self port
1600
f3acd5382fa1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1584
diff changeset
  1563
!
f3acd5382fa1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1584
diff changeset
  1564
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1565
sendData: aStringOrByteArray
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1566
	"Send all of the data in the given array, even if it requires multiple calls to send it all.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1567
	 Return the number of bytes sent."
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1568
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1569
	"An experimental version for use on slow lines:
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1570
	 Longer timeout and smaller writes to try to avoid spurious timeouts."
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1571
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1572
	|remaining nWritten|
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1573
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1574
Transcript show:'>> '; showCR:aStringOrByteArray.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1575
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1576
	remaining := aStringOrByteArray size.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1577
	[remaining > 0] whileTrue:[
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1578
	    nWritten := self nextPutBytes:remaining from:aStringOrByteArray startingAt:1.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1579
	    remaining := remaining - nWritten.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1580
	].
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1581
	^ aStringOrByteArray size.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1582
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1583
"/        | bytesSent bytesToSend count |
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1584
"/        bytesToSend := aStringOrByteArray size.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1585
"/        bytesSent := 0.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1586
"/        [bytesSent < bytesToSend] whileTrue: [
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1587
"/                (self waitForSendDoneFor: 60)
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1588
"/                        ifFalse: [ConnectionTimedOut signal: 'send data timeout; data not sent'].
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1589
"/                count := self primSocket: socketHandle
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1590
"/                        sendData: aStringOrByteArray
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1591
"/                        startIndex: bytesSent + 1
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1592
"/                        count: (bytesToSend - bytesSent min: 5000).
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1593
"/                bytesSent := bytesSent + count].
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1594
"/
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1595
"/        ^ bytesSent
1600
f3acd5382fa1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1584
diff changeset
  1596
!
f3acd5382fa1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1584
diff changeset
  1597
1462
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1598
setOption: optionName value: optionValue
1887
f26d9b04244d changed #setOption:value:
Claus Gittinger <cg@exept.de>
parents: 1886
diff changeset
  1599
    ^ self setSocketOption:optionName argument:optionValue argument:nil
f26d9b04244d changed #setOption:value:
Claus Gittinger <cg@exept.de>
parents: 1886
diff changeset
  1600
f26d9b04244d changed #setOption:value:
Claus Gittinger <cg@exept.de>
parents: 1886
diff changeset
  1601
    "Modified: / 04-06-2007 / 21:23:19 / cg"
1600
f3acd5382fa1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1584
diff changeset
  1602
!
f3acd5382fa1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1584
diff changeset
  1603
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1604
socketHandle
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1605
    ^ self
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1606
!
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1607
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1608
waitForConnectionUntil:aMillisecondClockValue
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1609
    self shouldImplement.
1886
e0d23764c809 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1885
diff changeset
  1610
!
e0d23764c809 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1885
diff changeset
  1611
e0d23764c809 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1885
diff changeset
  1612
waitForData
e0d23764c809 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1885
diff changeset
  1613
    self readWait
e0d23764c809 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1885
diff changeset
  1614
e0d23764c809 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1885
diff changeset
  1615
    "Created: / 04-06-2007 / 21:28:40 / cg"
771
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  1616
! !
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  1617
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1618
!Socket methodsFor:'accepting connections'!
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1619
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1620
accept
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1621
    "create a new TCP socket from accepting on the receiver.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1622
     This method will suspend the current process if no connection is waiting.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1623
     For ST-80 compatibility"
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1624
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1625
    |newSock|
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1626
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1627
    self readWait.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1628
    newSock := self class new.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1629
    (newSock primAcceptOn:self blocking:false) ifFalse:[
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1630
	"should raise an error here"
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1631
	^ nil
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1632
    ].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1633
    ^ newSock
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1634
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1635
    "
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1636
     |sock newSock|
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1637
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1638
     sock := Socket provide:8004.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1639
     sock listenFor:5.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1640
     newSock := sock accept.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1641
    "
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1642
!
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1643
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1644
blockingAccept
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1645
    "create a new TCP socket from accepting on the receiver.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1646
     This method will suspend the smalltalk image with all smalltalk processes if no connection is waiting.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1647
     For ST-80 compatibility"
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1648
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1649
    |newSock|
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1650
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1651
    newSock := self class new.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1652
    (newSock primAcceptOn:self blocking:true) ifFalse:[
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1653
	"should raise an error here"
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1654
	^ nil
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1655
    ].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1656
    ^ newSock
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1657
! !
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1658
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1659
!Socket methodsFor:'binding'!
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1660
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1661
bindAnonymously
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1662
    "bind to any address. A free port will be allocated.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1663
     Our own socket address will be determined after conection set up.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1664
     This is the default after the socket has been created"
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1665
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1666
    ^ self
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1667
	bindTo:nil
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1668
	address:nil
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1669
	reuseAddress:false
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1670
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1671
    "
1938
831af28cc848 comments
Stefan Vogel <sv@exept.de>
parents: 1935
diff changeset
  1672
      self newTCP bindAnonymously; listenFor:1; yourself
831af28cc848 comments
Stefan Vogel <sv@exept.de>
parents: 1935
diff changeset
  1673
    "
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1674
!
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1675
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1676
bindAnonymouslyToAddress:addressString
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1677
    "bind to address addressString.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1678
     A free port will be allocated"
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1679
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1680
    ^ self
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1681
	bindTo:nil
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1682
	address:addressString
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1683
	reuseAddress:false
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1684
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1685
    "
1938
831af28cc848 comments
Stefan Vogel <sv@exept.de>
parents: 1935
diff changeset
  1686
      self newTCP bindAnonymouslyToAddress:IPSocketAddress local; listenFor:1; yourself
831af28cc848 comments
Stefan Vogel <sv@exept.de>
parents: 1935
diff changeset
  1687
    "
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1688
!
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1689
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1690
bindTo:aSocketAddress
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1691
    "ST80 compatible bind, expecting a socketAddress argument.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1692
     The socketAddress object (an instance of SocketAddress)
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1693
     is supposed to respond to #portOrName and #address requests."
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1694
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1695
    ^ self bindTo:(aSocketAddress portOrName)
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1696
	   address:(aSocketAddress address)
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1697
	   reuseAddress:true
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1698
!
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1699
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1700
bindTo:portNrOrNameString address:addressString
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1701
    "low level bind - returns true if ok, false otherwise.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1702
     Currently only non-address binding is supported;
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1703
     i.e. the address must always be nil.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1704
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1705
     The interpretation of portNrOrName depends on the domain:
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1706
	inet domain uses (4byte) byteArray like internet numbers,
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1707
	unix domain uses pathname strings,
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1708
	others use whatever will come up in the future
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1709
     "
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1710
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1711
    ^ self
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1712
	bindTo:portNrOrNameString
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1713
	address:addressString
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1714
	reuseAddress:true
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1715
!
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1716
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1717
bindTo:portNrOrNameOrNil address:hostOrPathNameOrSocketAddrOrNil reuseAddress:reuse
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1718
    "low level bind - returns true if ok, false otherwise.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1719
     Currently only non-address binding is supported;
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1720
     i.e. address must always be nil.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1721
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1722
     The interpretation of portNrOrName depends on the domain:
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1723
	inet domain uses (4byte) byteArray like internet numbers,
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1724
	unix domain uses pathname strings,
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1725
	others use whatever will come up in the future
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1726
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1727
     The reuse boolean argument controls if the SO_REUSEADDR socket option
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1728
     is to be set (to avoid the 'bind: address in use' error).
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1729
    "
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1730
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1731
    |ok addr addrName domainClass error|
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1732
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1733
    handle isNil ifTrue:[
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1734
	^ self errorNotOpen
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1735
    ].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1736
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1737
    domainClass := self class socketAddressClassForDomain:domain.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1738
    domainClass isNil ifTrue:[
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1739
	^ self error:'invalid (unsupported) domain'.
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1740
    ].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1741
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1742
    hostOrPathNameOrSocketAddrOrNil isNil ifTrue:[
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1743
	addr := domainClass anyHost.
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1744
    ] ifFalse:[
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1745
	(hostOrPathNameOrSocketAddrOrNil isKindOf:SocketAddress) ifTrue:[
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1746
	    addr := hostOrPathNameOrSocketAddrOrNil.
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1747
	] ifFalse:[
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1748
	    "backward compatibility: support for byteArray and string arg"
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1749
	    hostOrPathNameOrSocketAddrOrNil isString ifTrue:[
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1750
		addr := domainClass hostName:hostOrPathNameOrSocketAddrOrNil.
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1751
		addrName := hostOrPathNameOrSocketAddrOrNil.
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1752
	    ] ifFalse:[
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1753
		hostOrPathNameOrSocketAddrOrNil isByteArray ifFalse:[
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1754
		    ^ self error:'bad host (socketAddress) argument'
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1755
		].
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1756
		addr := domainClass hostAddress:hostOrPathNameOrSocketAddrOrNil.
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1757
	    ].
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1758
	].
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1759
    ].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1760
    portNrOrNameOrNil notNil ifTrue:[
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1761
	addr port:portNrOrNameOrNil.
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1762
    ].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1763
    (portNrOrNameOrNil isNil or:[portNrOrNameOrNil == 0]) ifTrue:[
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1764
	addr := addr copy.
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1765
    ].
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1766
    ok := false.
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1767
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1768
%{  /* STACK: 100000 */
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1769
#ifndef NO_SOCKET
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1770
    OBJ fp = __INST(handle);
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1771
    SOCKET sock;
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1772
    union sockaddr_u sa;
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1773
    int sockaddr_size;
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1774
    int ret;
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1775
    int sockAddrOffs;
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1776
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1777
    if (! __isBytes(addr)) {
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1778
	error = __mkSmallInteger(-1);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1779
	addr = nil;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1780
	goto getOutOfHere;
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1781
    }
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1782
    if (fp == nil) {
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1783
	goto getOutOfHere;
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1784
    }
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1785
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1786
    /* get the socket-address */
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1787
    {
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1788
	int nIndex;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1789
	OBJ cls;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1790
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1791
	sockAddrOffs = 0;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1792
	if ((cls = __qClass(addr)) != @global(ByteArray))
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1793
	    sockAddrOffs += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1794
	nIndex = __qSize(addr) - OHDR_SIZE;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1795
	sockaddr_size = nIndex - sockAddrOffs;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1796
	if (sockaddr_size > sizeof(sa)) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1797
	    error=__mkSmallInteger(-2);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1798
	    goto getOutOfHere;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1799
	}
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1800
	memcpy(&sa, __byteArrayVal(addr) + sockAddrOffs, sockaddr_size);
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1801
    }
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1802
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1803
    sock = SOCKET_FROM_FILE_OBJECT(fp);
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1804
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1805
# ifdef SO_REUSEADDR
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1806
    if (reuse == true) {
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1807
	int on = 1;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1808
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1809
	if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1810
	    DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n"));
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1811
	}
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1812
    }
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1813
# endif /* SO_REUSEADDR */
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1814
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1815
# ifdef BIND_BLOCKS
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1816
#  ifdef DO_WRAP_CALLS
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1817
    do {
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1818
	__threadErrno = 0;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1819
	ret = STX_WSA_NOINT_CALL3("bind", bind, sock, &sa, sockaddr_size);
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1820
    } while ((ret < 0) && (__threadErrno == EINTR));
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1821
#  else
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1822
    __BEGIN_INTERRUPTABLE__
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1823
    do {
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1824
	ret = bind(sock, (struct sockaddr *)&sa, sockaddr_size);
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1825
    } while ((ret < 0) && (errno == EINTR));
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1826
    __END_INTERRUPTABLE__
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1827
#  endif
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1828
# else
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1829
    ret = bind(sock, (struct sockaddr *)&sa, sockaddr_size);
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1830
# endif
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1831
    if (ret < 0) {
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1832
	DBGPRINTF(("SOCKET: bind failed errno=%d\n", errno));
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1833
	error = __INST(lastErrorNumber) = __MKSMALLINT(errno);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1834
	goto getOutOfHere;
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1835
    } else {
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1836
	ok = true;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1837
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1838
	if (! __isSmallInteger(portNrOrNameOrNil)
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1839
	    || (portNrOrNameOrNil == __MKSMALLINT(0))) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1840
	    unsigned int alen = sockaddr_size;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1841
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1842
	    /*
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1843
	     * anonymous port - get the actual portNr
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1844
	     */
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1845
	    if (getsockname(sock, (struct sockaddr *)&sa, &alen) < 0) {
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1846
# ifdef WIN32
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1847
		errno = WSAGetLastError();
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1848
# endif
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1849
		console_fprintf(stderr, "SOCKET: cannot get socketname: %d\n", errno);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1850
	    }
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1851
	    memcpy(__byteArrayVal(addr) + sockAddrOffs, &sa, alen);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1852
	}
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1853
    }
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1854
#endif /* NO_SOCKET */
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1855
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1856
getOutOfHere: ;
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1857
%}.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1858
    ok ~~ true ifTrue:[
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1859
	"maybe someone catches the error and binds to some other port..."
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1860
	OpenError
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1861
	    raiseRequestWith:self
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1862
	    errorString:('cannot bind socket to port: <1p> address: <2p> (error=<3p>)'
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1863
				expandMacrosWith:portNrOrNameOrNil
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1864
				with:hostOrPathNameOrSocketAddrOrNil
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1865
				with:error).
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1866
	^ true.
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1867
    ].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1868
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1869
    port := addr port.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1870
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1871
    ^ true
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1872
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1873
    "
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1874
     (Socket domain:#inet type:#stream)
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1875
	 bindTo:21
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1876
	 address:nil
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1877
    "
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1878
!
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1879
1939
6e50b903881b changed #bindTo:reuseAddress:
Stefan Vogel <sv@exept.de>
parents: 1938
diff changeset
  1880
bindTo:aSocketAddress reuseAddress:reuseAddressBoolean
6e50b903881b changed #bindTo:reuseAddress:
Stefan Vogel <sv@exept.de>
parents: 1938
diff changeset
  1881
    "ST80 compatible bind, expecting a socketAddress argument.
6e50b903881b changed #bindTo:reuseAddress:
Stefan Vogel <sv@exept.de>
parents: 1938
diff changeset
  1882
     The socketAddress object (an instance of SocketAddress)
6e50b903881b changed #bindTo:reuseAddress:
Stefan Vogel <sv@exept.de>
parents: 1938
diff changeset
  1883
     is supposed to respond to #portOrName and #address requests."
6e50b903881b changed #bindTo:reuseAddress:
Stefan Vogel <sv@exept.de>
parents: 1938
diff changeset
  1884
6e50b903881b changed #bindTo:reuseAddress:
Stefan Vogel <sv@exept.de>
parents: 1938
diff changeset
  1885
    ^ self bindTo:(aSocketAddress portOrName)
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1886
	   address:(aSocketAddress address)
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1887
	   reuseAddress:reuseAddressBoolean
1939
6e50b903881b changed #bindTo:reuseAddress:
Stefan Vogel <sv@exept.de>
parents: 1938
diff changeset
  1888
!
6e50b903881b changed #bindTo:reuseAddress:
Stefan Vogel <sv@exept.de>
parents: 1938
diff changeset
  1889
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1890
listenFor:aNumber
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1891
    "start listening; return true if ok, false on error
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1892
     aNumber is the number of connect requests, that may be queued on the socket"
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1893
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1894
    handle isNil ifTrue:[
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1895
	^ self errorNotOpen
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1896
    ].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1897
%{
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1898
#ifndef NO_SOCKET
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1899
    OBJ fp = __INST(handle);
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1900
    SOCKET sock;
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1901
    int ret;
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1902
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1903
    if (! __isSmallInteger(aNumber)) {
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1904
	DBGPRINTF(("SOCKET: invalid arg\n"));
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1905
	RETURN (false);
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1906
    }
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1907
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1908
    sock = SOCKET_FROM_FILE_OBJECT(fp);
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1909
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1910
#ifdef LISTEN_BLOCKS
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1911
# ifdef DO_WRAP_CALLS
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1912
    do {
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1913
	__threadErrno = 0;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1914
	ret = STX_WSA_NOINT_CALL2("listen", listen, sock, __intVal(aNumber));
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1915
    } while ((ret < 0) && (__threadErrno == EINTR));
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1916
# else
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1917
    __BEGIN_INTERRUPTABLE__
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1918
    do {
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1919
	ret = listen(sock, __intVal(aNumber));
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1920
    } while ((ret < 0) && (errno == EINTR));
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1921
    __END_INTERRUPTABLE__
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1922
# endif
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1923
#else
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1924
    ret = listen(sock, __intVal(aNumber));
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1925
#endif
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1926
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1927
    if (ret < 0) {
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1928
	DBGPRINTF(("SOCKET: listen call failed errno=%d\n", errno));
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1929
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1930
	RETURN (false);
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1931
    }
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1932
#else
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1933
    RETURN (false);
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1934
#endif
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1935
%}.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1936
    listening := true.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1937
    ^ true
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1938
! !
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1939
1576
a2ffb22c5f5e New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents: 1568
diff changeset
  1940
!Socket methodsFor:'closing'!
a2ffb22c5f5e New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents: 1568
diff changeset
  1941
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1942
shutDown
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1943
    "shutDown and close the socket"
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1944
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1945
    self shutdown:2.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1946
    self close
1576
a2ffb22c5f5e New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents: 1568
diff changeset
  1947
!
a2ffb22c5f5e New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents: 1568
diff changeset
  1948
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1949
shutDownInput
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1950
    "shutDown the input side of the socket.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1951
     Any read on the socket will signal end-of-file from now on.
1839
c10cd58ec334 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  1952
     The other side MAY be informed, that no more data will be accepted
1576
a2ffb22c5f5e New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents: 1568
diff changeset
  1953
     (e.g. setting the TCP-Windowsize to 0)"
a2ffb22c5f5e New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents: 1568
diff changeset
  1954
a2ffb22c5f5e New: #shutDownInput #shutDownOutput
Stefan Vogel <sv@exept.de>
parents: 1568
diff changeset
  1955
    self shutdown:0.
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1956
!
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1957
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1958
shutDownOutput
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1959
    "shutDown the output side of the socket.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1960
     Any write to the socket will signal end-of-file from now on.
1884
ee0d640a25a7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1882
diff changeset
  1961
     The other side will get a end-of-file condition,
ee0d640a25a7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1882
diff changeset
  1962
     after the last buffered data has been read"
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1963
1884
ee0d640a25a7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1882
diff changeset
  1964
    self shutdown:1.
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1965
! !
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1966
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1967
!Socket methodsFor:'connecting'!
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1968
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1969
connectTo:hostOrPathName port:portNrOrName
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1970
    "low level connect; connect to port, portNrOrNameOrNil on host, hostName.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1971
     For backward compatibility, host may be also a string or a byteArray,
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1972
     but it is recommended to pass socketAddress instances.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1973
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1974
     Return true if ok, false otherwise.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1975
     The current process will block (but not the whole Smalltalk) until the connection is established.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1976
     See also: #connectTo:port:withTimeout: for a somewhat nicer interface."
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1977
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1978
    ^ self connectTo:hostOrPathName port:portNrOrName withTimeout:nil
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1979
!
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1980
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1981
connectTo:hostOrPathNameOrSocketAddr port:portNrOrNameOrNil withTimeout:timeout
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1982
    "low level connect; connect to port, portNrOrNameOrNil on host, hostName.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1983
     For backward compatibility, host may be also a string or a byteArray,
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1984
     but it is recommended to pass socketAddress instances.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1985
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1986
     Return true if ok, false otherwise.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1987
     The current process will block (but not the whole Smalltalk) until the connection is established,
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1988
     or timeout millliseconds have passed."
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1989
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1990
    |isAsync err domainClass addr addrName|
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1991
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  1992
    handle isNil ifTrue:[
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1993
	^ self errorNotOpen
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1994
    ].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1995
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  1996
    (hostOrPathNameOrSocketAddr isKindOf:SocketAddress) ifTrue:[
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1997
	addr := hostOrPathNameOrSocketAddr.
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1998
	portNrOrNameOrNil notNil ifTrue:[
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  1999
	    addr port:portNrOrNameOrNil.
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2000
	].
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2001
    ] ifFalse:[
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2002
	"backward compatibility: support for byteArray and string arg"
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2003
	domainClass := self class socketAddressClassForDomain:domain.
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2004
	domainClass isNil ifTrue:[
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2005
	    ^ self error:'invalid (unsupported) domain'.
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2006
	].
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2007
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2008
	hostOrPathNameOrSocketAddr isString ifTrue:[
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2009
	    addr := domainClass hostName:hostOrPathNameOrSocketAddr serviceName:portNrOrNameOrNil type:#SOCK_STREAM.
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2010
	    addrName := hostOrPathNameOrSocketAddr.
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2011
	] ifFalse:[
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2012
	    hostOrPathNameOrSocketAddr isByteCollection ifFalse:[
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2013
		^ self error:'bad host (socketAddress) argument'
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2014
	    ].
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2015
	    addr := domainClass hostAddress:hostOrPathNameOrSocketAddr port:portNrOrNameOrNil.
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2016
	].
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2017
    ].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2018
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2019
%{  /* STACK: 100000 */
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2020
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2021
#ifndef NO_SOCKET
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  2022
    OBJ fp = __INST(handle);
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2023
    union sockaddr_u sa;
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2024
    SOCKET sock;
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2025
    int a;
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2026
    int ret, oldFlags;
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2027
    int on = 1;
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2028
    int sockaddr_size;
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2029
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2030
    if (!__isNonNilObject(addr) || !__isBytes(addr)) {
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2031
	DBGPRINTF(("SOCKET: invalid addrBytes\n"));
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2032
	RETURN (false);
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2033
    }
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2034
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2035
    {
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2036
	int sockAddrOffs, nIndex;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2037
	OBJ cls;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2038
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2039
	sockAddrOffs = 0;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2040
	if ((cls = __qClass(addr)) != @global(ByteArray))
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2041
	    sockAddrOffs += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2042
	nIndex = __qSize(addr) - OHDR_SIZE;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2043
	sockaddr_size = nIndex - sockAddrOffs;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2044
	if (sockaddr_size > sizeof(sa)) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2045
	    console_fprintf(stderr, "Socket: bad socketAddr\n");
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2046
	    RETURN (false);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2047
	}
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2048
	bcopy((__byteArrayVal(addr) + sockAddrOffs), &sa, sockaddr_size);
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2049
    }
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2050
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2051
    sock = SOCKET_FROM_FILE_OBJECT(fp);
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2052
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2053
# if defined(O_NONBLOCK)
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2054
#  if !defined(WIN32)
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2055
    /*
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2056
     * set to non-blocking and wait later
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2057
     */
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2058
    oldFlags = fcntl(sock, F_GETFL, 0);
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2059
    /* on SUNOS4.x, would use fcntl(osfd, F_SETFL, flags | FNDELAY); */
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2060
    fcntl(sock, F_SETFL, oldFlags | O_NONBLOCK);
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2061
#  endif
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2062
# endif
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2063
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2064
    /*
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2065
     * connect
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2066
     */
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2067
# ifdef DO_WRAP_CALLS
2414
886ecf4b36cd changed:
ab
parents: 2340
diff changeset
  2068
    /* __setWrapCallDebugging(1,1); */
886ecf4b36cd changed:
ab
parents: 2340
diff changeset
  2069
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2070
    do {
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2071
	DBGFPRINTF((stderr, "SOCKET: connect...\n"));
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2072
	__threadErrno = 0;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2073
	ret = STX_WSA_NOINT_CALL3("connect", connect, sock, &sa, sockaddr_size);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2074
	DBGFPRINTF((stderr, "SOCKET: connect(%d) -> %d (%d)\n", sock, ret, __threadErrno));
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2075
    } while ((ret < 0) && (__threadErrno == EINTR));
2414
886ecf4b36cd changed:
ab
parents: 2340
diff changeset
  2076
    /* __setWrapCallDebugging(1,0); */
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2077
# else
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2078
    __BEGIN_INTERRUPTABLE__
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2079
    do {
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2080
	ret = connect(sock, (struct sockaddr *)&sa, sockaddr_size);
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2081
    } while ((ret < 0)
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2082
	     && ((errno == EINTR)
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2083
# ifdef EAGAIN
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2084
		 || (errno == EAGAIN)
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2085
# endif
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2086
		));
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2087
    __END_INTERRUPTABLE__
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2088
#endif
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2089
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2090
    if (ret < 0) {
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2091
# if defined(EINPROGRESS) || defined(EALREADY)
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2092
	if (0
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2093
#  ifdef EINPROGRESS
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2094
	    || (errno == EINPROGRESS)
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2095
#  endif
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2096
#  ifdef EALREADY
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2097
	    || (errno == EALREADY)
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2098
#  endif
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2099
	) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2100
	    /*
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2101
	     * This was a nonblocking operation that will take some time.
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2102
	     * Do a select on read to get informed when the operation is ready.
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2103
	     */
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2104
	    DBGFPRINTF((stderr, "SOCKET: isAsync is true\n"));
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2105
	    isAsync = true;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2106
	} else
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2107
# endif /* EINPROGRESS or EALREADY */
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2108
	{
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2109
	    DBGFPRINTF((stderr, "SOCKET: connect failed ret=%d errno=%d __threadErrno=%d\n",
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2110
			ret, errno, __threadErrno ));
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2111
# ifdef DUMP_ADDRESS
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2112
	    {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2113
		char *cp = (char *)(&sa);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2114
		int i;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2115
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2116
		console_printf("address data:\n");
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2117
		for (i=0; i<sockaddr_size; i++) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2118
		    console_printf(" %02x\n", *cp++);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2119
		}
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2120
	    }
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2121
# endif
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2122
	    err = __INST(lastErrorNumber) = __MKSMALLINT(errno);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2123
	    RETURN (false);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2124
	}
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2125
    }
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2126
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2127
# if defined(O_NONBLOCK)
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2128
#  if !defined(WIN32)
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2129
    fcntl(sock, F_SETFL, oldFlags);
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2130
#  endif
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2131
# endif
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2132
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2133
# else /* NO_SOCKET */
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2134
    RETURN (false);
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2135
# endif /* NO_SOCKET */
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2136
%}.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2137
    isAsync == true ifTrue:[
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2138
	(self writeWaitWithTimeoutMs:timeout) ifTrue:[
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2139
	    "/ a timeout occured
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2140
	    "/ should I cancel the connect?
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2141
	    ^ false.
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2142
	].
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2143
	err := self getSocketError.
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2144
	err ~~ 0 ifTrue:[
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2145
	    lastErrorNumber := err.
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2146
	    ^ false.
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2147
	].
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2148
    ].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2149
1940
2ea7d2c1a2e6 changed #connectTo:port:withTimeout: - add commented code tah may be used in the future
Stefan Vogel <sv@exept.de>
parents: 1939
diff changeset
  2150
"/ Once we will raise an exception instead of returning false (and have to change some code above):
2ea7d2c1a2e6 changed #connectTo:port:withTimeout: - add commented code tah may be used in the future
Stefan Vogel <sv@exept.de>
parents: 1939
diff changeset
  2151
"/    err notNil ifTrue:[
2ea7d2c1a2e6 changed #connectTo:port:withTimeout: - add commented code tah may be used in the future
Stefan Vogel <sv@exept.de>
parents: 1939
diff changeset
  2152
"/        (OperatingSystem errorHolderForNumber:err) reportError.
2ea7d2c1a2e6 changed #connectTo:port:withTimeout: - add commented code tah may be used in the future
Stefan Vogel <sv@exept.de>
parents: 1939
diff changeset
  2153
"/    ].
2ea7d2c1a2e6 changed #connectTo:port:withTimeout: - add commented code tah may be used in the future
Stefan Vogel <sv@exept.de>
parents: 1939
diff changeset
  2154
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2155
    peer := addr.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2156
    peerName := addrName.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2157
    port isNil ifTrue:[
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2158
	"socket has not been explicitly bound,
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2159
	 after connect it has been bound implicitly - fetch the port"
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2160
	port := self getFullSocketAddress port.
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2161
    ].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2162
    ^ true
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2163
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2164
    "
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2165
       |sock|
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2166
       sock := Socket newTCP.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2167
       sock connectTo:'localhost' port:21 withTimeout:1000.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2168
       sock
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2169
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2170
       |sock|
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2171
       sock := Socket newTCP.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2172
       sock connectTo:'localhost' port:9876 withTimeout:2000.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2173
       sock
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2174
    "
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2175
! !
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2176
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2177
!Socket methodsFor:'datagram transmission'!
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2178
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2179
receiveBuffer:aDataBuffer start:startIndex for:nBytes
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2180
    "receive data
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2181
     Return the number of bytes received, or a negative number on error.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2182
     On error, the unix error code is left in the lastErrorNumber
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2183
     instance variable.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2184
     The thread blocks until data arrives - you may want to wait before
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2185
     receiving, using #readWait or #readWaitWithTimeout:."
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2186
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2187
    |nReceived|
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2188
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2189
%{
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2190
#ifndef NO_SOCKET
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  2191
    OBJ fp = __INST(handle);
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2192
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2193
    if (fp != nil) {
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2194
	SOCKET sock;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2195
	int objSize, offs;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2196
	int n;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2197
	char *extPtr;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2198
	unsigned char *buffer;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2199
	unsigned char *allocatedBuffer = NULL;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2200
	int flags = 0;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2201
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2202
	sock = SOCKET_FROM_FILE_OBJECT(fp);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2203
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2204
	if (! setupBufferParameters(aDataBuffer, startIndex, &extPtr, &offs, &objSize)) goto bad;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2205
	if (__isSmallInteger(nBytes)) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2206
	    if (__intVal(nBytes) < objSize) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2207
		objSize = __intVal(nBytes);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2208
	    }
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2209
	}
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2210
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2211
# ifdef DO_WRAP_CALLS
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2212
	if (extPtr) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2213
	    buffer = extPtr + offs;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2214
	} else {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2215
	    allocatedBuffer = buffer = (char *)malloc(objSize);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2216
	}
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2217
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2218
	do {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2219
	    __threadErrno = 0;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2220
	    n = STX_WSA_NOINT_CALL4("recv", recv, sock, buffer, objSize, flags);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2221
	} while ((n < 0) && (__threadErrno == EINTR));
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2222
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2223
	if (allocatedBuffer) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2224
	    if (n > 0) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2225
		bcopy(allocatedBuffer, (char *)__InstPtr(aDataBuffer) + offs, n);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2226
	    }
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2227
	    free(allocatedBuffer);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2228
	}
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2229
# else
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2230
	__BEGIN_INTERRUPTABLE__
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2231
	do {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2232
	    if (extPtr) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2233
		n = recv(sock, extPtr + offs, objSize, flags);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2234
	    } else {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2235
		n = recv(sock, (char *)__InstPtr(aDataBuffer) + offs, objSize, flags);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2236
	    }
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2237
	} while ((n < 0) && (errno == EINTR));
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2238
	__END_INTERRUPTABLE__
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2239
# endif
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2240
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2241
	if (n < 0) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2242
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2243
	}
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2244
	nReceived = __MKSMALLINT(n);
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2245
    }
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2246
#endif
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2247
bad: ;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2248
%}.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2249
    nReceived notNil ifTrue:[
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2250
	nReceived < 0 ifTrue:[
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2251
	    'Socket [warning]: ' infoPrint.
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2252
	    (OperatingSystem errorTextForNumber:lastErrorNumber) infoPrintCR.
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2253
	].
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2254
	^ nReceived
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2255
    ].
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2256
    "
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2257
     arrive here if you try to receive into an invalid buffer (i.e. not ByteArray-like)
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2258
    "
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2259
    self primitiveFailed
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2260
!
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2261
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2262
receiveFrom:anAddressBuffer buffer:aDataBuffer
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2263
    "receive datagramm data - put address of originating host into
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2264
     anAddressBuffer, data into aBuffer.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2265
     Both must be ByteArray-like. The addressBuffer must
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2266
     provide space for a valid address for my domain (i.e. for inet, a 4-byte byteArray).
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2267
     Return the number of bytes received, or a negative number on error.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2268
     On error, the unix error code is left in the lastErrorNumber
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2269
     instance variable."
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2270
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2271
    ^ self receiveFrom:anAddressBuffer buffer:aDataBuffer start:1 for:(aDataBuffer size)
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
  2272
!
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
  2273
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2274
receiveFrom:anAddressBuffer buffer:aDataBuffer start:startIndex for:nBytes
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2275
    "receive datagramm data
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2276
     - put address of originating host into anAddressBuffer, data into aBuffer.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2277
     For backward compatibility, the addressBuffer may be a non-SocketAddress;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2278
     then, it must be a byteArray with appropriate size for the addressBytes.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2279
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2280
     Return the number of bytes received, or a negative number on error.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2281
     On error, the unix error code is left in the lastErrorNumber
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2282
     instance variable.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2283
     The thread blocks until data arrives - you may want to wait before
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2284
     receiving, using #readWait or #readWaitWithTimeout:."
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2285
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2286
    |domainClass addr addrLen nReceived|
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2287
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2288
    domainClass := self class socketAddressClassForDomain:domain.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2289
    domainClass isNil ifTrue:[
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2290
	^ self error:'invalid (unsupported) domain'.
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2291
    ].
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2292
    (anAddressBuffer isKindOf:SocketAddress) ifTrue:[
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2293
	anAddressBuffer class == domainClass ifFalse:[
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2294
	    ^ self error:'addressBuffer class mismatch (domain)'.
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2295
	].
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2296
	addr := anAddressBuffer.
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2297
    ] ifFalse:[
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2298
	anAddressBuffer notNil ifTrue:[
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2299
	    addr := domainClass new.
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2300
	].
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2301
    ].
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2302
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2303
%{
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2304
#ifndef NO_SOCKET
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  2305
    OBJ fp = __INST(handle);
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2306
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2307
    if (fp != nil) {
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2308
	SOCKET sock;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2309
	int objSize;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2310
	union sockaddr_u sa;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2311
	unsigned int alen = 0;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2312
	int n, offs;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2313
	int flags = 0;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2314
	char *extPtr;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2315
	unsigned char *allocatedBuffer = NULL;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2316
	unsigned char *buffer = NULL;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2317
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2318
	sock = SOCKET_FROM_FILE_OBJECT(fp);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2319
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2320
	if (! setupBufferParameters(aDataBuffer, startIndex, &extPtr, &offs, &objSize)) goto bad;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2321
	if (__isSmallInteger(nBytes)) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2322
	    if (__intVal(nBytes) < objSize) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2323
		objSize = __intVal(nBytes);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2324
	    }
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2325
	}
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2326
# ifdef DO_WRAP_CALLS
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2327
	if (extPtr) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2328
	    buffer = extPtr + offs;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2329
	} else {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2330
	    allocatedBuffer = buffer = (char *)malloc(objSize);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2331
	}
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2332
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2333
	do {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2334
	    __threadErrno = 0;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2335
	    alen = sizeof(sa);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2336
	    n = STX_WSA_NOINT_CALL6("recvfrom", recvfrom, sock, buffer, objSize, flags, (struct sockaddr *)&sa, &alen);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2337
	} while ((n < 0) && (__threadErrno == EINTR));
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2338
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2339
	if (allocatedBuffer) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2340
	    if (n > 0) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2341
		bcopy(allocatedBuffer, (char *)__InstPtr(aDataBuffer) + offs, n);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2342
	    }
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2343
	    free(allocatedBuffer);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2344
	}
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2345
# else
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2346
	__BEGIN_INTERRUPTABLE__
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2347
	do {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2348
	    alen = sizeof(sa);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2349
	    if (extPtr) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2350
		n = recvfrom(sock, extPtr + offs, objSize, flags, (struct sockaddr *) &sa, &alen);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2351
	    } else {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2352
		n = recvfrom(sock, (char *)__InstPtr(aDataBuffer) + offs, objSize, flags, (struct sockaddr *) &sa, &alen);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2353
	    }
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2354
	} while ((n < 0) && (errno == EINTR));
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2355
	__END_INTERRUPTABLE__
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2356
# endif
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2357
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2358
	if (n >= 0) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2359
	    if (__isNonNilObject(addr)) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2360
		char *addrPtr;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2361
		OBJ oClass;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2362
		int nInstVars, nInstBytes, objSize;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2363
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2364
		oClass = __qClass(addr);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2365
		if (! __isBytes(addr) )
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2366
		    goto bad;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2367
		nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2368
		nInstBytes = OHDR_SIZE + (nInstVars * sizeof(OBJ));
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2369
		objSize = __qSize(addr) - nInstBytes;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2370
		addrPtr = (char *)__InstPtr(addr) + nInstBytes;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2371
		if (objSize < alen)
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2372
		    goto bad;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2373
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2374
		/*
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2375
		 * extract the datagrams address
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2376
		 */
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2377
		bcopy((char *)&sa, addrPtr, alen);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2378
		addrLen = __MKSMALLINT(alen);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2379
	    }
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2380
	}
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2381
	if (n < 0) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2382
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2383
	}
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2384
	nReceived = __MKSMALLINT(n);
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2385
    }
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2386
#endif
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2387
bad: ;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2388
%}.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2389
    nReceived notNil ifTrue:[
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2390
	nReceived < 0 ifTrue:[
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2391
	    'Socket [warning]: ' infoPrint.
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2392
	    (OperatingSystem errorTextForNumber:lastErrorNumber) infoPrintCR.
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2393
	].
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2394
	addrLen notNil ifTrue:[
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2395
	    (addr == anAddressBuffer) ifFalse:[
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2396
		self obsoleteFeatureWarning:'please use a socketAddress argument'.
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2397
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2398
		" can be a ByteArray for backward compatibility "
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2399
		anAddressBuffer replaceFrom:1 to:addrLen with:(addr hostAddress).
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2400
	    ].
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2401
	].
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2402
	^ nReceived
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2403
    ].
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2404
    "
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2405
     arrive here if you try to receive into an invalid buffer
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2406
     (i.e. not ByteArray-like),
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  2407
     or if the addressBuffer is nonNil AND not a SocketAddress/ByteArray
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2408
     or if the addressBuffer is nonNil AND too small.
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2409
    "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2410
    self primitiveFailed
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2411
!
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2412
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2413
sendBuffer:aDataBuffer start:startIndex for:nBytes flags:flags
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2414
    "send data.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2415
     Both must be ByteArray-like. The bytes in the addressBuffer must
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2416
     be a valid address for my domain (i.e. for inet, a 4-byte byteArray).
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2417
     Return the number of bytes transmitted, or a negative number on error.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2418
     On error, the unix error code is left in the lastErrorNumber
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2419
     instance variable."
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2420
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2421
    |nReceived portNo|
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2422
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2423
%{
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2424
#ifndef NO_SOCKET
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  2425
    OBJ fp = __INST(handle);
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2426
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2427
    if ((fp != nil)
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2428
     && __isSmallInteger(startIndex)
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2429
     && __isSmallInteger(nBytes)) {
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2430
	SOCKET sock;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2431
	int objSize;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2432
	int n;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2433
	char *extPtr;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2434
	int _flags = 0;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2435
	int offs;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2436
	unsigned long norder;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2437
	unsigned char *buffer;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2438
	unsigned char *allocatedBuffer = NULL;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2439
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2440
	_flags = __longIntVal(flags);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2441
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2442
	sock = SOCKET_FROM_FILE_OBJECT(fp);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2443
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2444
	if (! setupBufferParameters(aDataBuffer, startIndex, &extPtr, &offs, &objSize)) goto bad;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2445
	if (__isSmallInteger(nBytes)) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2446
	    if (__intVal(nBytes) < objSize) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2447
		objSize = __intVal(nBytes);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2448
	    }
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2449
	}
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2450
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2451
# ifdef DGRAM_DEBUG
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2452
	console_printf("sending %d bytes ...\n", nBytes);
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2453
# endif
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2454
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2455
#ifdef DO_WRAP_CALLS
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2456
	if (extPtr) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2457
	    buffer = extPtr + offs;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2458
	} else {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2459
	    allocatedBuffer = buffer = (char *)malloc(objSize);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2460
	    bcopy((char *)__InstPtr(aDataBuffer) + offs, allocatedBuffer, objSize);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2461
	}
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2462
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2463
	do {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2464
	    __threadErrno = 0;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2465
	    n = STX_WSA_NOINT_CALL4("send", send, sock, buffer, objSize, _flags);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2466
	} while ((n < 0) && (__threadErrno == EINTR));
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2467
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2468
	if (allocatedBuffer) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2469
	    free(allocatedBuffer);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2470
	}
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2471
#else
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2472
	__BEGIN_INTERRUPTABLE__
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2473
	do {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2474
	    if (extPtr) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2475
		n = send(sock, extPtr + offs, objSize, _flags);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2476
	    } else {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2477
		n = send(sock, (char *)__InstPtr(aDataBuffer) + offs, objSize, _flags);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2478
	    }
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2479
	} while ((n < 0) && (errno == EINTR));
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2480
	__END_INTERRUPTABLE__
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2481
#endif
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2482
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2483
	if (n < 0) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2484
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2485
	}
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2486
	RETURN (__MKSMALLINT(n));
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2487
    }
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2488
#endif
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2489
bad: ;
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2490
%}.
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2491
    "
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  2492
     arrive here if you try to send from an invalid buffer (i.e. not ByteArray-like),
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2493
    "
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2494
    self primitiveFailed
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2495
!
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2496
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2497
sendTo:anAddressBuffer buffer:buffer
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2498
    "send datagramm data - fetch address of destination host from
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2499
     anAddressBuffer, data from aDataBuffer.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2500
     Both must be ByteArray-like. The bytes in the addressBuffer must
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2501
     be a valid address for my domain (i.e. for inet, a 4-byte byteArray).
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2502
     Return the number of bytes transmitted, or a negative number on error.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2503
     On error, the unix error code is left in the lastErrorNumber
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2504
     instance variable.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2505
     Flags is currently ignored; it is there for ST-80 compatibility."
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2506
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  2507
    ^ self sendTo:anAddressBuffer buffer:buffer start:1 for:buffer size flags:0
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2508
!
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2509
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2510
sendTo:anAddressBuffer buffer:buffer start:startIndex for:count
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2511
    "send datagramm data - fetch address of destination host from
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2512
     anAddressBuffer, data from aDataBuffer.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2513
     Both must be ByteArray-like. The bytes in the addressBuffer must
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2514
     be a valid address for my domain (i.e. for inet, a 4-byte byteArray).
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2515
     Return the number of bytes transmitted, or a negative number on error.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2516
     On error, the unix error code is left in the lastErrorNumber
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2517
     instance variable.
817
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2518
     Flags is currently ignored; it is there for ST-80 compatibility."
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2519
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  2520
    ^ self sendTo:anAddressBuffer buffer:buffer start:startIndex for:count flags:0
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2521
!
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2522
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2523
sendTo:anAddressBuffer buffer:aDataBuffer start:startIndex for:nBytes flags:flags
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2524
    "send datagramm data - fetch address of destination host from
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2525
     anAddressBuffer, data from aDataBuffer starting at startIndex,
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2526
     sending count bytes.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2527
     Both must be ByteArray-like. The bytes in the addressBuffer must
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2528
     be a valid address for my domain (i.e. for inet, a 4-byte byteArray).
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2529
     Return the number of bytes transmitted, or a negative number on error.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2530
     On error, the unix error code is left in the lastErrorNumber
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2531
     instance variable."
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2532
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2533
    |domainClass addr|
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2534
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2535
    domainClass := self class socketAddressClassForDomain:domain.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2536
    domainClass isNil ifTrue:[
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2537
	^ self error:'invalid (unsupported) domain'.
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2538
    ].
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2539
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2540
    (anAddressBuffer isKindOf:SocketAddress) ifTrue:[
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2541
	addr := anAddressBuffer.
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2542
    ] ifFalse:[
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2543
	anAddressBuffer isByteArray ifFalse:[
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2544
	    ^ self error:'bad socketAddress argument'
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2545
	].
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2546
	addr := domainClass hostAddress:anAddressBuffer.
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2547
    ].
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2548
%{
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2549
#ifndef NO_SOCKET
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  2550
    OBJ fp = __INST(handle);
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2551
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2552
    if ((fp != nil)
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2553
     && __isSmallInteger(startIndex)
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2554
     && __isSmallInteger(nBytes)) {
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2555
	SOCKET sock;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2556
	int objSize;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2557
	struct sockaddr *sockaddr_ptr;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2558
	union sockaddr_u sa;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2559
	int alen = 0;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2560
	int sockAddrOffs, sockaddr_size;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2561
	int n;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2562
	char *extPtr;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2563
	int _flags = 0;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2564
	int offs;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2565
	unsigned long norder;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2566
	unsigned char *buffer;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2567
	unsigned char *allocatedBuffer = NULL;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2568
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2569
	_flags = __longIntVal(flags);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2570
	sock = SOCKET_FROM_FILE_OBJECT(fp);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2571
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2572
	if (! __isBytes(addr)) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2573
	    sockaddr_size = 0;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2574
	    sockaddr_ptr = (struct sockaddr *)0;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2575
	} else {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2576
	    int nIndex;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2577
	    OBJ cls;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2578
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2579
	    sockAddrOffs = 0;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2580
	    if ((cls = __qClass(addr)) != @global(ByteArray))
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2581
		sockAddrOffs += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2582
	    nIndex = __qSize(addr) - OHDR_SIZE;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2583
	    sockaddr_size = nIndex - sockAddrOffs;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2584
	    if (sockaddr_size > sizeof(sa)) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2585
		console_fprintf(stderr, "Socket [warning]: bad socketAddr\n");
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2586
		goto bad;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2587
	    }
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2588
	    bcopy((__byteArrayVal(addr) + sockAddrOffs), &sa, sockaddr_size);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2589
	    sockaddr_ptr = (struct sockaddr *)(&sa);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2590
	}
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2591
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2592
	if (! setupBufferParameters(aDataBuffer, startIndex, &extPtr, &offs, &objSize)) goto bad;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2593
	if (__isSmallInteger(nBytes)) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2594
	    if (__intVal(nBytes) < objSize) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2595
		objSize = __intVal(nBytes);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2596
	    }
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2597
	}
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2598
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2599
#ifdef DO_WRAP_CALLS
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2600
	if (extPtr) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2601
	    buffer = extPtr + offs;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2602
	} else {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2603
	    allocatedBuffer = buffer = (char *)malloc(objSize);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2604
	    bcopy((char *)__InstPtr(aDataBuffer) + offs, allocatedBuffer, objSize);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2605
	}
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2606
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2607
	do {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2608
	    __threadErrno = 0;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2609
	    n = STX_WSA_NOINT_CALL6("sendto", sendto, sock, buffer, objSize, _flags, sockaddr_ptr, sockaddr_size);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2610
	} while ((n < 0) && (__threadErrno == EINTR));
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2611
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2612
	if (allocatedBuffer) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2613
	    free(allocatedBuffer);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2614
	}
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2615
#else
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2616
	__BEGIN_INTERRUPTABLE__
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2617
	do {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2618
	    if (extPtr) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2619
		n = sendto(sock, extPtr + offs, objSize, _flags, sockaddr_ptr, sockaddr_size);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2620
	    } else {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2621
		n = sendto(sock, (char *)__InstPtr(aDataBuffer) + offs, objSize, _flags, sockaddr_ptr, sockaddr_size);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2622
	    }
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2623
	} while ((n < 0) && (errno == EINTR));
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2624
	__END_INTERRUPTABLE__
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2625
#endif
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2626
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2627
	if (n < 0) {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2628
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2629
	}
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  2630
	RETURN (__MKSMALLINT(n));
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2631
    }
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2632
#endif
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2633
bad: ;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2634
%}.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2635
    "
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2636
     arrive here if you try to send from an invalid buffer
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2637
     (i.e. not ByteArray-like),
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2638
     or if the addressBuffer is nonNil AND not a ByteArray/String
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2639
     or if the addressBuffer is nonNil AND too small.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2640
    "
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2641
    self primitiveFailed
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2642
! !
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2643
2686
2d22c9e67090 changed: #closeFile
Stefan Vogel <sv@exept.de>
parents: 2685
diff changeset
  2644
!Socket methodsFor:'low level'!
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2645
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2646
closeFile
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2647
    "low level close"
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2648
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2649
%{  /* NOCONTEXT */
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2650
#ifndef NO_SOCKET
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2651
    OBJ t;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2652
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  2653
    t = __INST(handle);
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2654
    if (t != nil) {
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2655
	FILE *fp;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2656
	SOCKET sock;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2657
	int fd;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2658
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2659
	__INST(handle) = nil;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2660
	fp = __FILEVal(t);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2661
	fd = fileno(fp);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2662
	sock = SOCKET_FROM_FD(fd);
2414
886ecf4b36cd changed:
ab
parents: 2340
diff changeset
  2663
886ecf4b36cd changed:
ab
parents: 2340
diff changeset
  2664
# ifdef DO_WRAP_CALLS
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2665
	{
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2666
	  int ret;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2667
	  /*__setWrapCallDebugging(1,1); */
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2668
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2669
	  do {
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2670
	    __threadErrno = 0;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2671
	    ret = STX_C_NOINT_CALL1("fclose", fclose, fp);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2672
	  } while ((ret < 0) && (__threadErrno == EINTR));
2680
ff00563f0444 Protect against concurrent access when doing fclose and fdopen
Stefan Vogel <sv@exept.de>
parents: 2579
diff changeset
  2673
ff00563f0444 Protect against concurrent access when doing fclose and fdopen
Stefan Vogel <sv@exept.de>
parents: 2579
diff changeset
  2674
#  if defined(WIN32) && defined(CLOSESOCKET_AFTER_FCLOSE)
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2675
	  do {
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2676
	    __threadErrno = 0;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2677
	    ret = STX_WSA_NOINT_CALL1("closesocket", closesocket, sock);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2678
	  } while ((ret < 0) && (__threadErrno == EINTR));
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2679
#  endif
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2680
	  /*__setWrapCallDebugging(1,0);*/
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2681
	}
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2682
# else /* !DO_WRAP_CALLS */
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2683
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2684
	DBGFPRINTF((stderr, "SOCKET: fflush %x (%d %d)\n", fp, fileno(fp), sock));
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2685
	fflush(fp);
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2686
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2687
#  if defined(CLOSESOCKET_BEFORE_FCLOSE)
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2688
	DBGFPRINTF((stderr, "SOCKET: closesocket (%d)\n", sock));
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2689
	closesocket(sock);
1558
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2690
#  endif
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2691
	if ((@global(FileOpenTrace) == true) || __debugging__) {
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2692
	    console_fprintf(stderr, "SOCKET: fclose %x (%d %d)\n", fp, fileno(fp), sock);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2693
	}
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2694
	fclose(fp);
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2695
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2696
#  if defined(CLOSESOCKET_AFTER_FCLOSE)
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2697
	DBGFPRINTF((stderr, "SOCKET: closesocket (%d)\n", sock));
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2698
	closesocket(sock);
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2699
#  endif
2414
886ecf4b36cd changed:
ab
parents: 2340
diff changeset
  2700
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2701
# endif /* !DO_WRAP_CALLS */
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2702
    }
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2703
#endif /* NO_SOCKET */
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2704
%}
2686
2d22c9e67090 changed: #closeFile
Stefan Vogel <sv@exept.de>
parents: 2685
diff changeset
  2705
!
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2706
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2707
getSocketAdress
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2708
    "BAD SPELLING, of #getSocketAddress, kept for compatibility with swazoo"
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2709
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2710
    <resource: #obsolete>
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2711
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2712
    ^ self getSocketAddress
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2713
!
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2714
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2715
getSocketError
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2716
    "get the SO_ERROR form the socket, which indicates the
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2717
     result of an asynchronous operation"
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2718
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2719
%{
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2720
#ifndef NO_SOCKET
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2721
    OBJ fp;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2722
    int err;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2723
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  2724
    fp = __INST(handle);
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2725
    if (fp == nil) {
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2726
	err = EBADF;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2727
    } else {
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2728
	unsigned int sz;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2729
	SOCKET sock;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2730
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2731
	sock = SOCKET_FROM_FILE_OBJECT(fp);
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2732
	sz = sizeof(err);
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2733
	if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &err, &sz) < 0) {
1558
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2734
# ifdef WIN32
1568
3bca500e0c7a send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents: 1561
diff changeset
  2735
	    errno = WSAGetLastError();
1558
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2736
# endif
1568
3bca500e0c7a send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents: 1561
diff changeset
  2737
	    err = errno;
3bca500e0c7a send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents: 1561
diff changeset
  2738
	}
1558
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2739
    }
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2740
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2741
    RETURN(__MKSMALLINT(err));
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2742
#endif
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2743
%}
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2744
!
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2745
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2746
listenWithBacklog:aNumber
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2747
    <resource: #obsolete>
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2748
    "same as listenFor: - backward compatibility with old ST/X"
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2749
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2750
    ^ self listenFor:aNumber
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2751
!
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2752
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2753
pollingWaitForNewConnectionOrDataOnAny:otherConnections timeout:timeoutSeconds
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2754
    <resource: #obsolete>
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2755
    "stupid MSDOS does not support select on sockets (sigh).
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2756
     Must poll here."
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2757
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2758
    |millis newConnection|
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2759
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2760
    millis := timeoutSeconds * 1000.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2761
    [millis > 0] whileTrue:[
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2762
	otherConnections size > 0 ifTrue:[
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2763
	    otherConnections do:[:aConnection |
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2764
		aConnection canReadWithoutBlocking ifTrue:[
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2765
		    ^ aConnection
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2766
		]
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2767
	    ].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2768
	].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2769
	newConnection := self blockingAccept.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2770
	newConnection notNil ifTrue:[^ newConnection].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2771
	Delay waitForMilliseconds:20.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2772
	millis := millis - 20.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2773
    ].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2774
    ^ nil.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2775
!
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2776
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2777
pollingWaitForNewConnectionWithTimeout:timeoutSeconds
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2778
    <resource: #obsolete>
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2779
    "stupid MSDOS does not support select on sockets (sigh).
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2780
     Must poll here."
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2781
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2782
    |millis newConnection|
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2783
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2784
    timeoutSeconds notNil ifTrue:[
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2785
	millis := timeoutSeconds * 1000.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2786
    ].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2787
    [millis isNil or:[millis > 0]] whileTrue:[
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2788
	newConnection := self blockingAccept.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2789
	newConnection notNil ifTrue:[^ newConnection].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2790
	Delay waitForMilliseconds:20.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2791
	millis notNil ifTrue:[
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2792
	    millis := millis - 20.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2793
	]
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2794
    ].
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2795
    ^ nil.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2796
!
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2797
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2798
primAcceptOn:aSocket blocking:blocking
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2799
    "accept a connection on a server port (created with:'Socket>>onIPPort:')
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2800
     usage is: (Socket basicNew acceptOn:(Socket onIPPort:9999)).
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2801
     Return the true if ok; false if not.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2802
     If blocking is true, the accept() syscall (and the whole smalltalk image)
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2803
     will block, until a connection is accepted.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2804
     If blocking is false, this call will return immediately, if there is no connection pending."
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2805
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2806
    |serverSocketFd addr addrLen domainClass|
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2807
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  2808
    handle notNil ifTrue:[
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2809
	^ self errorAlreadyOpen
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2810
    ].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2811
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2812
    domain := aSocket domain.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2813
    socketType := aSocket type.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2814
    serverSocketFd := aSocket fileDescriptor.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2815
    serverSocketFd isNil ifTrue:[
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2816
	^ self error:'invalid server socket'
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2817
    ].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2818
    (serverSocketFd isMemberOf:SmallInteger) ifFalse:[
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2819
	^ self error:'invalid server socket'
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2820
    ].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2821
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2822
    domainClass := self class socketAddressClassForDomain:domain.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2823
    domainClass isNil ifTrue:[
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2824
	^ self error:'invalid (unsupported) domain'.
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2825
    ].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2826
    addrLen := domainClass socketAddressSize.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2827
    addr := domainClass new.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2828
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2829
%{  /* STACK: 100000 */
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2830
#ifndef NO_SOCKET
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2831
    FILE *fp;
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2832
    int flags;
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2833
    SOCKET sock, newSock;
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2834
    union sockaddr_u sa;
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2835
    unsigned int alen, alen0;
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2836
    struct hostent *he ;
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2837
    char dotted[20] ;
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2838
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2839
    if (!__isSmallInteger(addrLen)) {
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2840
	DBGPRINTF(("SOCKET: bad addrLen\n"));
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2841
	RETURN (false);
1558
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2842
    }
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2843
    alen0 = __intVal(addrLen);
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2844
    sock = SOCKET_FROM_FD(__intVal(serverSocketFd));
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2845
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2846
    if (blocking == false) {
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2847
# if defined(O_NONBLOCK) && defined(SET_NDELAY)
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2848
	flags = fcntl(sock, F_GETFL);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2849
	fcntl(sock, F_SETFL, flags | O_NONBLOCK);
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2850
# endif
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2851
    }
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2852
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2853
# ifdef DO_WRAP_CALLS
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2854
    do {
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2855
	__threadErrno = 0;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2856
	alen = alen0;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2857
	newSock = STX_WSA_CALL3("accept", accept, sock, &sa, &alen);
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2858
    } while ((newSock < 0) && (__threadErrno == EINTR));
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2859
# else
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2860
    __BEGIN_INTERRUPTABLE__
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2861
    do {
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2862
	alen = alen0;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2863
	newSock = accept(sock, (struct sockaddr *) &sa, &alen);
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2864
    } while ((newSock < 0) && (errno == EINTR));
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2865
    __END_INTERRUPTABLE__
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2866
# endif
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2867
    DBGFPRINTF((stderr, "SOCKET: accept newSock=%d\n", newSock));
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2868
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2869
    if (blocking == false) {
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2870
# if defined(O_NDELAY) && defined(SET_NDELAY)
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2871
	fcntl(sock, F_SETFL, flags);
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2872
# endif
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2873
    }
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2874
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2875
    if (newSock < 0) {
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2876
	DBGPRINTF(("SOCKET: accept call failed errno=%d\n", errno));
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2877
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2878
	RETURN (false);
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2879
    }
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2880
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2881
    if (__isNonNilObject(addr)) {
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2882
	OBJ oClass;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2883
	int nInstVars, nInstBytes, objSize;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2884
	char *cp;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2885
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2886
	oClass = __qClass(addr);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2887
	if (! __isBytes(addr) ) {
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2888
	    DBGPRINTF(("SOCKET: bad addr\n"));
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2889
	    closesocket(newSock);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2890
	    RETURN (false);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2891
	}
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2892
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2893
	nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2894
	nInstBytes = OHDR_SIZE + (nInstVars * sizeof(OBJ));
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2895
	objSize = __qSize(addr) - nInstBytes;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2896
	cp = (char *)__InstPtr(addr) + nInstBytes;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2897
	if (objSize < alen) {
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2898
	    DBGPRINTF(("SOCKET: bad addr\n"));
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2899
	    closesocket(newSock);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2900
	    RETURN (false);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2901
	}
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2902
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2903
	/*
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2904
	 * extract the partners address
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2905
	 */
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2906
	bcopy((char *)&sa, cp, alen);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2907
	addrLen = __MKSMALLINT(alen);
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2908
    }
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2909
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2910
    /*
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2911
     * make it a FILE *
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2912
     */
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2913
# ifdef WIN32
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2914
    {
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2915
	int _fd;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2916
	__stxWrapApiEnterCritical();
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2917
#  ifdef __BORLANDC__
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2918
	_fd = _open_osfhandle((long)newSock, 0);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2919
#  else
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2920
	_fd = (int)newSock;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2921
#  endif
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2922
	fp = fdopen(_fd, "r+");
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2923
	__stxWrapApiLeaveCritical();
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2924
	DBGPRINTF(("SOCKET: sock=%d fd=%d fp=%x\n",newSock,_fd, fp));
1558
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2925
    }
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2926
# else
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2927
    fp = fdopen(newSock, "r+");
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2928
# endif
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2929
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2930
    if (! fp) {
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2931
	DBGPRINTF(("SOCKET: fdopen call failed\n"));
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2932
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2933
#  ifdef DO_WRAP_CALLS
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2934
	{
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2935
	  int ret;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2936
	  do {
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2937
	      __threadErrno = 0;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2938
	      ret = STX_WSA_CALL1("closesocket", closesocket, newSock);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2939
	  } while ((ret < 0) && (__threadErrno == EINTR));
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2940
	}
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2941
#  else
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2942
	closesocket(newSock);
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2943
#  endif
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2944
	DBGFPRINTF((stderr, "SOCKET: close (fdopen failed) (%d)\n", newSock));
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2945
	RETURN (false);
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2946
    }
2340
2dc6e31f0142 handleType
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  2947
    __INST(handleType) = @symbol(socketFilePointer);
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2948
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2949
    if ((@global(FileOpenTrace) == true) || __debugging__) {
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2950
# ifdef WIN32
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2951
	{
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2952
	    HANDLE h;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2953
	    int _fd = fileno(fp);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2954
	    h = (HANDLE)_get_osfhandle(_fd);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2955
	    console_fprintf(stderr, "fdopen [Socket] -> %x (fd: %d) (H: %x)\n", fp, _fd, h);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2956
	}
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2957
# else
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2958
	console_fprintf(stderr, "fdopen [Socket] -> %x (fd: %d)\n", fp, newSock);
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2959
# endif
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2960
    }
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2961
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2962
# ifdef BUGGY_STDIO_LIB
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2963
    setbuf(fp, NULL);
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2964
    __INST(buffered) = false;
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2965
# endif
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2966
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2967
# if 0
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2968
    // The original code was:
2417
6df5cc0fc132 Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents: 2414
diff changeset
  2969
    __INST(handle) = __MKEXTERNALADDRESS(fp); __STORESELF(handle);
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2970
    // but for that, gcc generates wrong code, which loads self (volatile) into
2417
6df5cc0fc132 Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents: 2414
diff changeset
  2971
    // a register (bp), then calls __MKEXTERNALADDRESS, then stores indirect bp.
6df5cc0fc132 Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents: 2414
diff changeset
  2972
    // That is wrong if a scavenge occurs in __MKEXTERNALADDRESS, as bp is now still pointing to the old
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2973
    // object.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2974
# endif
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2975
    {
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2976
	OBJ t;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2977
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2978
	t = __MKEXTERNALADDRESS(fp);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2979
	__INST(handle) = t;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2980
	__STORE(self, t);
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2981
    }
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2982
#endif /* not NO_SOCKET */
1558
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2983
%}.
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2984
    mode := #readwrite.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2985
    Lobby register:self.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2986
    binary := false.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2987
    port := aSocket port.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2988
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2989
    addr notNil ifTrue:[
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  2990
	peer := addr.
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2991
    ].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  2992
1558
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2993
    ^ true
2551
6da1bc89b74a changed:
Stefan Vogel <sv@exept.de>
parents: 2516
diff changeset
  2994
!
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2995
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2996
setSocketOption:option argument:arg1 argument:arg2
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2997
    |ok|
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2998
2551
6da1bc89b74a changed:
Stefan Vogel <sv@exept.de>
parents: 2516
diff changeset
  2999
    handle isNil ifTrue:[
2579
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3000
	^ self errorNotOpen
2551
6da1bc89b74a changed:
Stefan Vogel <sv@exept.de>
parents: 2516
diff changeset
  3001
    ].
6da1bc89b74a changed:
Stefan Vogel <sv@exept.de>
parents: 2516
diff changeset
  3002
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3003
%{  /* STACK: 32000 */
2818
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2773
diff changeset
  3004
#ifndef NO_SOCKET
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3005
    OBJ fp = __INST(handle);
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3006
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3007
    if (fp != nil) {
2579
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3008
	SOCKET sock;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3009
	int opt = -1;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3010
	int level = -1;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3011
	int usize = -1;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3012
	int ret;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3013
	union u {
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3014
	    BOOL        u_bool;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3015
	    int         u_int;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3016
	    struct linger u_linger;
2516
592619f82885 Add setsockopt for Multicast stuff
Stefan Vogel <sv@exept.de>
parents: 2465
diff changeset
  3017
# ifdef IP_ADD_MEMBERSHIP
2579
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3018
	    struct ip_mreq      u_ip_mreq;
2516
592619f82885 Add setsockopt for Multicast stuff
Stefan Vogel <sv@exept.de>
parents: 2465
diff changeset
  3019
# endif
2579
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3020
	} u;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3021
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3022
	sock = SOCKET_FROM_FILE_OBJECT(fp);
2516
592619f82885 Add setsockopt for Multicast stuff
Stefan Vogel <sv@exept.de>
parents: 2465
diff changeset
  3023
592619f82885 Add setsockopt for Multicast stuff
Stefan Vogel <sv@exept.de>
parents: 2465
diff changeset
  3024
# ifdef IP_ADD_MEMBERSHIP
2579
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3025
	if (option == @symbol(IP_DROP_MEMBERSHIP)) {
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3026
	    opt = IP_DROP_MEMBERSHIP;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3027
	    goto dropOrAdd;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3028
	}
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3029
	if (option == @symbol(IP_ADD_MEMBERSHIP)) {
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3030
	    /* add membership to a multicast group */
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3031
	    opt = IP_ADD_MEMBERSHIP;
2516
592619f82885 Add setsockopt for Multicast stuff
Stefan Vogel <sv@exept.de>
parents: 2465
diff changeset
  3032
dropOrAdd:
2579
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3033
	    level = IPPROTO_IP;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3034
	    usize = sizeof(u.u_ip_mreq);
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3035
	    if (__isByteArrayLike(arg1) && __isByteArrayLike(arg2)) {
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3036
		memcpy(&u.u_ip_mreq.imr_multiaddr, __byteArrayVal(arg1), sizeof(u.u_ip_mreq.imr_multiaddr));
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3037
		memcpy(&u.u_ip_mreq.imr_interface, __byteArrayVal(arg2), sizeof(u.u_ip_mreq.imr_interface));
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3038
	    }
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3039
	    else
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3040
		goto argError;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3041
	}
2516
592619f82885 Add setsockopt for Multicast stuff
Stefan Vogel <sv@exept.de>
parents: 2465
diff changeset
  3042
# endif /* IP_ADD_MEMBERSHIP */
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3043
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3044
# ifdef SO_BROADCAST
2579
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3045
	if (option == @symbol(SO_BROADCAST)) {
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3046
	    /* Enables transmission and receipt of broadcast messages on the socket. */
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3047
	    opt = SO_BROADCAST;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3048
	    level = SOL_SOCKET;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3049
	    usize = sizeof(u.u_bool);
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3050
	    if (arg1 == true) u.u_bool = TRUE;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3051
	    else if (arg1 == false) u.u_bool = FALSE;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3052
	    else goto argError;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3053
	}
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3054
# endif /* SO_BROADCAST */
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3055
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3056
# ifdef SO_CONDITIONAL
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3057
#  if 0
2579
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3058
	if (option == @symbol(SO_CONDITIONAL)) {
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3059
	    /* Enables sockets to delay the acknowledgment of a connection until after the WSAAccept condition function is called. */
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3060
	    opt = SO_CONDITIONAL;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3061
	    level = SOL_SOCKET;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3062
	    usize = sizeof(u.u_bool);
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3063
	    if (arg1 == true) u.u_bool = TRUE;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3064
	    else if (arg1 == false) u.u_bool = FALSE;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3065
	    else goto argError;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3066
	}
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3067
#  endif
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3068
# endif /* SO_CONDITIONAL */
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3069
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3070
# ifdef SO_DEBUG
2579
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3071
	if (option == @symbol(SO_DEBUG)) {
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3072
	    /* Records debugging information. */
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3073
	    opt = SO_DEBUG;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3074
	    level = SOL_SOCKET;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3075
	    usize = sizeof(u.u_bool);
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3076
	    if (arg1 == true) u.u_bool = TRUE;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3077
	    else if (arg1 == false) u.u_bool = FALSE;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3078
	    else goto argError;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3079
	}
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3080
# endif /* SO_DEBUG */
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3081
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3082
# ifdef SO_DONTLINGER
2579
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3083
	if (option == @symbol(SO_DONTLINGER)) {
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3084
	    /* Does not block close waiting for unsent data to be sent.
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3085
	       Setting this option is equivalent to setting SO_LINGER with l_onoff set to zero. */
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3086
	    opt = SO_DONTLINGER;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3087
	    level = SOL_SOCKET;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3088
	    usize = sizeof(u.u_bool);
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3089
	    if (arg1 == true) u.u_bool = TRUE;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3090
	    else if (arg1 == false) u.u_bool = FALSE;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3091
	    else goto argError;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3092
	}
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3093
# endif /* SO_DONTLINGER */
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3094
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3095
# ifdef SO_DONTROUTE
2579
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3096
	if (option == @symbol(SO_DONTROUTE)) {
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3097
	    /* Does not route: sends directly to interface.
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3098
	       Succeeds but is ignored on AF_INET sockets;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3099
	       fails on AF_INET6 sockets with WSAENOPROTOOPT.
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3100
	       Not supported on ATM sockets (results in an error). */
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3101
	    opt = SO_DONTROUTE;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3102
	    level = SOL_SOCKET;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3103
	    usize = sizeof(u.u_bool);
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3104
	    if (arg1 == true) u.u_bool = TRUE;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3105
	    else if (arg1 == false) u.u_bool = FALSE;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3106
	    else goto argError;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3107
	}
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3108
# endif /* SO_DONTROUTE */
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3109
2516
592619f82885 Add setsockopt for Multicast stuff
Stefan Vogel <sv@exept.de>
parents: 2465
diff changeset
  3110
#if defined(IPPROTO_TCP) && defined(TCP_NODELAY)
2579
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3111
	if (option == @symbol(TCP_NODELAY)) {
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3112
	    /* enable/disable TCP_NODELAY (i.e. disable/enable the Nagle algorithm) */
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3113
	    opt = TCP_NODELAY;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3114
	    level = IPPROTO_TCP;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3115
	    usize = sizeof(u.u_bool);
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3116
	    if (arg1 == true) u.u_bool = TRUE;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3117
	    else if (arg1 == false) u.u_bool = FALSE;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3118
	    else goto argError;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3119
	}
2516
592619f82885 Add setsockopt for Multicast stuff
Stefan Vogel <sv@exept.de>
parents: 2465
diff changeset
  3120
# endif /* TCP_NODELAY */
592619f82885 Add setsockopt for Multicast stuff
Stefan Vogel <sv@exept.de>
parents: 2465
diff changeset
  3121
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3122
# ifdef SO_KEEPALIVE
2579
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3123
	if (option == @symbol(SO_KEEPALIVE)) {
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3124
	    /* Sends keep-alives. Not supported on ATM sockets (results in an error). */
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3125
	    opt = SO_KEEPALIVE;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3126
	    level = SOL_SOCKET;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3127
	    usize = sizeof(u.u_bool);
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3128
	    if (arg1 == true) u.u_bool = TRUE;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3129
	    else if (arg1 == false) u.u_bool = FALSE;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3130
	    else goto argError;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3131
	}
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3132
# endif /* SO_KEEPALIVE */
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3133
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3134
# ifdef SO_LINGER
2579
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3135
	if (option == @symbol(SO_LINGER)) {
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3136
	    /* Lingers on close if unsent data is present. */
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3137
	    opt = SO_LINGER;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3138
	    level = SOL_SOCKET;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3139
	    usize = sizeof(u.u_linger);
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3140
	    if (arg1 == true) u.u_linger.l_onoff = TRUE;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3141
	    else if (arg1 == false) u.u_linger.l_onoff = FALSE;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3142
	    else goto argError;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3143
	    if (arg2 == nil) u.u_linger.l_linger = 0;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3144
	    else if (__isSmallInteger(arg2))u.u_linger.l_linger = __intVal(arg2);
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3145
	    else goto argError;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3146
	    DBGPRINTF(("SOCKET: SO_LINGER %d %d\n", u.u_linger.l_onoff, u.u_linger.l_linger));
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3147
	}
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3148
# endif /* SO_LINGER */
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3149
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3150
# ifdef SO_OOBINLINE
2579
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3151
	if (option == @symbol(SO_OOBINLINE)) {
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3152
	    /* Receives OOB data in the normal data stream. */
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3153
	    opt = SO_OOBINLINE;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3154
	    level = SOL_SOCKET;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3155
	    usize = sizeof(u.u_bool);
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3156
	    if (arg1 == true) u.u_bool = TRUE;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3157
	    else if (arg1 == false) u.u_bool = FALSE;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3158
	    else goto argError;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3159
	}
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3160
# endif /* SO_OOBINLINE */
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3161
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3162
# ifdef SO_RCVBUF
2579
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3163
	if (option == @symbol(SO_RCVBUF)) {
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3164
	    /* Specifies the total per-socket buffer space reserved for receives.
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3165
	       This is unrelated to SO_MAX_MSG_SIZE or the size of a TCP window. */
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3166
	    opt = SO_RCVBUF;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3167
	    level = SOL_SOCKET;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3168
	    usize = sizeof(u.u_int);
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3169
	    if (__isSmallInteger(arg1))u.u_int = __intVal(arg1);
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3170
	    else goto argError;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3171
	}
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3172
# endif /* SO_RCVBUF */
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3173
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3174
# ifdef SO_SNDBUF
2579
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3175
	if (option == @symbol(SO_SNDBUF)) {
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3176
	    /* Specifies the total per-socket buffer space reserved for sends.
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3177
	       This is unrelated to SO_MAX_MSG_SIZE or the size of a TCP window. */
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3178
	    opt = SO_SNDBUF;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3179
	    level = SOL_SOCKET;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3180
	    usize = sizeof(u.u_int);
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3181
	    if (__isSmallInteger(arg1))u.u_int = __intVal(arg1);
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3182
	    else goto argError;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3183
	}
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3184
# endif /* SO_SNDBUF */
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3185
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3186
# ifdef SO_REUSEADDR
2579
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3187
	if (option == @symbol(SO_REUSEADDR)) {
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3188
	    /* Allows the socket to be bound to an address that is already in use.  */
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3189
	    opt = SO_REUSEADDR;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3190
	    level = SOL_SOCKET;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3191
	    usize = sizeof(u.u_bool);
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3192
	    if (arg1 == true) u.u_bool = TRUE;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3193
	    else if (arg1 == false) u.u_bool = FALSE;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3194
	    else goto argError;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3195
	}
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3196
# endif /* SO_OOBINLINE */
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3197
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3198
# ifdef SO_EXCLUSIVEADDRUSE
2579
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3199
	if (option == @symbol(SO_EXCLUSIVEADDRUSE)) {
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3200
	    /* Enables a socket to be bound for exclusive access.
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3201
	       Does not require administrative privilege.  */
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3202
	    opt = SO_EXCLUSIVEADDRUSE;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3203
	    level = SOL_SOCKET;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3204
	    usize = sizeof(u.u_bool);
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3205
	    if (arg1 == true) u.u_bool = TRUE;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3206
	    else if (arg1 == false) u.u_bool = FALSE;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3207
	    else goto argError;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3208
	}
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3209
# endif /* SO_OOBINLINE */
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3210
2579
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3211
	if (usize == -1) goto argError;
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3212
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3213
	ok = ( setsockopt( sock, level, opt, &u, usize) >= 0) ? true : false;
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3214
    }
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3215
argError: ;
2818
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2773
diff changeset
  3216
#endif /* NO_SOCKET */
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3217
%}.
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3218
    ok isNil ifTrue:[
2579
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3219
	self primitiveFailed
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3220
    ].
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3221
    ok ifFalse:[
2579
d70306ae12ac visual c compilable
Claus Gittinger <cg@exept.de>
parents: 2551
diff changeset
  3222
	'setsocketoption failed' infoPrintCR.
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3223
    ].
2551
6da1bc89b74a changed:
Stefan Vogel <sv@exept.de>
parents: 2516
diff changeset
  3224
!
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3225
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3226
shutdown: howNum
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3227
    "shutDown the socket - inform it that no more I/O will be performed.
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  3228
	 0 - read side   (no further reads)
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  3229
	 1 - write side  (no further writes)
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  3230
	 2 - both        (no further I/O at all)
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3231
     shutDown:2
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  3232
	discards any pending data
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  3233
	(as opposed to close, which might wait until data is delivered as set by LINGER)"
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3234
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3235
%{
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3236
#ifndef NO_SOCKET
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3237
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3238
    OBJ fp;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3239
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3240
    fp = __INST(handle);
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3241
    if ((fp != nil) && __isSmallInteger(howNum)) {
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  3242
	SOCKET sock;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  3243
	int ret;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  3244
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  3245
	sock = SOCKET_FROM_FILE_OBJECT(fp);
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3246
# ifdef DO_WRAP_CALLS
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  3247
	do {
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  3248
	    __threadErrno = 0;
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  3249
	    DBGFPRINTF((stderr, "SOCKET: shutDown...\n"));
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  3250
	    ret = STX_WSA_NOINT_CALL2("shutdown", shutdown, sock, __intVal(howNum));
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  3251
	    DBGFPRINTF((stderr, "SOCKET: shutDown -> %d (%d)\n", ret, __threadErrno));
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  3252
	} while ((ret < 0) && (__threadErrno == EINTR));
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3253
# else
2465
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  3254
	__BEGIN_INTERRUPTABLE__
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  3255
	shutdown(sock, __intVal(howNum));
54e32314a856 initialize allocatedBuffer with NULL
ca
parents: 2461
diff changeset
  3256
	__END_INTERRUPTABLE__
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3257
# endif
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3258
    }
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3259
#endif
1339
cc973a42aa54 shutdown: added
Claus Gittinger <cg@exept.de>
parents: 1338
diff changeset
  3260
%}.
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3261
! !
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3262
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3263
!Socket methodsFor:'printing & storing'!
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3264
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3265
printOn:aStream
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3266
    aStream nextPutAll:self className; nextPutAll:'(protocol='.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3267
    protocol printOn:aStream.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3268
    aStream nextPutAll:' port='.
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3269
    self port printOn:aStream.
1462
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  3270
    aStream nextPutAll:' peer='.
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  3271
    peer printOn:aStream.
1842
88c04d1e9e6b changed #printOn:
Stefan Vogel <sv@exept.de>
parents: 1839
diff changeset
  3272
    aStream nextPut:$).
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3273
! !
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3274
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3275
!Socket methodsFor:'queries'!
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3276
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3277
domain
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3278
    "return the sockets addressing domain (i.e. #inet, #unix, #x25, #appletalk)"
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3279
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3280
    ^ domain
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3281
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3282
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3283
getFullSocketAddress
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3284
    "implemented for swazoo project (primitive code can't be loaded as extension)
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3285
     Answer my own address (I am bound to this address).
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3286
     Note that this address may change after a connect or accept."
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3287
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3288
    |error domainClass addr addrLen|
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3289
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3290
    handle isNil ifTrue:[
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3291
	^ self errorNotOpen
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3292
    ].
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3293
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3294
    domainClass := self class socketAddressClassForDomain:domain.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3295
    domainClass isNil ifTrue:[
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3296
	^ self error:'invalid (unsupported) domain'.
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3297
    ].
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3298
    addrLen := domainClass socketAddressSize.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3299
    addr := domainClass new.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3300
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3301
%{
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3302
#ifndef NO_SOCKET
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3303
    OBJ fp = __INST(handle);
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3304
    SOCKET sock;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3305
    int ret;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3306
    union sockaddr_u sa;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3307
    unsigned int alen, alen0;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3308
    char *addrP;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3309
    int addrObjSize, nAddrInstBytes;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3310
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3311
    if (!__isSmallInteger(addrLen)) {
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3312
	DBGPRINTF(("SOCKET: bad addrLen\n"));
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3313
	error = @symbol(badArgument);
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3314
	goto err;
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3315
    }
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3316
    alen = alen0 = __intVal(addrLen);
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3317
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3318
    if (!__isNonNilObject(addr) || !__isBytes(addr)) {
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3319
	DBGPRINTF(("SOCKET: bad addr\n"));
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3320
	error = @symbol(badArgument);
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3321
	goto err;
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3322
    }
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3323
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3324
    {
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3325
	OBJ addrClass;
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3326
	int nAddrInstVars;
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3327
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3328
	addrClass = __qClass(addr);
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3329
	nAddrInstVars = __intVal(__ClassInstPtr(addrClass)->c_ninstvars);
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3330
	nAddrInstBytes = OHDR_SIZE + (nAddrInstVars * sizeof(OBJ));
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3331
	addrObjSize = __qSize(addr) - nAddrInstBytes;
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3332
	if (addrObjSize < alen0) {
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3333
	    DBGPRINTF(("SOCKET: bad addr/alen\n"));
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3334
	    error = @symbol(badArgument);
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3335
	    goto err;
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3336
	}
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3337
    }
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3338
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3339
    sock = SOCKET_FROM_FILE_OBJECT(fp);
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3340
# ifdef WIN32
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3341
    __threadErrno = 0;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3342
# endif
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3343
    ret = getsockname(sock, (struct sockaddr *)&sa, &alen);
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3344
    if (ret < 0) {
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3345
# ifdef WIN32
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3346
	errno = WSAGetLastError();
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3347
# endif
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3348
	DBGPRINTF(("SOCKET: getsocketname failed ret=%d errno=%d\n", ret, errno));
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3349
	error = __MKSMALLINT(errno);
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3350
	goto err;
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3351
    }
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3352
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3353
    if (addrObjSize < alen) {
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3354
	DBGPRINTF(("SOCKET: bad addr\n"));
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3355
	error = @symbol(badArgument);
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3356
	goto err;
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3357
    }
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3358
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3359
    addrP = (char *)__InstPtr(addr) + nAddrInstBytes;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3360
    bcopy((char *)&sa, addrP, alen);
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3361
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3362
    addrLen = __MKSMALLINT(alen);
1535
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3363
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3364
err:;
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3365
#else /* NO_SOCKET */
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3366
    error = @symbol(notImplemented);
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3367
#endif /* NO_SOCKET */
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3368
%}.
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3369
    error notNil ifTrue:[
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3370
	^ self errorReporter reportOn:error
1535
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3371
    ].
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3372
    ^ addr
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3373
!
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3374
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3375
getName
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3376
    "return the name; here, we return the ports name"
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3377
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3378
    ^ self port printString
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3379
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3380
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3381
getPeer
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3382
    "ST-80 compatibility: return an IPSocketAddress instance representing
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3383
     my hostname/port combination.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3384
     If you are interested in the hostname, use getPeerName directly."
102
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  3385
1187
7e5f2f6b177d getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents: 1186
diff changeset
  3386
    ^ peer
102
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  3387
!
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  3388
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3389
getPeerName
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3390
    "return the peer name; thats the hostname (or dotted name) of the
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3391
     partners host after an accept."
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3392
1187
7e5f2f6b177d getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents: 1186
diff changeset
  3393
    peerName isNil ifTrue:[
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3394
	peerName := self class peerNameFromDomain:domain peer:peer.
1187
7e5f2f6b177d getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents: 1186
diff changeset
  3395
    ].
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3396
    ^ peerName
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3397
!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3398
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3399
getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3400
    "implemented for swazoo project primitive code cant load as extension
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3401
     answer my own address (I am bound to this address).
1146
71a9df78ba9e bad spelling
Stefan Vogel <sv@exept.de>
parents: 1136
diff changeset
  3402
     Note that this address may change after connect or accept."
1029
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  3403
1535
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3404
    ^ self getFullSocketAddress hostAddress
1146
71a9df78ba9e bad spelling
Stefan Vogel <sv@exept.de>
parents: 1136
diff changeset
  3405
!
71a9df78ba9e bad spelling
Stefan Vogel <sv@exept.de>
parents: 1136
diff changeset
  3406
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3407
isActive
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3408
    "return true, if the receiver has a connection"
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3409
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3410
    ^ handle notNil
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3411
!
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3412
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3413
isConnected
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3414
    "return true, if the receiver has a connection"
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3415
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3416
    ^ self isActive
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3417
	and:[peer notNil]
1558
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3418
!
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3419
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3420
port
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3421
    "return the port number (or name for unix-sockets) to which the socket is bound
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3422
     - so this is the local port."
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3423
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3424
"/    port isNil ifTrue:[
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3425
"/        port := self getFullSocketAddress port.
1505
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
  3426
"/    ].
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3427
71
claus
parents: 63
diff changeset
  3428
    ^ port
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3429
!
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3430
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3431
type
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3432
    "return the sockets connection type (i.e. #datagram, #stream etc)"
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3433
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3434
    ^ socketType
81
claus
parents: 79
diff changeset
  3435
! !
claus
parents: 79
diff changeset
  3436
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3437
!Socket methodsFor:'socket setup'!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3438
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3439
domain:domainArg type:typeArg
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3440
    "set up socket with domain and type.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3441
     This is a low level entry; no binding, listening or connect
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3442
     is done. Both arguments must be symbols from one of
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3443
     #inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3444
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3445
    ^ self domain:domainArg type:typeArg protocol:0 reuseAddress:true
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3446
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3447
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3448
domain:domainArg type:typeArg protocol:protocolNumber
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3449
    "set up socket with domain, type and protocol number.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3450
     This is a low level entry; no binding, listening or connect
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3451
     is done. Both arguments must be symbols from one of
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3452
     #inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp."
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3453
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3454
    ^ self domain:domainArg type:typeArg protocol:protocolNumber reuseAddress:true
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3455
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3456
    "
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3457
     Socket new domain:#inet type:#stream
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3458
     Socket new domain:#unix type:#stream
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3459
    "
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3460
!
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3461
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3462
domain:domainArg type:typeArg protocol:protocolNumber reuseAddress:reuse
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3463
    "set up socket with domain, type and protocol number.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3464
     This is a low level entry; no binding, listening or connect
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3465
     is done. Both arguments must be symbols from one of
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3466
     #inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3467
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3468
     The reuse boolean argument controls if the SO_REUSEADDR socket option
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3469
     is to be set (to avoid the 'bind: address in use' error)."
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3470
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3471
    |domainName domainCode typeCode error|
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3472
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3473
    handle notNil ifTrue:[
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3474
	^ self errorAlreadyOpen
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3475
    ].
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3476
    domainName := SocketAddress domainCodeFromName:domainArg.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3477
    domainCode := OperatingSystem domainCodeOf:domainName.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3478
    typeCode := OperatingSystem socketTypeCodeOf:typeArg.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3479
%{
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3480
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3481
#ifndef NO_SOCKET
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3482
    FILE *fp;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3483
    int dom, typ, pf, proto = 0;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3484
    int on = 1;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3485
    SOCKET sock;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3486
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3487
    if (! __isSmallInteger(domainCode)) {
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3488
	error = @symbol(badArgument1);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3489
	goto out;
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3490
    }
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3491
    if (! __isSmallInteger(typeCode)) {
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3492
	error = @symbol(badArgument2);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3493
	goto out;
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3494
    }
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3495
    if (protocolNumber != nil) {
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3496
	if (!__isSmallInteger(protocolNumber)) {
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3497
	    error = @symbol(badArgument3);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3498
	    goto out;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3499
	}
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3500
	proto = __intVal(protocolNumber);
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3501
    }
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3502
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3503
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3504
    /*
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3505
     * get address and protocol-family
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3506
     */
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3507
    dom = __intVal(domainCode);
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3508
    typ = __intVal(typeCode);
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3509
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3510
# ifdef SOCKET_BLOCKS
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3511
#  ifdef DO_WRAP_CALLS
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3512
    do {
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3513
	__threadErrno = 0;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3514
	sock = STX_WSA_NOINT_CALL3("socket", socket, dom, typ, proto);
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3515
    } while ((sock < 0) && (__threadErrno == EINTR));
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3516
#  else
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3517
    __BEGIN_INTERRUPTABLE__
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3518
    do {
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3519
	DBGPRINTF(("SOCKET: opening socket domain=%d type=%d proto=%d\n", dom, typ, proto));
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3520
	sock = socket(dom, typ, proto);
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3521
#   if defined(EPROTONOSUPPORT) /* for SGI */
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3522
	if ((proto != 0) && (sock < 0) && (errno == EPROTONOSUPPORT)) {
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3523
	    DBGPRINTF(("SOCKET: retry with UNSPEC protocol\n"));
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3524
	    proto = 0;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3525
	    sock = socket(dom, typ, 0);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3526
	}
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3527
#   endif
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3528
    } while ((sock < 0) && (errno == EINTR));
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3529
    __END_INTERRUPTABLE__
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3530
#  endif
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3531
# else
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3532
    sock = socket(dom, typ, proto);
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3533
#  if defined(EPROTONOSUPPORT) /* for SGI */
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3534
    if ((proto != 0) && (sock < 0) && (errno == EPROTONOSUPPORT)) {
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3535
	DBGPRINTF(("SOCKET: retry with UNSPEC protocol\n"));
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3536
	proto = 0;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3537
	sock = socket(dom, typ, 0);
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3538
    }
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3539
#  endif
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3540
# endif
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3541
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3542
    DBGFPRINTF((stderr, "SOCKET: create newSock=%d\n", sock));
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3543
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3544
# ifdef WIN32
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3545
    if (sock == INVALID_SOCKET)
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3546
# else
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3547
    if (sock < 0)
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3548
# endif
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3549
    {
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3550
	DBGPRINTF(("SOCKET: socket(dom=%d typ=%d proto=%d) call failed errno=%d\n", dom, typ, proto, errno));
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3551
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3552
    } else {
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3553
# ifdef SO_REUSEADDR
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3554
	if (reuse == true) {
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3555
	    DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR\n"));
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3556
	    if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) {
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3557
		DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n"));
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3558
	    }
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3559
	}
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3560
# endif /* SO_REUSEADDR */
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3561
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3562
# ifdef SET_LINGER_WHEN_CREATING_SOCKET
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3563
#  ifdef SO_LINGER
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3564
	{
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3565
	    struct linger l;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3566
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3567
	    l.l_onoff = 1;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3568
	    l.l_linger = 30;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3569
	    setsockopt( sock, SOL_SOCKET, SO_LINGER, &l, sizeof(l));
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3570
	}
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3571
#  endif
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3572
# endif
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3573
# ifdef WIN32
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3574
	/*
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3575
	 * make it blocking
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3576
	 */
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3577
	{
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3578
	    int zero = 0;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3579
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3580
	    ioctlsocket(sock, FIONBIO, &zero);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3581
	}
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3582
# endif
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3583
	/*
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3584
	 * make it a FILE *
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3585
	 */
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3586
# ifdef WIN32
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3587
	{
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3588
	    int _fd;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3589
	    __stxWrapApiEnterCritical();
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3590
#  ifdef __BORLANDC__
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3591
	    _fd = _open_osfhandle((long)sock, 0);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3592
#  else
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3593
	    _fd = (int)sock;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3594
#  endif
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3595
	    fp = fdopen(_fd, "r+");
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3596
	    __stxWrapApiLeaveCritical();
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3597
	    DBGPRINTF(("SOCKET: sock=%d fd=%d fp=%x\n",sock,_fd, fp));
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3598
	}
2680
ff00563f0444 Protect against concurrent access when doing fclose and fdopen
Stefan Vogel <sv@exept.de>
parents: 2579
diff changeset
  3599
# else
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3600
	fp = fdopen(sock, "r+");
2680
ff00563f0444 Protect against concurrent access when doing fclose and fdopen
Stefan Vogel <sv@exept.de>
parents: 2579
diff changeset
  3601
# endif
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3602
	if (! fp) {
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3603
	    DBGPRINTF(("SOCKET: fdopen call failed\n"));
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3604
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3605
# ifdef DO_WRAP_CALLS
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3606
	    { int ret;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3607
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3608
	      do {
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3609
		__threadErrno = 0;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3610
		ret = STX_WSA_NOINT_CALL1("closesocket", closesocket, sock);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3611
	      } while ((ret < 0) && (__threadErrno == EINTR));
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3612
	    }
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3613
# else
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3614
	    __BEGIN_INTERRUPTABLE__
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3615
	    closesocket(sock);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3616
	    DBGFPRINTF((stderr, "SOCKET: fdopen failed (%d)\n", sock));
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3617
	    __END_INTERRUPTABLE__
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3618
# endif
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3619
	} else {
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3620
	    __INST(handleType) = @symbol(socketFilePointer);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3621
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3622
	    if ((@global(FileOpenTrace) == true) || __debugging__) {
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3623
		console_fprintf(stderr, "fdopen [Socket] -> %x\n", fp);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3624
	    }
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3625
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3626
# if 0
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3627
	    // The original code was:
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3628
	    __INST(handle) = __MKEXTERNALADDRESS(fp); __STORESELF(handle);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3629
	    // but for that, gcc generates wrong code, which loads self (volatile) into
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3630
	    // a register (bp), then calls __MKEXTERNALADDRESS, then stores indirect bp.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3631
	    // That is wrong if a scavenge occurs in __MKEXTERNALADDRESS, as bp is now still pointing to the old
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3632
	    // object.
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3633
# endif
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3634
	    {
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3635
		OBJ t;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3636
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3637
		t = __MKEXTERNALADDRESS(fp);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3638
		__INST(handle) = t;
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3639
		__STORE(self, t);
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3640
	    }
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3641
	}
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3642
    }
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3643
#endif
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3644
out:;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3645
%}.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3646
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3647
    "all ok?"
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3648
    handle notNil ifTrue:[
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3649
	domain := domainArg.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3650
	socketType := typeArg.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3651
	Lobby register:self.
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3652
    ] ifFalse:[
2773
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3653
	error notNil ifTrue:[
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3654
	    ^ self primitiveFailed:error.
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3655
	].
ab3049f4a351 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
  3656
	^ self openError
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3657
    ].
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3658
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3659
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3660
     Socket new domain:#inet type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3661
     Socket new domain:#unix type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3662
    "
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3663
! !
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3664
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3665
!Socket methodsFor:'specials'!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3666
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3667
receiveBufferSize
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3668
    "get the send buffer size - for special applications only.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3669
     Not all operatingSystems offer this functionality
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3670
     (returns nil, if unsupported)"
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3671
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3672
    handle isNil ifTrue:[
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3673
	^ self errorNotOpen
1335
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3674
    ].
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3675
%{
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3676
#if defined(SO_RCVBUF) && defined(SOL_SOCKET)
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3677
    {
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3678
	OBJ fp = __INST(handle);
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3679
	SOCKET sock;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3680
	int opt;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3681
	unsigned int size;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3682
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3683
	sock = SOCKET_FROM_FILE_OBJECT(fp);
1568
3bca500e0c7a send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents: 1561
diff changeset
  3684
	if (getsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *)&opt, &size) >= 0) {
3bca500e0c7a send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents: 1561
diff changeset
  3685
	    RETURN( __MKSMALLINT(opt) );
3bca500e0c7a send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents: 1561
diff changeset
  3686
	}
1335
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3687
    }
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3688
#endif
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3689
%}.
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3690
    ^ nil
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3691
!
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3692
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3693
receiveBufferSize:size
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3694
    "set the receive buffer size - for special applications only.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3695
     Not all operatingSystems offer this functionality
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3696
     (returns false, if unsupported)"
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3697
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3698
    handle isNil ifTrue:[
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3699
	^ self errorNotOpen
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3700
    ].
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3701
%{
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3702
#if defined(SO_RCVBUF) && defined(SOL_SOCKET)
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3703
    if (__isSmallInteger(size)) {
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3704
	OBJ fp = __INST(handle);
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3705
	SOCKET sock;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3706
	int opt;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3707
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3708
	sock = SOCKET_FROM_FILE_OBJECT(fp);
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3709
	opt = __intVal(size);
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3710
	if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *)&opt, sizeof(int)) >= 0 ) {
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3711
	    RETURN(true);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3712
	}
1335
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3713
    }
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3714
#endif
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3715
%}.
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3716
    ^ false
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3717
!
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3718
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3719
receiveTimeout
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3720
    "get the receive timeout in millis - for special applications only.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3721
     Not all operatingSystems offer this functionality
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3722
     (returns nil, if unsupported)"
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3723
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3724
    |millis|
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3725
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3726
    handle isNil ifTrue:[
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3727
	^ self errorNotOpen
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3728
    ].
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3729
%{
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3730
#if defined(SO_RCVTIMEO) && defined(SOL_SOCKET)
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3731
    {
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3732
	OBJ fp = __INST(handle);
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3733
	int sock;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3734
	int len;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3735
	int __millis;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3736
	struct timeval tv = {0, 0};
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3737
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3738
	sock = fileno(__FILEVal(fp));
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3739
	len = sizeof(struct timeval);
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3740
	if (getsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (void *)&tv, &len) == 0) {
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3741
	    __millis = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3742
	    millis = __mkSmallInteger(__millis);
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3743
# if 0
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3744
	    console_fprintf(stderr, "getsockopt -> s:%d us:%d -> millis:%d\n", tv.tv_sec, tv.tv_usec, __millis);
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3745
# endif
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3746
	} else {
1839
c10cd58ec334 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  3747
	    console_fprintf(stderr, "Socket [warning]: getsockopt %d failed; errno=%d\n", sock, errno);
1568
3bca500e0c7a send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents: 1561
diff changeset
  3748
	}
3bca500e0c7a send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents: 1561
diff changeset
  3749
    }
3bca500e0c7a send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents: 1561
diff changeset
  3750
#endif
3bca500e0c7a send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents: 1561
diff changeset
  3751
%}.
3bca500e0c7a send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents: 1561
diff changeset
  3752
    millis notNil ifTrue:[^ millis / 1000 ].
3bca500e0c7a send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents: 1561
diff changeset
  3753
    ^ nil
3bca500e0c7a send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents: 1561
diff changeset
  3754
!
3bca500e0c7a send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents: 1561
diff changeset
  3755
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3756
receiveTimeout:seconds
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3757
    "set the receive timeout - for special applications only.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3758
     Not all operatingSystems offer this functionality
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3759
     (returns false, if unsupported)"
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3760
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3761
    |millis|
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3762
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3763
    handle isNil ifTrue:[
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3764
	^ self errorNotOpen
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3765
    ].
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3766
    millis := (seconds * 1000) rounded.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3767
%{
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3768
#if defined(SO_RCVTIMEO) && defined(SOL_SOCKET)
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3769
    if (__isSmallInteger(millis)) {
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3770
	OBJ fp = __INST(handle);
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3771
	int sock;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3772
	int __millis = __intVal(millis);
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3773
	struct timeval tv = {0, 0};
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3774
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3775
	sock = fileno(__FILEVal(fp));
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3776
	tv.tv_sec = __millis / 1000;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3777
	tv.tv_usec = (__millis % 1000) * 1000;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3778
# if 0
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3779
	console_fprintf(stderr, "setsockopt -> millis:%d -> s:%d us:%d \n", __millis, tv.tv_sec, tv.tv_usec);
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3780
# endif
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3781
	if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (void *)&tv, sizeof(struct timeval)) == 0) {
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3782
	    RETURN(true);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3783
	}
1839
c10cd58ec334 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  3784
	console_fprintf(stderr, "Socket [warning]: setsockopt %d failed; errno=%d\n", sock, errno);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3785
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3786
#endif
71
claus
parents: 63
diff changeset
  3787
%}.
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3788
    ^ false
81
claus
parents: 79
diff changeset
  3789
!
claus
parents: 79
diff changeset
  3790
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3791
sendBufferSize
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3792
    "get the send buffer size - for special applications only.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3793
     Not all operatingSystems offer this functionality
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3794
     (returns nil, if unsupported)"
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3795
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3796
    handle isNil ifTrue:[
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3797
	^ self errorNotOpen
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3798
    ].
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3799
%{
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3800
#if defined(SO_SNDBUF) && defined(SOL_SOCKET)
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3801
    {
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3802
	OBJ fp = __INST(handle);
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3803
	SOCKET sock;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3804
	int opt;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3805
	unsigned int size;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3806
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3807
	sock = SOCKET_FROM_FILE_OBJECT(fp);
1568
3bca500e0c7a send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents: 1561
diff changeset
  3808
	if (getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *)&opt, &size) >= 0) {
3bca500e0c7a send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents: 1561
diff changeset
  3809
	    RETURN( __MKSMALLINT(opt) );
3bca500e0c7a send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents: 1561
diff changeset
  3810
	}
1335
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3811
    }
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3812
#endif
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3813
%}.
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3814
    ^ nil
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3815
!
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3816
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3817
sendBufferSize:size
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3818
    "set the send buffer size - for special applications only.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3819
     Not all operatingSystems offer this functionality
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3820
     (returns false, if unsupported)"
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3821
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3822
    handle isNil ifTrue:[
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3823
	^ self errorNotOpen
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3824
    ].
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3825
%{
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3826
#if defined(SO_SNDBUF) && defined(SOL_SOCKET)
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3827
    if (__isSmallInteger(size)) {
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3828
	OBJ fp = __INST(handle);
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3829
	SOCKET sock;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3830
	int opt;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3831
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3832
	sock = SOCKET_FROM_FILE_OBJECT(fp);
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3833
	opt = __intVal(size);
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3834
	if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *)&opt, sizeof(int)) >= 0) {
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3835
	    RETURN(true);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3836
	}
1335
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3837
    }
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3838
#endif
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3839
%}.
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3840
    ^ false
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3841
!
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3842
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3843
sendTimeout
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3844
    "get the send timeout in millis - for special applications only.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3845
     Not all operatingSystems offer this functionality
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3846
     (returns nil, if unsupported)"
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3847
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3848
    |millis|
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3849
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3850
    handle isNil ifTrue:[
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3851
	^ self errorNotOpen
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3852
    ].
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3853
%{
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3854
#if defined(SO_SNDTIMEO) && defined(SOL_SOCKET)
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3855
    {
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3856
	OBJ fp = __INST(handle);
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3857
	int sock;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3858
	int len;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3859
	int __millis;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3860
	struct timeval tv = {0, 0};
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3861
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3862
	sock = fileno(__FILEVal(fp));
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3863
	len = sizeof(struct timeval);
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3864
	if (getsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (void *)&tv, &len) == 0) {
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3865
	    __millis = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3866
	    millis = __mkSmallInteger(__millis);
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3867
# if 0
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3868
	    console_fprintf(stderr, "getsockopt -> s:%d us:%d -> millis:%d\n", tv.tv_sec, tv.tv_usec, __millis);
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3869
# endif
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3870
	} else {
1839
c10cd58ec334 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  3871
	    console_fprintf(stderr, "Socket [warning]: getsockopt %d failed; errno=%d\n", sock, errno);
1568
3bca500e0c7a send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents: 1561
diff changeset
  3872
	}
3bca500e0c7a send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents: 1561
diff changeset
  3873
    }
3bca500e0c7a send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents: 1561
diff changeset
  3874
#endif
3bca500e0c7a send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents: 1561
diff changeset
  3875
%}.
3bca500e0c7a send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents: 1561
diff changeset
  3876
    millis notNil ifTrue:[^ millis / 1000 ].
3bca500e0c7a send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents: 1561
diff changeset
  3877
    ^ nil
3bca500e0c7a send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents: 1561
diff changeset
  3878
!
3bca500e0c7a send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents: 1561
diff changeset
  3879
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3880
sendTimeout:seconds
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3881
    "set the send timeout - for special applications only.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3882
     Not all operatingSystems offer this functionality
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3883
     (returns false, if unsupported)"
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3884
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3885
    |millis|
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3886
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3887
    handle isNil ifTrue:[
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3888
	^ self errorNotOpen
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3889
    ].
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3890
    millis := (seconds * 1000) rounded.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3891
%{
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3892
#if defined(SO_SNDTIMEO) && defined(SOL_SOCKET)
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3893
    if (__isSmallInteger(millis)) {
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 2308
diff changeset
  3894
	OBJ fp = __INST(handle);
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3895
	int sock;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3896
	int __millis = __intVal(millis);
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3897
	struct timeval tv = {0, 0};
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3898
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3899
	sock = fileno(__FILEVal(fp));
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3900
	tv.tv_sec = __millis / 1000;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3901
	tv.tv_usec = (__millis % 1000) * 1000;
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3902
# if 0
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3903
	console_fprintf(stderr, "setsockopt -> millis:%d -> s:%d us:%d \n", __millis, tv.tv_sec, tv.tv_usec);
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3904
# endif
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3905
	if (setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (void *)&tv, sizeof(struct timeval)) == 0) {
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3906
	    RETURN(true);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3907
	}
1839
c10cd58ec334 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  3908
	console_fprintf(stderr, "Socket [warning]: setsockopt %d failed; errno=%d\n", sock, errno);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3909
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3910
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3911
%}.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3912
    ^ false
1568
3bca500e0c7a send and receiveTimeout fixed
Claus Gittinger <cg@exept.de>
parents: 1561
diff changeset
  3913
1340
eb9b1f1340e5 setTCP_NODELAY
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
  3914
!
eb9b1f1340e5 setTCP_NODELAY
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
  3915
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3916
setTCPCork:aBoolean
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3917
    "enable/disable TCP_CORK (do-not-send-partial-frames)
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3918
     For special applications only.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3919
     Not all OperatingSystems offer this functionality
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3920
     (returns false, if unsupported)"
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3921
2551
6da1bc89b74a changed:
Stefan Vogel <sv@exept.de>
parents: 2516
diff changeset
  3922
    ^ self setSocketOption:#'TCP_CORK' argument:aBoolean argument:nil.
1885
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3923
!
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3924
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3925
setTCPNoDelay:aBoolean
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3926
    "enable/disable TCP_NODELAY (i.e. disable/enable the Nagle algorithm)
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3927
     For special applications only.
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3928
     Not all OperatingSystems offer this functionality
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3929
     (returns false, if unsupported)"
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  3930
2551
6da1bc89b74a changed:
Stefan Vogel <sv@exept.de>
parents: 2516
diff changeset
  3931
    ^ self setSocketOption:#'TCP_NODELAY' argument:aBoolean argument:nil.
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3932
! !
82
claus
parents: 81
diff changeset
  3933
1935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3934
!Socket methodsFor:'waiting'!
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3935
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3936
waitForNewConnectionOrDataOnAny:otherConnections timeout:timeoutSeconds
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3937
    "suspend the current process, until either a new connection comes
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3938
     in at the receiver, or data arrives on any of the otherConnections.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3939
     For a new connection, an accept is performed and the new socket is returned.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3940
     For an old connection, that socket is returned.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3941
     In any case, the caller gets a socket to operate on as return value,
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3942
     or nil, if a timeout occured.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3943
     This method implements the inner wait-primitive of a multi-connection
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3944
     server application."
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3945
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3946
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3947
    |wasBlocked sema|
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3948
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3949
    "first, a quick check if data is already available"
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3950
    self canReadWithoutBlocking ifTrue:[
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3951
	^ self accept.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3952
    ].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3953
    otherConnections do:[:aConnection |
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3954
	aConnection canReadWithoutBlocking ifTrue:[
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3955
	    ^ aConnection
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3956
	]
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3957
    ].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3958
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3959
    [
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3960
	"check again - prevent incoming interrupts from disturbing our setup"
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3961
	wasBlocked := OperatingSystem blockInterrupts.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3962
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3963
	self canReadWithoutBlocking ifTrue:[
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3964
	    ^ self accept.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3965
	].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3966
	otherConnections do:[:aConnection |
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3967
	    aConnection canReadWithoutBlocking ifTrue:[
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3968
		^ aConnection
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3969
	    ]
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3970
	].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3971
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3972
	"nope - must wait"
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3973
	sema := Semaphore new name:'multiReadWait'.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3974
	otherConnections do:[:aConnection |
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3975
	    Processor signal:sema onInput:(aConnection fileDescriptor).
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3976
	].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3977
	Processor signal:sema onInput:(self fileDescriptor).
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3978
	timeoutSeconds notNil ifTrue:[
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3979
	    Processor signal:sema afterSeconds:timeoutSeconds
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3980
	].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3981
	Processor activeProcess state:#ioWait.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3982
	sema wait.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3983
    ] ensure:[
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3984
	sema notNil ifTrue:[Processor disableSemaphore:sema].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3985
	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3986
    ].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3987
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3988
    "see who it was ..."
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3989
    self canReadWithoutBlocking ifTrue:[
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3990
	^ self accept.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3991
    ].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3992
    otherConnections do:[:aConnection |
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3993
	aConnection canReadWithoutBlocking ifTrue:[
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3994
	    ^ aConnection
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3995
	]
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3996
    ].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3997
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3998
    "none - a timeout"
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  3999
    ^ nil
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  4000
!
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  4001
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  4002
waitForNewConnectionWithTimeout:timeoutSeconds
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  4003
    "suspend the current process, until a new connection comes
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  4004
     in at the receiver or a timeout occurs.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  4005
     For a new connection, an accept is performed and the new socket is returned.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  4006
     Returns nil, if a timeout occured.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  4007
     This method implements the inner wait-primitive of a single-connection
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  4008
     server application."
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  4009
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  4010
    (self readWaitWithTimeout:timeoutSeconds) ifTrue:[
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  4011
	"a timeout occurred - no connection within timeout"
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  4012
	^ nil
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  4013
    ].
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  4014
    ^ self accept.
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  4015
! !
326f8d31e7ca Clean up:
Stefan Vogel <sv@exept.de>
parents: 1911
diff changeset
  4016
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  4017
!Socket class methodsFor:'documentation'!
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  4018
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  4019
version
2818
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2773
diff changeset
  4020
    ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.269 2012-09-03 20:23:42 cg Exp $'
2292
c4b0b901278e added: #standardTimeout
Claus Gittinger <cg@exept.de>
parents: 1940
diff changeset
  4021
!
c4b0b901278e added: #standardTimeout
Claus Gittinger <cg@exept.de>
parents: 1940
diff changeset
  4022
c4b0b901278e added: #standardTimeout
Claus Gittinger <cg@exept.de>
parents: 1940
diff changeset
  4023
version_CVS
2818
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2773
diff changeset
  4024
    ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.269 2012-09-03 20:23:42 cg Exp $'
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  4025
! !