Socket.st
author Stefan Vogel <sv@exept.de>
Tue, 28 Jun 2005 15:25:08 +0200
changeset 1560 50c1e959ede8
parent 1558 a563aac90660
child 1561 43a2b204e80e
permissions -rw-r--r--
Avoid compiler signed/unsigned warnings (gcc4)
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
"
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    12
888
a868b0e54a2b ipAddress stuff
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
    13
"{ Package: 'stx:libbasic2' }"
a868b0e54a2b ipAddress stuff
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
    14
63
7dd3d5b7877e *** empty log message ***
claus
parents: 58
diff changeset
    15
NonPositionableExternalStream subclass:#Socket
1505
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
    16
	instanceVariableNames:'domain socketType protocol port serviceName peer peerName
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
    17
		listening'
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
    18
	classVariableNames:''
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
    19
	poolDictionaries:''
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
    20
	category:'Streams-External'
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    21
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    22
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    23
!Socket primitiveDefinitions!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    24
%{
444
9ba31a1fba38 always unbuffered on linux
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
    25
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
    26
/* #define DGRAM_DEBUG /* */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
    27
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
    28
#include "stxOSDefs.h"
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    29
1503
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
    30
#ifdef WIN32
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
    31
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__
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
    34
# define __BEGIN_INTERRUPTABLE__ ..
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
    35
# define __END_INTERRUPTABLE__ ..
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
    36
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
    37
# define WRAP_STDIO
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    38
# 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
    39
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    40
# define SOCKET_FROM_FD(fd)               (_get_osfhandle(fd))
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
    41
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
    42
#else /* not WIN32 */
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
    43
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    44
# 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
    45
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    46
#if 0
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    47
# undef INT
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    48
# undef Array
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    49
# undef Number
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    50
# undef Method
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    51
# undef Point
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    52
# undef Rectangle
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    53
# undef Block
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    54
# undef Context
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    55
# undef String
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    56
# undef Message
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    57
# undef Object
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    58
# undef Date
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    59
# undef Time
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    60
# undef Set
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    61
# undef Signal
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    62
# undef Delay
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    63
#endif
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
    64
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
    65
#endif /* WIN32 */
1503
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
    66
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    67
# define SOCKET_FROM_FILE(f)             (SOCKET_FROM_FD(fileno(f)))
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    68
# 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
    69
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    70
#ifndef WIN32
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    71
# define closesocket(sock)    close(sock)
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
    72
# define SOCKET               int
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    73
#endif
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    74
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    75
#include <stdio.h>
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    76
#include <errno.h>
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    77
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
    78
#ifdef WANT__TCP_DOT_H
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
    79
# include <netinet/tcp.h>
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
    80
#endif
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
    81
1344
70d73917ac78 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1343
diff changeset
    82
#ifdef WANT__NETDB_DOT_H
70d73917ac78 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1343
diff changeset
    83
# include <netdb.h>
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
    84
#endif
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
    85
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    86
#if 0
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    87
#ifdef WIN32
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    88
# ifdef __BORLANDC__
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    89
#  define NO_GDI
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    90
#  include <windows.h>
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    91
# else
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    92
/* # include <WINSOCK.H> /* */
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    93
#  include <WINSOCK2.H>
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    94
# endif
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    95
#endif
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    96
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    97
#if 0
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    98
# ifdef __DEF_Array
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
    99
#  define Array __DEF_Array
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   100
# endif
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   101
# ifdef __DEF_Number
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   102
#  define Number __DEF_Number
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   103
# endif
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   104
# ifdef __DEF_Method
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   105
#  define Method __DEF_Method
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   106
# endif
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   107
# ifdef __DEF_Point
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   108
#  define Point __DEF_Point
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   109
# endif
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   110
# ifdef __DEF_Block
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   111
#  define Block __DEF_Block
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   112
# endif
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   113
# ifdef __DEF_Context
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   114
#  define Context __DEF_Context
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   115
# endif
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   116
# ifdef __DEF_String
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   117
#  define String __DEF_String
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   118
# endif
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   119
# ifdef __DEF_Message
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   120
#  define Message __DEF_Message
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   121
# endif
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   122
# ifdef __DEF_Object
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   123
#  define Object __DEF_Object
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   124
# endif
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   125
# ifdef __DEF_Date
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   126
#  define Date __DEF_Date
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   127
# endif
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   128
# ifdef __DEF_Time
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   129
#  define Time __DEF_Time
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   130
# endif
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   131
# ifdef __DEF_Set
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   132
#  define Set __DEF_Set
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   133
# endif
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   134
# ifdef __DEF_Signal
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   135
#  define Signal __DEF_Signal
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   136
# endif
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   137
# ifdef __DEF_Delay
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   138
#   define Delay __DEF_Delay
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   139
# endif
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   140
#endif
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   141
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   142
# define xxxINT int
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   143
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   144
#endif
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   145
739
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   146
#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
   147
# define USE_H_ERRNO
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   148
#endif
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   149
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   150
/*
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   151
 * on some systems errno is a macro ... check for it here
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   152
 */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   153
#ifndef errno
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   154
 extern errno;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   155
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   156
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   157
#ifdef USE_H_ERRNO
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   158
# ifndef h_errno
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   159
 extern h_errno;
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   160
# endif
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   161
#endif
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   162
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   163
#ifdef DEBUG
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   164
# define DBGPRINTF(x)    { if (__debugging__) printf x; }
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
   165
# define DBGFPRINTF(x)   { if (__debugging__) fprintf x; }
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   166
#else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   167
# define DBGPRINTF(x)    /* as nothing */
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
   168
# define DBGFPRINTF(x)   /* as nothing */
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   169
#endif
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   170
#ifdef SRWDEBUG
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   171
# define SRWPRINTF(x)    { if (__debugging__) printf x; }
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
# define SRWPRINTF(x)    /* as nothing */
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   174
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   175
1531
ec98158988ca compilable under unix
Claus Gittinger <cg@exept.de>
parents: 1529
diff changeset
   176
#ifndef TRUE
1535
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
   177
# define TRUE   1
1531
ec98158988ca compilable under unix
Claus Gittinger <cg@exept.de>
parents: 1529
diff changeset
   178
#endif
ec98158988ca compilable under unix
Claus Gittinger <cg@exept.de>
parents: 1529
diff changeset
   179
#ifndef FALSE
1535
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
   180
# define FALSE  0
1531
ec98158988ca compilable under unix
Claus Gittinger <cg@exept.de>
parents: 1529
diff changeset
   181
#endif
ec98158988ca compilable under unix
Claus Gittinger <cg@exept.de>
parents: 1529
diff changeset
   182
#ifndef WIN32
ec98158988ca compilable under unix
Claus Gittinger <cg@exept.de>
parents: 1529
diff changeset
   183
typedef int BOOL;
ec98158988ca compilable under unix
Claus Gittinger <cg@exept.de>
parents: 1529
diff changeset
   184
#endif
ec98158988ca compilable under unix
Claus Gittinger <cg@exept.de>
parents: 1529
diff changeset
   185
ec98158988ca compilable under unix
Claus Gittinger <cg@exept.de>
parents: 1529
diff changeset
   186
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   187
%}
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   188
! !
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   189
511
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   190
!Socket primitiveVariables!
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   191
%{
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   192
static int __debugging__ = 0;
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   193
%}
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   194
! !
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   195
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   196
!Socket primitiveFunctions!
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   197
%{
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   198
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   199
static int
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   200
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
   201
    OBJ aDataBuffer, startIndex;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   202
    char **p_extPtr;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   203
    int *p_offs;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   204
    int *p_objSize;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   205
{
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   206
	char *extPtr = 0;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   207
	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
   208
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   209
	sIdx = 0;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   210
	if (__isSmallInteger(startIndex)) {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   211
	    sIdx = __intVal(startIndex) - 1;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   212
	}
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   213
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   214
	if (__isExternalBytesLike(aDataBuffer)) {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   215
	    OBJ sz;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   216
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   217
	    extPtr = (char *)(__externalBytesAddress(aDataBuffer));
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   218
	    sz = __externalBytesSize(aDataBuffer);
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   219
	    if (__isSmallInteger(sz)) {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   220
		objSize = __intVal(sz);
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   221
	    } else {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   222
		objSize = 0; /* unknown */
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   223
	    }
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   224
	    offs = sIdx;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   225
	} else {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   226
	    OBJ oClass;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   227
	    int nInstVars, nInstBytes;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   228
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   229
	    extPtr = (char *)0;
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   230
	    oClass = __Class(aDataBuffer);
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   231
	    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
   232
		case BYTEARRAY:
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   233
		    offs = sIdx;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   234
		    break;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   235
		case WORDARRAY:
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   236
		case SWORDARRAY:
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   237
		    offs = sIdx * 2;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   238
		    break;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   239
		case LONGARRAY:
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   240
		case SLONGARRAY:
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   241
		    offs = sIdx * 4;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   242
		    break;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   243
		case LONGLONGARRAY:
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   244
		case SLONGLONGARRAY:
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   245
		    offs = sIdx * 8;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   246
# ifdef __NEED_LONGLONG_ALIGN
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   247
		    offs += 4;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   248
# endif
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   249
		    break;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   250
		case FLOATARRAY:
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   251
		    offs = sIdx * sizeof(float);
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   252
		    break;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   253
		case DOUBLEARRAY:
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   254
		    offs = sIdx * sizeof(double);
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   255
# ifdef __NEED_DOUBLE_ALIGN
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   256
		    offs += 4;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   257
# endif
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   258
		    break;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   259
		default:
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   260
		    *p_objSize = -1;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   261
		    return 0;
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   262
	    }
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   263
	    nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   264
	    nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ);
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   265
	    offs = offs + nInstBytes;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   266
	    objSize = _Size(aDataBuffer) - offs;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   267
	}
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   268
	*p_extPtr = extPtr;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   269
	*p_objSize = objSize;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   270
	*p_offs = offs;
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   271
	return 1;
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   272
}
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   273
%}
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   274
! !
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   275
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
   276
!Socket class methodsFor:'documentation'!
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   277
31
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   278
copyright
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   279
"
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   280
 COPYRIGHT (c) 1992 by Claus Gittinger
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   281
	      All Rights Reserved
31
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   282
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   283
 This software is furnished under a license and may be used
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   284
 only in accordance with the terms of that license and with the
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   285
 inclusion of the above copyright notice.   This software may not
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   286
 be provided or otherwise made available to, or used by, any
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   287
 other person.  No title to or ownership of the software is
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   288
 hereby transferred.
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   289
"
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   290
!
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   291
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   292
documentation
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   293
"
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
   294
    This class provides access to sockets for interprocess communication.
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   295
    The message protocol is preliminary, until someone tells me how
31
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   296
    other smalltalk's socket interfaces look like.
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   297
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
   298
    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
   299
    tested and supported.
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   300
    Code for appletalk is included, but was never tested ...
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   301
    More may be added in the future.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   302
    (the code is prepared for things like SNA or decNet;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   303
     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
   304
     Implementing those is pretty straight forward, once the address
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   305
     data structures are known.)
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
   306
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   307
    Due to historic reasons (I started this class, before I got hold of some
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   308
    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
   309
    still provided.
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
   310
    This will vanish; use the #family:type: or #newTCPxxx and #newUDPxxx interfaces,
71
claus
parents: 63
diff changeset
   311
    together with the bind/listen and accept calls,
claus
parents: 63
diff changeset
   312
    which are meant to be compatible to ST-80's UnixSocketAccessor interface.
claus
parents: 63
diff changeset
   313
claus
parents: 63
diff changeset
   314
    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
   315
	  (mhmh - how can I test those ?)
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
   316
	  change to raise more signals on errors.
529
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   317
	  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
   318
		 net please test this (and send bug fixes ...)
259
6d36f3ac42a2 documentation
Claus Gittinger <cg@exept.de>
parents: 220
diff changeset
   319
6d36f3ac42a2 documentation
Claus Gittinger <cg@exept.de>
parents: 220
diff changeset
   320
    [author:]
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   321
	Claus Gittinger
48
18b9353c9d07 *** empty log message ***
claus
parents: 44
diff changeset
   322
"
18b9353c9d07 *** empty log message ***
claus
parents: 44
diff changeset
   323
!
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   324
48
18b9353c9d07 *** empty log message ***
claus
parents: 44
diff changeset
   325
examples
18b9353c9d07 *** empty log message ***
claus
parents: 44
diff changeset
   326
"
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   327
    example (get help info from an nntp server):
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   328
									[exBegin]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   329
	|sock host|
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   330
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   331
	host := OperatingSystem getEnvironment:'NNTPSERVER'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   332
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   333
	sock := Socket newTCPclientToHost:host port:'nntp'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   334
	Transcript showCR:sock nextLine.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   335
	sock buffered:false.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   336
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   337
	sock nextPutAll:'HELP'; cr.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   338
	[:exit |
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   339
	    |line|
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   340
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   341
	    line := sock nextLine.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   342
	    line = '.' ifTrue:[exit value:nil].
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   343
	    Transcript showCR:line.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   344
	] loopWithExit.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   345
	sock close
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   346
									[exEnd]
209
2152fceba563 finger example
Claus Gittinger <cg@exept.de>
parents: 208
diff changeset
   347
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   348
209
2152fceba563 finger example
Claus Gittinger <cg@exept.de>
parents: 208
diff changeset
   349
    example (connect to finger daemon, get users entry):
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   350
									[exBegin]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   351
	|sock host entry|
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   352
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   353
	host := OperatingSystem getHostName.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   354
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   355
	sock := Socket newTCPclientToHost:host port:'finger'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   356
	sock isNil ifTrue:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   357
	    self warn:'no finger daemon is running'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   358
	    ^ self
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   359
	].
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   360
	sock useCRLF:true.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   361
	sock buffered:false.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   362
	sock isNil ifTrue:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   363
	    Transcript showCR:'cannot connect to local finger daemon'
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   364
	] ifFalse:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   365
	    sock nextPutAll:(OperatingSystem getLoginName).
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   366
	    sock cr.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   367
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   368
	    entry := sock nextLine.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   369
	    Transcript showCR:entry.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   370
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   371
	    sock close
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   372
	]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   373
									[exEnd]
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   374
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   375
    example (connect to an ftp server):
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   376
									[exBegin]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   377
	|sock host|
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   378
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   379
	host := OperatingSystem getHostName.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   380
	sock := Socket newTCPclientToHost:host port:'ftp'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   381
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   382
	sock buffered:false.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   383
	Transcript showCR:sock nextLine.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   384
	sock nextPutAll:('USER ' , 'anonymous'); cr.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   385
	Transcript showCR:sock nextLine.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   386
	sock nextPutAll:('PASS ' , 'fooBar'); cr.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   387
	Transcript showCR:sock nextLine.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   388
	sock nextPutAll:'LIST'; cr.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   389
	Transcript showCR:sock nextLine.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   390
	sock close.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   391
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   392
	'dont know enough of the ftp protocol to continue here ...'
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   393
									[exEnd]
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   394
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   395
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
   396
    example (connect to an snmp server [UDP]):
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   397
									[exBegin]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   398
	|sock port|
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   399
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   400
	sock := Socket newUDP.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   401
	port := Socket portOfService:'snmp'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   402
	sock connectTo:(OperatingSystem getHostName) port:port.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   403
	sock buffered:false.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   404
	Transcript showCR:'got it'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   405
	sock close.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   406
									[exEnd]
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   407
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   408
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   409
    example (await connection from a client and read some data):
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   410
									[exBegin]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   411
	|connectSock sock|
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   412
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   413
	connectSock := Socket newTCPserverAtPort:9998.
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   414
	connectSock isNil ifTrue:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   415
	    Transcript showCR:'socket setup failed.'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   416
	] ifFalse:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   417
	    Transcript showCR:'listen ..'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   418
	    (connectSock listenFor:5) ifFalse:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   419
		Transcript showCR:'listen failed.'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   420
	    ] ifTrue:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   421
		Transcript showCR:'wait'.
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   422
		connectSock readWait.
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   423
		Transcript showCR:'accept'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   424
		sock := connectSock accept.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   425
		sock isNil ifTrue:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   426
		    Transcript showCR:'accept failed.'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   427
		] ifFalse:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   428
		    sock buffered:false.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   429
		    Transcript showCR:'server: got it'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   430
		    'can now do transfer via sock'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   431
		    Transcript showCR:'read'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   432
		    Transcript showCR:('got: ' , sock nextLine).
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   433
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   434
		    Transcript showCR:'close'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   435
		    sock close
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   436
		].
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   437
		connectSock close.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   438
	    ]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   439
	]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   440
									[exEnd]
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   441
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   442
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   443
    example (connect to above server and send some data):
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   444
									[exBegin]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   445
	|sock|
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   446
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   447
	sock := Socket newTCPclientToHost:(OperatingSystem getHostName) port:9998.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   448
	sock isNil ifTrue:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   449
	    Transcript showCR:'nope'
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   450
	] ifFalse:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   451
	    sock buffered:false.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   452
	    Transcript showCR:'client: got it'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   453
	    'can now do transfer via sock'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   454
	    Transcript showCR:'sending <hello>'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   455
	    sock nextPutLine:'hello'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   456
	    sock close
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   457
	]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   458
									[exEnd]
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
   459
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
   460
    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
   461
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   462
	|connectSock sock|
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   463
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   464
	'/tmp/ud_socket' asFilename remove.
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   465
	connectSock := Socket newUNIXserverAt:'/tmp/ud_socket'.
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   466
	connectSock isNil ifTrue:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   467
	    Transcript showCR:'socket setup failed.'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   468
	] ifFalse:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   469
	    Transcript showCR:'listen ..'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   470
	    (connectSock listenFor:5) ifFalse:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   471
		Transcript showCR:'listen failed.'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   472
	    ] ifTrue:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   473
		Transcript showCR:'wait'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   474
		connectSock buffered:false.
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   475
		connectSock readWait.
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   476
		Transcript showCR:'accept'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   477
		sock := connectSock accept.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   478
		sock isNil ifTrue:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   479
		    Transcript showCR:'accept failed.'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   480
		] ifFalse:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   481
		    sock buffered:false.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   482
		    Transcript showCR:'server: got it'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   483
		    'can now do transfer via sock'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   484
		    Transcript showCR:'read'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   485
		    Transcript showCR:('got: ' , sock nextLine).
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   486
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   487
		    Transcript showCR:'close'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   488
		    sock close
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   489
		].
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   490
		connectSock close.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   491
	    ]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   492
	]
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
   493
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
   494
118
142d5c273454 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 117
diff changeset
   495
    example (connect to above server and send some data;
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   496
	     Notice, this fails, if above server code is executed in the same ST/X image
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   497
		     (at least on LINUX), since the OS does not correctly handle
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   498
		     a connect from within an interrupted accept system call
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   499
		     On SGI's SVR4, this works ok
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   500
									[exBegin]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   501
	|sock|
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   502
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   503
	sock := Socket newUNIXclientTo:'/tmp/ud_socket'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   504
	sock isNil ifTrue:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   505
	    Transcript showCR:'nope'
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   506
	] ifFalse:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   507
	    sock buffered:false.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   508
	    Transcript showCR:'client: got it'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   509
	    'can now do transfer via sock'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   510
	    Transcript showCR:'sending <hello>'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   511
	    sock nextPutLine:'hello'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   512
	    sock close
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   513
	]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   514
									[exEnd]
1007
5267b5738779 UDP examples
Claus Gittinger <cg@exept.de>
parents: 1004
diff changeset
   515
5267b5738779 UDP examples
Claus Gittinger <cg@exept.de>
parents: 1004
diff changeset
   516
5267b5738779 UDP examples
Claus Gittinger <cg@exept.de>
parents: 1004
diff changeset
   517
    example (UDP await packet from a client and read some data):
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   518
									[exBegin]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   519
	|udpSock sock addr n dataBuffer|
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   520
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   521
	udpSock := Socket newUDPserverAtPort:9999.
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   522
	udpSock isNil ifTrue:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   523
	    Transcript showCR:'socket setup failed.'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   524
	] ifFalse:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   525
	    Transcript showCR:'wait'.
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   526
	    udpSock readWait.
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   527
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   528
	    addr := IPSocketAddress new.
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   529
	    dataBuffer := ByteArray new:1000.
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   530
	    n := udpSock receiveFrom:addr buffer:dataBuffer start:1 for:dataBuffer size.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   531
	    n > 0 ifTrue:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   532
		Transcript showCR:('got: ' , n printString , 'bytes  from ' , addr printString).
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   533
		Transcript showCR:('data: ' , (dataBuffer copyTo:n) printString).
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   534
	    ] ifFalse:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   535
		Transcript showCR:'read failed'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   536
	    ].
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   537
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   538
	    Transcript showCR:'close'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   539
	    udpSock close
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   540
	]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   541
									[exEnd]
1007
5267b5738779 UDP examples
Claus Gittinger <cg@exept.de>
parents: 1004
diff changeset
   542
    example (connect to above UDP server and send some data;
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   543
									[exBegin]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   544
	|sock|
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   545
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   546
	sock := Socket newUDP.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   547
	sock isNil ifTrue:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   548
	    Transcript showCR:'nope'
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   549
	] ifFalse:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   550
	    sock sendTo:(IPSocketAddress new hostName:'localhost' port:9999) buffer:'hello world'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   551
	    sock close
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   552
	]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   553
									[exEnd]
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   554
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   555
    example: pingWalk (try to ping hosts on the local network)
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   556
									[exBegin]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   557
	|myName myAddress list top hosts walkProcess port|
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   558
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   559
	myName := OperatingSystem getHostName.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   560
	myAddress := Socket ipAddressOfHost:myName.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   561
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   562
	port := Socket portOfService:'echo'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   563
	port isNil ifTrue:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   564
	    self error:'dont know echo port'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   565
	    ^ self
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   566
	].
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   567
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   568
	top := StandardSystemView new.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   569
	top label:'PING net walk'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   570
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   571
	list := ScrollableView for:ListView in:top.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   572
	list origin:0.0@0.0 corner:1.0@1.0.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   573
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   574
	top openAndWait.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   575
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   576
	walkProcess := [
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   577
	    |l low hi direction tryHostID dottedName hostName conn addr|
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   578
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   579
	    l := SortedCollection new.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   580
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   581
	    ' only works with type C-net
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   582
	      the code below could simply do 1 to:254 do:[:hostID }
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   583
	      but, to probe likely hosts earlier, the probing is done
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   584
	      ping-pong like around my ip-address (assuming, that other machines
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   585
	      have numbers around my own)'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   586
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   587
	    low := hi := (myAddress at:4).
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   588
	    direction := 1.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   589
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   590
	    [low > 0 or:[hi < 255]] whileTrue:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   591
		direction > 0 ifTrue:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   592
		    hi := hi + 1.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   593
		    tryHostID := hi.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   594
		    direction := -1.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   595
		] ifFalse:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   596
		    low := low - 1.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   597
		    tryHostID := low.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   598
		    direction := 1.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   599
		].
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   600
		(tryHostID between:1 and:254) ifTrue:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   601
		    dottedName := (myAddress at:1) printString
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   602
				  , '.' , (myAddress at:2) printString
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   603
				  , '.' , (myAddress at:3) printString
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   604
				  , '.' , tryHostID printString.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   605
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   606
		    top label:'PING net walk - trying ' , dottedName.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   607
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   608
		    top windowGroup withCursor:Cursor wait do:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   609
			conn := Socket newTCPclientToHost:dottedName port:port withTimeout:1000.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   610
			conn notNil ifTrue:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   611
			    addr := Socket ipAddressOfHost:dottedName.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   612
			    hostName := Socket hostWithIpAddress:addr.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   613
			    hostName isNil ifTrue:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   614
				hostName :='?'
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   615
			    ].
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   616
			    l add:(dottedName paddedTo:15 with:Character space)
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   617
				   , ' '
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   618
				   , (hostName paddedTo:15 with:Character space)
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   619
				   , ' up & reachable'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   620
			    list list:l.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   621
			    conn close.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   622
			]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   623
		    ].
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   624
		].
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   625
	    ].
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   626
	    top label:'PING reachable hosts'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   627
	] forkAt:(Processor userBackgroundPriority).
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   628
	walkProcess name:'ping net walker'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   629
									[exEnd]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   630
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   631
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   632
	This example creates a simple UDP server that accepts
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   633
	single packets from anybody and broadcasts them to all
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   634
	clients that have connected so far.
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   635
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   636
									[exBegin]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   637
	| socket address buffer msgSize clients |
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   638
	clients := Set new.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   639
	address := IPSocketAddress new.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   640
	buffer := String new: 1024.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   641
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   642
	socket := self newUDPserverAtPort: 6666.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   643
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   644
	Transcript showCR: 'server starting'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   645
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   646
	[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   647
	    [true] whileTrue: [
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   648
		(socket readWaitWithTimeoutMs: 200) ifFalse: [
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   649
		    msgSize := socket
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   650
			    receiveFrom: address
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   651
			    buffer: buffer
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   652
			    start: 1
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   653
			    for: buffer size.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   654
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   655
		    clients add: address copy.
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   656
		    clients do: [ :clientAddress |
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   657
			    socket
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   658
				    sendTo: clientAddress
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   659
				    buffer: buffer
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   660
				    start: 1
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   661
				    for: msgSize]]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   662
	    ]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   663
	] valueNowOrOnUnwindDo:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   664
	    Transcript showCR: 'server shutting down'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   665
	    socket close
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   666
	]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   667
									[exEnd]
817
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
   668
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
   669
   send a datagram to above server:
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   670
									[exBegin]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   671
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   672
	| socket address buffer host msg |
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   673
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   674
	host := Dialog
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   675
		request: 'What is the name of the server''s host?'
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   676
		initialAnswer: 'localhost'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   677
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   678
	socket := self newUDP.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   679
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   680
	address := IPSocketAddress hostName: host port: 6666.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   681
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   682
	buffer := ByteArray new: 1000.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   683
	[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   684
	    [(msg := Dialog request: 'Say something') isEmpty] whileFalse:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   685
		| replySize stream |
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   686
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   687
		socket writeWait.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   688
		stream := buffer writeStream.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   689
		stream nextPutAll: msg.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   690
		socket sendTo:address buffer:buffer start:1 for:stream position.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   691
		socket readWait.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   692
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   693
		replySize := socket receiveFrom:address buffer:buffer.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   694
		replySize > 0 ifTrue: [
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   695
		    Transcript cr; nextPutAll: 'Server acknowledged: '.
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   696
		    Transcript show: ((buffer copyFrom: 1 to: replySize) asString)
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   697
		]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   698
	    ]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   699
	] valueNowOrOnUnwindDo: [socket close].
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   700
	Transcript cr
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   701
									[exEnd]
1316
ffe05bfee9b5 example
Claus Gittinger <cg@exept.de>
parents: 1313
diff changeset
   702
ffe05bfee9b5 example
Claus Gittinger <cg@exept.de>
parents: 1313
diff changeset
   703
ffe05bfee9b5 example
Claus Gittinger <cg@exept.de>
parents: 1313
diff changeset
   704
   loopBack:
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   705
									[exBegin]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   706
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   707
	|readerTask readingSocket writingSocket|
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   708
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   709
	readingSocket := self newTCPserverAtPort:9999.
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   710
	readerTask :=
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   711
	    [
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   712
		|connection|
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   713
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   714
		readingSocket listenFor:1.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   715
		connection := readingSocket accept.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   716
		readingSocket close.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   717
		[connection atEnd] whileFalse:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   718
		    Transcript showCR:(connection nextLine).
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   719
		].
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   720
		connection close.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   721
	    ] fork.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   722
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   723
	Delay waitForSeconds:1.
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   724
	writingSocket := self newTCPclientToHost:(OperatingSystem getHostName) port:9999.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   725
	writingSocket nextPutLine:'Hello'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   726
	writingSocket nextPutLine:'World'.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   727
	writingSocket close.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
   728
									[exEnd]
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   729
"
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   730
! !
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   731
1462
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   732
!Socket class methodsFor:'instance creation'!
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   733
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   734
domain:domainSymbol type:type
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   735
    "create a socket for domain and type -
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   736
     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
   737
     Domain must be one of the symbols:
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   738
	#inet, #unix, #appletalk, #decnet, #xns, ...;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   739
     Type must be:
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   740
	#stream, #datagram or #raw
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   741
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   742
     XXX: currently only the #inet domain is supported"
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
    ^ self new domain:domainSymbol type:type
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   745
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   746
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   747
     Socket domain:#inet type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   748
     Socket domain:#inet type:#datagram
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   749
     Socket domain:#unix type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   750
     Socket domain:#appletalk type:#stream
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   751
     Socket domain:#decnet type:#stream
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
   752
     Socket domain:#irda type:#stream
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   753
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   754
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   755
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   756
new
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   757
    "create a TCP socket"
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   758
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   759
    ^ super new buffered:false
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   760
!
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   761
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   762
newTCP
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   763
    "create a TCP socket - no binding or other setup is done,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   764
     neither connect nor connect-wait is done."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   765
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   766
    ^ self new domain:#inet type:#stream
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   767
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   768
    "Socket newUDP"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   769
!
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
newTCP:aServiceOrNil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   772
    "create a TCP socket for a service -
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   773
     neither connect nor connect-wait is done."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   774
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   775
    |newSock|
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
    newSock := self newTCP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   778
    (newSock notNil and:[aServiceOrNil notNil]) ifTrue:[
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   779
	^ newSock tryToBindTo:(self portOfService:aServiceOrNil)
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   780
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   781
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   782
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   783
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   784
    "Socket newTCP:'nntp'"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   785
    "Socket newTCP:9995"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   786
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   787
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   788
newTCPclientToAddress:aHostAddress port:aService
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   789
    "create a new TCP client socket connecting to a service.
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   790
     Return a socket instance if ok, nil on failure.
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   791
     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
   792
     not the whole smalltalk).
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   793
     See also: #newTCPclientToAddress:port:withTimeout:"
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   794
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   795
    ^ self newTCPclientToAddress:aHostAddress port:aService withTimeout:nil
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   796
!
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   797
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   798
newTCPclientToAddress:aHostAddress port:aService withTimeout:millis
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   799
    "create a new TCP client socket connecting to a service.
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   800
     Return a socket instance if ok, nil on failure.
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   801
     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
   802
     and return nil."
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   803
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   804
    ^ self newTCPclientToHost:aHostAddress port:aService withTimeout:millis
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   805
!
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   806
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   807
newTCPclientToHost:hostname port:aService
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   808
    "create a new TCP client socket connecting to a service.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   809
     Return a socket instance if ok, nil on failure.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   810
     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
   811
     not the whole smalltalk).
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   812
     See also: #newTCPclientToHost:port:withTimeout:"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   813
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   814
    ^ self newTCPclientToHost:hostname port:aService withTimeout:nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   815
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   816
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   817
      Socket newTCPclientToHost:'localhost' port:'nntp'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   818
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   819
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   820
    "Created: 31.10.1995 / 18:54:11 / cg"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   821
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   822
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   823
newTCPclientToHost:hostname port:aService withTimeout:millis
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   824
    "create a new TCP client socket connecting to a service.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   825
     Return a socket instance if ok, nil on failure.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   826
     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
   827
     and return nil.."
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
    |newSock|
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
    newSock := self newTCP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   832
    newSock notNil ifTrue:[
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   833
	(newSock connectTo:hostname
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   834
		 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
   835
		 withTimeout:millis
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   836
	) ifFalse:[
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   837
	    newSock close.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   838
	    ^ nil
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   839
	]
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   840
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   841
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   842
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   843
same as:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   844
    ^ (self new) for:hostname port:(self portOfService:aPort).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   845
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   846
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   847
      Socket newTCPclientToHost:'slsv6bt' port:'nntp'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   848
      Socket newTCPclientToHost:'localhost' port:'nntp' withTimeout:1000
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   849
    "
604
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
   850
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
   851
    "Modified: / 16.1.1998 / 09:47:06 / stefan"
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   852
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   853
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   854
newTCPserverAtAnonymousPort
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   855
    "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
   856
     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
   857
811
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   858
    ^ self newTCPserverAtPort:0
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   859
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   860
!
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   861
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   862
newTCPserverAtPort:aService
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   863
    "create a new TCP server socket providing service."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   864
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   865
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   866
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   867
    newSock := self newTCP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   868
    newSock notNil ifTrue:[
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   869
	^ newSock tryToBindTo:(self portOfService:aService)
126
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
    ^ newSock
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
newUDP
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   875
    "create a UDP socket - no binding or other setup is done,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   876
     neither connect nor connect-wait is done."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   877
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   878
    ^ self new domain:#inet type:#datagram
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   879
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   880
    "Socket newUDP"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   881
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   882
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   883
newUDP:aServiceOrNil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   884
    "create a UDP socket for a service -
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   885
     neither connect nor connect-wait is done."
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
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   888
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   889
    newSock := self newUDP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   890
    (newSock notNil and:[aServiceOrNil notNil]) ifTrue:[
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   891
	^ newSock tryToBindTo:(self portOfService:aServiceOrNil)
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   892
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   893
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   894
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   895
    "Socket newUDP:nil"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   896
!
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
newUDPserverAtPort:aService
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   899
    "create a new UDP server socket providing service."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   900
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   901
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   902
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   903
    newSock := self newUDP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   904
    newSock notNil ifTrue:[
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   905
	^ newSock tryToBindTo:(self portOfService:aService)
126
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
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   908
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   909
same as:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   910
    ^ (self new) for:nil udpPort:aPort
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
newUNIX
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   915
    "create a UNIX domain socket - no binding or other setup is done,
811
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   916
     neither connect nor connect-wait is done.
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   917
     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
   918
     return nil."
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   919
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   920
    ^ self new domain:#unix type:#stream
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   921
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   922
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   923
     Socket newUNIX
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   924
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   925
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   926
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   927
newUNIXclientTo:pathName
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   928
    "create a new UNIX client socket connecting to a pathname.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   929
     Return a socket instance if ok, nil on failure.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   930
     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
   931
     not the whole smalltalk).
811
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   932
     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
   933
     return nil.
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   934
     See also: #newUNIXclientTo:withTimeout:"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   935
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   936
    ^ self newUNIXclientTo:pathName withTimeout:nil
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
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   940
newUNIXclientTo:pathName withTimeout:millis
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   941
    "create a new UNIX client socket connecting to a pathname.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   942
     Return a socket instance if ok, nil on failure.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   943
     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
   944
     and return nil.
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   945
     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
   946
     return nil."
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   947
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   948
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   949
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   950
    newSock := self newUNIX.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   951
    newSock notNil ifTrue:[
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   952
	(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
   953
	    newSock close.
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   954
	    ^ nil
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
   955
	]
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   956
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   957
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   958
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   959
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   960
     |s|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   961
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   962
     s := Socket newUNIXclientTo:'/tmp/foo'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   963
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   964
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   965
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   966
newUNIXserverAt:pathName
811
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   967
    "create a new UNIX server socket providing service at a pathname.
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   968
     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
   969
     return nil."
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   970
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   971
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   972
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   973
    newSock := self newUNIX.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   974
    newSock notNil ifTrue:[
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
   975
	^ newSock tryToBindTo:pathName
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   976
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   977
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   978
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   979
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   980
     |s s2|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   981
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   982
     s := Socket newUNIXserverAt:'/tmp/foo'.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   983
     s listenFor:5.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   984
     s2 := s accept.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   985
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   986
! !
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   987
1462
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   988
!Socket class methodsFor:'Compatibility-ST80'!
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
family:domainSymbol type:typeSymbol
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   991
    "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
   992
     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
   993
     Type must be #stream, #datagram or #raw."
1462
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   994
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   995
    ^ self domain:domainSymbol type:typeSymbol
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   996
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   997
    "
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   998
     Socket family:#inet type:#stream
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
   999
     Socket family:#inet type:#datagram
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1000
     Socket family:#unix type:#stream
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
!
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
getHostname
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1005
    "return the computers hostname string"
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1006
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1007
    ^ OperatingSystem getHostName
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1008
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1009
    "Created: / 27.2.1998 / 02:32:17 / cg"
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
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1012
sockStream
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1013
    "return the type code for stream sockets"
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1014
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1015
    ^ #stream
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1016
! !
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
!Socket class methodsFor:'Compatibility-VW'!
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1019
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1020
AF_INET
1462
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1021
    ^ #AF_INET
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
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1024
SOCK_STREAM
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1025
    ^ #SOCK_STREAM
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
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1028
!Socket class methodsFor:'Signal constants'!
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1029
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1030
brokenConnectionSignal
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1031
    "return the signal used to tell broken connections.
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1032
     Since in unix, this is the same as the broken pipe signal,
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1033
     return that one.
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1034
     (for other Operatingsystems, this may change ..)"
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1035
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1036
    ^ PipeStream brokenPipeSignal
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1037
!
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1038
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1039
invalidArgumentsSignal
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1040
    "dummy for compatibility"
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1041
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1042
    ^ self errorSignal
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1043
! !
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1044
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1045
!Socket class methodsFor:'debugging'!
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1046
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1047
debug:aBoolean
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1048
    "turn on/off internal debugprints.
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1049
     This method is for ST/X debugging only and
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1050
     may  be removed in later versions"
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1051
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1052
%{  /* NOCONTEXT */
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1053
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1054
    __debugging__ = (aBoolean == true);
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1055
%}
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1056
    "
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1057
     Socket debug:true
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1058
     Socket debug:false
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1059
    "
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1060
! !
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1061
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1062
!Socket class methodsFor:'host queries'!
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1063
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1064
appletalkAddressOfHost:aHostName
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1065
    "return the APPLETALK address for a hostname as a byteArray,
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1066
     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
  1067
     followed by the node byte.
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1068
     If the host is unknown, return nil.
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1069
     This is the reverse operation to #hostWithAppletalkAddress:.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1070
     WARNING: untested code - I have no appletalk to test this."
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1071
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1072
    NameLookupError
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1073
	handle:[:ex |
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1074
	    ^ nil
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1075
	]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1076
	do:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1077
	    ^ (AppletalkSocketAddress hostName:aHostName) address
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1078
	]
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1079
!
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1080
1278
7251c65b8d38 use nameLookup from SocketAddress for all addr-families
Claus Gittinger <cg@exept.de>
parents: 1274
diff changeset
  1081
hostWithAppletalkAddress:addrByteArray
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1082
    "return the hostname for an APPLETALK address.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1083
     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
  1084
     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
  1085
     The last byte is the node number.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1086
     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
  1087
     This is is the reverse operation to #appletalkAddressOfHost:.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1088
     WARNING: untested code - I have no appletalk to test this."
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1089
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1090
    NameLookupError
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1091
	handle:[:ex |
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1092
	    ^ nil
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1093
	]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1094
	do:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1095
	    ^ (AppletalkSocketAddress hostAddress:addrByteArray) hostName
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1096
	]
1278
7251c65b8d38 use nameLookup from SocketAddress for all addr-families
Claus Gittinger <cg@exept.de>
parents: 1274
diff changeset
  1097
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1098
    "
1278
7251c65b8d38 use nameLookup from SocketAddress for all addr-families
Claus Gittinger <cg@exept.de>
parents: 1274
diff changeset
  1099
     Socket appletalkAddressOfHost:'yourAppleHere'
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1100
     Socket hostWithAppletalkAddress:#[1 2 3]
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1101
     "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1102
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1103
1278
7251c65b8d38 use nameLookup from SocketAddress for all addr-families
Claus Gittinger <cg@exept.de>
parents: 1274
diff changeset
  1104
hostWithIpAddress:addrByteArray
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1105
    "return the hostname for an IP (internet-) address.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1106
     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
  1107
     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
  1108
     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
  1109
     This is the reverse operation to #ipAddressOfHost:."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1110
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1111
    NameLookupError
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1112
	handle:[:ex |
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1113
	    ^ nil
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1114
	]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1115
	do:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1116
	    ^ (IPSocketAddress hostAddress:addrByteArray) hostName
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1117
	]
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1118
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1119
    "
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1120
     Socket ipAddressOfHost:'clam'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1121
     Socket hostWithIpAddress:(Socket ipAddressOfHost:'clam')
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1122
     Socket ipAddressOfHost:'porty'
1278
7251c65b8d38 use nameLookup from SocketAddress for all addr-families
Claus Gittinger <cg@exept.de>
parents: 1274
diff changeset
  1123
     Socket hostWithIpAddress:(Socket ipAddressOfHost:'porty')
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1124
     Socket hostWithIpAddress:#[1 2 3 4]
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1125
     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
  1126
     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
  1127
     Socket hostWithIpAddress:(Socket ipAddressOfHost:'www.altavista.com')
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1128
     "
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
hostWithIpV6Address:addrByteArray
820
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1132
    "return the hostname for an IPv6 (internet-) address.
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1133
     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
  1134
     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
  1135
     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
  1136
     This is the reverse operation to #ipV6AddressOfHost:."
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1137
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1138
    NameLookupError
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1139
	handle:[:ex |
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1140
	    ^ nil
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1141
	]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1142
	do:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1143
	    ^ (IPv6SocketAddress hostAddress:addrByteArray) hostName
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1144
	]
820
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1145
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1146
    "
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1147
     Socket ipV6AddressOfHost:'clam'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1148
     Socket hostWithIpV6Address:(Socket ipAddressOfHost:'clam')
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1149
     Socket ipV6AddressOfHost:'porty'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1150
     Socket hostWithIpV6Address:(Socket ipAddressOfHost:'porty')
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1151
     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
  1152
     Socket ipV6AddressOfHost:'www.exept.de'
820
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1153
     "
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1154
!
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1155
6
claus
parents: 4
diff changeset
  1156
ipAddressOfHost:aHostName
98
5e787ba2cb31 use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
  1157
    "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
  1158
     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
  1159
     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
  1160
     This is the reverse operation to #hostWithIpAddress:."
6
claus
parents: 4
diff changeset
  1161
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1162
    NameLookupError
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1163
	handle:[:ex |
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1164
	    ^ nil
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1165
	]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1166
	do:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1167
	    ^ (IPSocketAddress hostName:aHostName) address
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1168
	]
21
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1169
71
claus
parents: 63
diff changeset
  1170
    "
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1171
     Socket ipAddressOfHost:'localhost'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1172
     Socket ipAddressOfHost:'exept'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1173
     Socket ipAddressOfHost:'1.2.3.4'
1274
f257a1b16b4d use naemLookup from SocketAddress for ipv6
Claus Gittinger <cg@exept.de>
parents: 1263
diff changeset
  1174
     Socket ipAddressOfHost:'193.15.16.17'
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1175
     Socket ipAddressOfHost:'josef'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1176
     Socket ipAddressOfHost:'styx.com'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1177
     Socket hostWithIpAddress:(Socket ipAddressOfHost:'localhost')
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1178
     Socket ipAddressOfHost:(Socket hostWithIpAddress:'127.0.0.1')
71
claus
parents: 63
diff changeset
  1179
    "
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1180
!
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1181
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1182
ipV6AddressOfHost:aHostName
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1183
    "return the IPv6 (internet-) number for a hostname as a byteArray,
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1184
     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
  1185
     If the host is unknown, return nil.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1186
     This is the reverse operation to #hostWithIpV6Address:."
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1187
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1188
    NameLookupError
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1189
	handle:[:ex |
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1190
	    ^ nil
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1191
	]
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1192
	do:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1193
	    ^ (IPv6SocketAddress hostName:aHostName) address
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1194
	]
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1195
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1196
    "
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1197
     Socket ipV6AddressOfHost:'localhost'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1198
     Socket ipV6AddressOfHost:'exept'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1199
     Socket ipV6AddressOfHost:'exept.exept.de'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1200
     Socket ipV6AddressOfHost:'www.google.de'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1201
     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
  1202
     Socket ipV6AddressOfHost:'josef'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1203
     Socket ipV6AddressOfHost:'styx.com'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1204
     Socket hostWithIpV6Address:(Socket ipV6AddressOfHost:'localhost')
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1205
     Socket ipV6AddressOfHost:(Socket hostV6WithIpAddress:'127.0.0.1')
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1206
    "
531
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1207
! !
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1208
1209
e7c98932cb0d mark obsolete messages
Stefan Vogel <sv@exept.de>
parents: 1202
diff changeset
  1209
!Socket class methodsFor:'obsolete'!
e7c98932cb0d mark obsolete messages
Stefan Vogel <sv@exept.de>
parents: 1202
diff changeset
  1210
e7c98932cb0d mark obsolete messages
Stefan Vogel <sv@exept.de>
parents: 1202
diff changeset
  1211
connectTo:service on:host
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1212
    "standard & easy client setup:
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1213
	create new client tcp socket, bind and connect;
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1214
	return the socket.
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1215
     The thread blocks (interruptable), until the connection is established."
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  1216
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  1217
    ^ self newTCPclientToHost:host port:(self portOfService:service).
1209
e7c98932cb0d mark obsolete messages
Stefan Vogel <sv@exept.de>
parents: 1202
diff changeset
  1218
e7c98932cb0d mark obsolete messages
Stefan Vogel <sv@exept.de>
parents: 1202
diff changeset
  1219
    "
e7c98932cb0d mark obsolete messages
Stefan Vogel <sv@exept.de>
parents: 1202
diff changeset
  1220
     Socket connectTo:9995 on:'clam'
e7c98932cb0d mark obsolete messages
Stefan Vogel <sv@exept.de>
parents: 1202
diff changeset
  1221
     Socket connectTo:4711 on:'exept'
e7c98932cb0d mark obsolete messages
Stefan Vogel <sv@exept.de>
parents: 1202
diff changeset
  1222
     Socket connectTo:'finger' on:'clam'
e7c98932cb0d mark obsolete messages
Stefan Vogel <sv@exept.de>
parents: 1202
diff changeset
  1223
     Socket connectTo:'ftp' on:'exept'
e7c98932cb0d mark obsolete messages
Stefan Vogel <sv@exept.de>
parents: 1202
diff changeset
  1224
     Socket connectTo:'nntp' on:(OperatingSystem getEnvironment:'NNTPSERVER')
e7c98932cb0d mark obsolete messages
Stefan Vogel <sv@exept.de>
parents: 1202
diff changeset
  1225
    "
e7c98932cb0d mark obsolete messages
Stefan Vogel <sv@exept.de>
parents: 1202
diff changeset
  1226
!
e7c98932cb0d mark obsolete messages
Stefan Vogel <sv@exept.de>
parents: 1202
diff changeset
  1227
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  1228
provide:aService
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1229
    "standard & easy server setup:
1209
e7c98932cb0d mark obsolete messages
Stefan Vogel <sv@exept.de>
parents: 1202
diff changeset
  1230
     create a new TCP server socket providing a service."
e7c98932cb0d mark obsolete messages
Stefan Vogel <sv@exept.de>
parents: 1202
diff changeset
  1231
e7c98932cb0d mark obsolete messages
Stefan Vogel <sv@exept.de>
parents: 1202
diff changeset
  1232
    <resource:#obsolete>
e7c98932cb0d mark obsolete messages
Stefan Vogel <sv@exept.de>
parents: 1202
diff changeset
  1233
e7c98932cb0d mark obsolete messages
Stefan Vogel <sv@exept.de>
parents: 1202
diff changeset
  1234
    |newSock|
e7c98932cb0d mark obsolete messages
Stefan Vogel <sv@exept.de>
parents: 1202
diff changeset
  1235
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  1236
    self obsoleteMethodWarning:'use newTCPserverAtPort: / listen'.
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  1237
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  1238
    newSock := self newTCPserverAtPort:(self portOfService:aService).
1209
e7c98932cb0d mark obsolete messages
Stefan Vogel <sv@exept.de>
parents: 1202
diff changeset
  1239
    newSock notNil ifTrue:[
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1240
	newSock listenFor:5.
1209
e7c98932cb0d mark obsolete messages
Stefan Vogel <sv@exept.de>
parents: 1202
diff changeset
  1241
    ].
e7c98932cb0d mark obsolete messages
Stefan Vogel <sv@exept.de>
parents: 1202
diff changeset
  1242
    ^ newSock
e7c98932cb0d mark obsolete messages
Stefan Vogel <sv@exept.de>
parents: 1202
diff changeset
  1243
e7c98932cb0d mark obsolete messages
Stefan Vogel <sv@exept.de>
parents: 1202
diff changeset
  1244
    "
e7c98932cb0d mark obsolete messages
Stefan Vogel <sv@exept.de>
parents: 1202
diff changeset
  1245
     Socket provide:9995
e7c98932cb0d mark obsolete messages
Stefan Vogel <sv@exept.de>
parents: 1202
diff changeset
  1246
     (Socket provide:9996) accept
e7c98932cb0d mark obsolete messages
Stefan Vogel <sv@exept.de>
parents: 1202
diff changeset
  1247
     Socket provide:'nntp'
e7c98932cb0d mark obsolete messages
Stefan Vogel <sv@exept.de>
parents: 1202
diff changeset
  1248
    "
e7c98932cb0d mark obsolete messages
Stefan Vogel <sv@exept.de>
parents: 1202
diff changeset
  1249
! !
e7c98932cb0d mark obsolete messages
Stefan Vogel <sv@exept.de>
parents: 1202
diff changeset
  1250
531
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1251
!Socket class methodsFor:'queries'!
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
domainOfProtocol:aProtocol
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1254
    "given a protocols name (i.e. tcp, udp etc) return the domain.
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1255
     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
  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
     tcp/ip stuff
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
    (aProtocol = 'tcp') ifTrue:[^ #inet].
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1261
    (aProtocol = 'udp') ifTrue:[^ #inet].
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1262
    (aProtocol = 'ip')  ifTrue:[^ #inet].
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
     unix domain
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
    (aProtocol = 'ud')  ifTrue:[^ #unix].
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
     add x25 stuff (if any) here ...
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1270
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1271
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1272
     add appletalk stuff (if any) here ...
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1273
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1274
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1275
     add other stuff (if any) here ...
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1276
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1277
    ^ nil
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1278
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1279
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1280
     Socket domainOfProtocol:'tcp'
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1281
     Socket domainOfProtocol:'ucp'
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1282
     Socket domainOfProtocol:(Socket protocolOfService:'nntp')
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1283
     Socket domainOfProtocol:(Socket protocolOfService:'echo')
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1284
    "
6
claus
parents: 4
diff changeset
  1285
!
claus
parents: 4
diff changeset
  1286
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1287
networkLongOrderIsMSB
1558
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  1288
    "return the well known fact, that network byte order is most significant byte first"
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  1289
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  1290
    <resource: #obsolete>
964
a11c607f1a3e checkin from browser
ca
parents: 962
diff changeset
  1291
a11c607f1a3e checkin from browser
ca
parents: 962
diff changeset
  1292
    ^ true
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1293
!
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1294
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1295
networkShortOrderIsMSB
1558
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  1296
    "return the well known fact, that network byte order is most significant byte first"
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  1297
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  1298
    <resource: #obsolete>
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  1299
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  1300
    ^ true
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1301
!
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1302
1260
9a8fb2391174 instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents: 1235
diff changeset
  1303
peerFromDomain:domain name:peerName port:port
9a8fb2391174 instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents: 1235
diff changeset
  1304
    |addrClass|
9a8fb2391174 instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents: 1235
diff changeset
  1305
9a8fb2391174 instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents: 1235
diff changeset
  1306
    addrClass := self socketAddressClassForDomain:domain.
1263
23161346a162 no longer callBack into sockets getHostName/getAddress code.
Claus Gittinger <cg@exept.de>
parents: 1260
diff changeset
  1307
    ^ 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
  1308
!
7e5f2f6b177d getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents: 1186
diff changeset
  1309
7e5f2f6b177d getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents: 1186
diff changeset
  1310
peerNameFromDomain:domain peer:peer
1260
9a8fb2391174 instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents: 1235
diff changeset
  1311
    |addrClass|
9a8fb2391174 instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents: 1235
diff changeset
  1312
9a8fb2391174 instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents: 1235
diff changeset
  1313
    addrClass := self socketAddressClassForDomain:domain.
9a8fb2391174 instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents: 1235
diff changeset
  1314
    ^ 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
  1315
!
7e5f2f6b177d getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents: 1186
diff changeset
  1316
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1317
portOfService:aNameOrNumber
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1318
    "returns the port-number for a given IP-service
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1319
     or nil if no such service exists;
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1320
     - used to convert service names to portNumbers"
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1321
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1322
    ^ self portOfService:aNameOrNumber protocol:nil
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1323
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1324
    "
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1325
     Socket portOfService:'finger'
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1326
     Socket portOfService:'nntp'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1327
     Socket portOfService:'echo'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1328
     Socket portOfService:'snmp'
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1329
    "
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1330
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1331
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1332
portOfService:aNameOrNumber protocol:aProtocol
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1333
    "returns the port-number for a given IP-service
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1334
     or nil if no such service exists;
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1335
     - used to convert service names to portNumbers"
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1336
1499
1ff98f9bc58f Unlimitedstack for some methods which call getXXXByName().
Stefan Vogel <sv@exept.de>
parents: 1486
diff changeset
  1337
%{ /* UNLIMITEDSTACK */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1338
#ifndef NO_SOCKET
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1339
    struct servent *servent = NULL;
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1340
    char *protocol;
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1341
    int tryBoth = 0;
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1342
    short portNo;
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1343
604
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
  1344
    if (__isSmallInteger(aNameOrNumber)) {
1503
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1345
	RETURN ( aNameOrNumber );
92
Claus Gittinger <cg@exept.de>
parents: 91
diff changeset
  1346
    }
Claus Gittinger <cg@exept.de>
parents: 91
diff changeset
  1347
604
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
  1348
    if (__isString(aProtocol)) {
1503
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1349
	protocol = (char *)__stringVal(aProtocol);
604
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
  1350
    } else {
1503
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1351
	protocol = "tcp";
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1352
	tryBoth = 1;
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1353
    }
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1354
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1355
    if (__isString(aNameOrNumber) || __isSymbol(aNameOrNumber)) {
1503
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1356
	servent = getservbyname((char *) __stringVal(aNameOrNumber), protocol);
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1357
	if (servent != NULL) {
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1358
	    RETURN ( __MKSMALLINT(ntohs(servent->s_port)) );
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1359
	}
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1360
	if (tryBoth) {
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1361
	    servent = getservbyname((char *) __stringVal(aNameOrNumber), "udp");
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1362
	    if (servent != NULL) {
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1363
		RETURN ( __MKSMALLINT(ntohs(servent->s_port)) );
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1364
	    }
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1365
	}
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1366
	RETURN ( nil );
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1367
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1368
#endif
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1369
    RETURN ( nil );
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1370
%}
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1371
    "
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1372
     Socket portOfService:'echo' protocol:'udp'
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1373
     Socket portOfService:'echo' protocol:'tcp'
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1374
    "
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1375
!
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1376
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1377
protocolOfService:aNameOrNumber
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1378
    "returns the protocol (as string) for a given IP-service
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1379
     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
  1380
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1381
%{  /* UNLIMITEDSTACK(noWIN32) */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1382
#ifndef NO_SOCKET
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1383
    struct servent *servent = NULL;
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1384
    short portNo;
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1385
58
bd6753bf0401 *** empty log message ***
claus
parents: 51
diff changeset
  1386
    if (__isSmallInteger(aNameOrNumber)) {
1503
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1387
	portNo = __intVal(aNameOrNumber);
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1388
	servent = getservbyport(htons(portNo), "tcp") ;
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1389
	if (servent == NULL) {
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1390
	    servent = getservbyport(htons(portNo), "udp") ;
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1391
	    if (servent == NULL) {
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1392
		RETURN ( nil );
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1393
	    }
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1394
	}
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1395
    } else {
1503
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1396
	if (__isString(aNameOrNumber)) {
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1397
	    servent = getservbyname((char *) __stringVal(aNameOrNumber), "tcp");
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1398
	    if (servent == NULL) {
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1399
		servent = getservbyname((char *) __stringVal(aNameOrNumber), "udp");
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1400
		if (servent == NULL) {
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1401
		    RETURN ( nil );
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1402
		}
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1403
	    }
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1404
	}
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1405
    }
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1406
    if (servent) {
1503
4d97e4191d04 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
  1407
	RETURN ( __MKSTRING(servent->s_proto) );
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1408
    }
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1409
#endif /* !NO_SOCKET */
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1410
    RETURN ( nil );
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1411
%}
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1412
    "
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1413
     Socket protocolOfService:'finger'
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1414
     Socket protocolOfService:'nntp'
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1415
     Socket protocolOfService:'xxx'
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1416
     Socket protocolOfService:79
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1417
     Socket protocolOfService:'snmp'
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1418
    "
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1419
!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1420
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
  1421
socketAddressClassForDomain:domain
1230
2cfb8c270cb5 more functionality moved to SocketAccessor
Claus Gittinger <cg@exept.de>
parents: 1224
diff changeset
  1422
    ^ SocketAddress knownClassFromCode:domain
2cfb8c270cb5 more functionality moved to SocketAccessor
Claus Gittinger <cg@exept.de>
parents: 1224
diff changeset
  1423
2cfb8c270cb5 more functionality moved to SocketAccessor
Claus Gittinger <cg@exept.de>
parents: 1224
diff changeset
  1424
    "
2cfb8c270cb5 more functionality moved to SocketAccessor
Claus Gittinger <cg@exept.de>
parents: 1224
diff changeset
  1425
     self socketAddressClassForDomain:#inet
1260
9a8fb2391174 instance creation of peer refactored
Claus Gittinger <cg@exept.de>
parents: 1235
diff changeset
  1426
     self socketAddressClassForDomain:#unix
1230
2cfb8c270cb5 more functionality moved to SocketAccessor
Claus Gittinger <cg@exept.de>
parents: 1224
diff changeset
  1427
    "
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
  1428
!
7e5f2f6b177d getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents: 1186
diff changeset
  1429
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1430
supportedProtocolFamilies
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1431
    "return a collection of supported protocol families.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1432
     This list specifies what the Socket class supports -
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1433
     socket creation may still fail, if your system was built
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1434
     without it."
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1435
1280
b973855bfe74 moved all socket constant queries from SocketHandle
Claus Gittinger <cg@exept.de>
parents: 1278
diff changeset
  1436
    ^ OperatingSystem supportedProtocolFamilies
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1437
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1438
    "
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1439
     Socket supportedProtocolFamilies
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1440
    "
559
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1441
!
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1442
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1443
typeOfProtocol:aProtocol
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1444
    "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
  1445
     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
  1446
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1447
    (aProtocol = 'tcp') ifTrue:[^ #stream].
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1448
    (aProtocol = 'udp') ifTrue:[^ #datagram].
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1449
    (aProtocol = 'ip')  ifTrue:[^ #raw].
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1450
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1451
     unix domain
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1452
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1453
    (aProtocol = 'ud')  ifTrue:[^ #stream].
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1454
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1455
     add x25 stuff (if any) here ...
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1456
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1457
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1458
     add appletalk stuff (if any) here ...
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1459
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1460
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1461
     add other stuff (if any) here ...
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1462
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1463
    ^ nil
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1464
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1465
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1466
     Socket typeOfProtocol:'tcp'
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1467
     Socket typeOfProtocol:'ucp'
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1468
     Socket typeOfProtocol:(Socket protocolOfService:'nntp')
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1469
     Socket typeOfProtocol:(Socket protocolOfService:'echo')
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1470
    "
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1471
! !
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1472
1202
c52279df60d8 method category rename
Claus Gittinger <cg@exept.de>
parents: 1187
diff changeset
  1473
!Socket methodsFor:'Compatibility-Dolphin'!
1110
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  1474
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  1475
setReceiveTimeout: milliseconds
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  1476
    self receiveTimeout:(milliseconds / 1000)
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  1477
!
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  1478
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  1479
setSendTimeout: milliseconds
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  1480
    self sendTimeout:(milliseconds / 1000)
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  1481
! !
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  1482
1202
c52279df60d8 method category rename
Claus Gittinger <cg@exept.de>
parents: 1187
diff changeset
  1483
!Socket methodsFor:'Compatibility-ST80'!
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1484
887
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  1485
acceptNonBlock
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  1486
    ^ self accept
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  1487
!
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  1488
870
452fc695de34 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  1489
connectTo:aSocketAddress
452fc695de34 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  1490
    ^ self connectTo:aSocketAddress hostAddress port:aSocketAddress port
452fc695de34 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  1491
!
452fc695de34 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  1492
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1493
errorReporter
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1494
    "ST-80 mimicry."
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1495
1535
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  1496
    ^ self class
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1497
!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1498
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1499
ioConnection
887
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  1500
    ^ self
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  1501
!
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  1502
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1503
notReadySignal
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1504
    "ST-80 mimicry.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1505
     for now - this is not yet raised"
71
claus
parents: 63
diff changeset
  1506
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1507
    ^ Signal new
486
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1508
!
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1509
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1510
readAppendStream
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1511
    "ST-80 mimicry.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1512
     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
  1513
     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
  1514
     the actual stream.
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1515
     In ST/X, sockets inherit from stream, so
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1516
     this method returns the receiver, for transparency"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1517
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1518
    ^ self
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1519
!
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1520
486
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1521
readStream
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1522
    "ST-80 mimicry.
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1523
     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
  1524
     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
  1525
     the actual stream.
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1526
     In ST/X, sockets inherit from stream, so
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1527
     this method returns the receiver, for transparency"
486
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1528
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1529
    ^ self
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1530
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1531
    "Created: 24.1.1997 / 23:52:57 / cg"
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1532
!
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1533
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1534
writeStream
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1535
    "ST-80 mimicry.
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1536
     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
  1537
     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
  1538
     the actual stream.
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1539
     In ST/X, sockets inherit from stream, so
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1540
     this method returns the receiver, for transparency"
486
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1541
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1542
    ^ self
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1543
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1544
    "Created: 24.1.1997 / 10:34:35 / cg"
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1545
    "Modified: 24.1.1997 / 23:52:52 / cg"
71
claus
parents: 63
diff changeset
  1546
! !
claus
parents: 63
diff changeset
  1547
1202
c52279df60d8 method category rename
Claus Gittinger <cg@exept.de>
parents: 1187
diff changeset
  1548
!Socket methodsFor:'Compatibility-Squeak'!
771
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  1549
1462
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1550
address
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1551
    ^ self getSocketAddress
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
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1554
dataAvailable
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1555
    ^ self canReadWithoutBlocking
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1556
!
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1557
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1558
listenOn:aPortNr
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1559
    self bindTo:aPortNr address:nil.
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1560
    self listenWithBacklog:5
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1561
!
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1562
771
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  1563
peerName
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  1564
    "return my peer (i.e. ipAddr + port);
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  1565
     May return nil if not yet setup completely."
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  1566
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  1567
    ^ self getPeer
1462
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1568
!
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1569
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1570
setOption: optionName value: optionValue
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1571
    optionName = 'TCP_NODELAY' ifTrue:[
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1572
	^ self setTCPNoDelay:optionValue
1462
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1573
    ].
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1574
    self error:'unimplemented socketoption' mayProceed:true
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1575
!
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1576
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  1577
waitForConnectionUntil:aMillisecondClockValue
1505
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
  1578
    self shouldImplement.
771
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  1579
! !
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  1580
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1581
!Socket methodsFor:'datagram transmission'!
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1582
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1583
receiveBuffer:aDataBuffer start:startIndex for:nBytes
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1584
    "receive data
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1585
     Return the number of bytes received, or a negative number on error.
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1586
     On error, the unix error code is left in the lastErrorNumber
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1587
     instance variable.
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1588
     The thread blocks until data arrives - you may want to wait before
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1589
     receiving, using #readWait or #readWaitWithTimeout:."
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1590
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1591
    |nReceived|
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1592
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1593
%{
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1594
#ifndef NO_SOCKET
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1595
    OBJ fp = __INST(filePointer);
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1596
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1597
    if (fp != nil) {
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1598
	SOCKET sock;
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1599
	int objSize, offs;
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1600
	int n;
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1601
	char *extPtr;
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1602
	unsigned char *buffer;
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1603
	unsigned char *allocatedBuffer;
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1604
	int flags = 0;
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1605
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1606
	sock = SOCKET_FROM_FILE_OBJECT(fp);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1607
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1608
	if (! setupBufferParameters(aDataBuffer, startIndex, &extPtr, &offs, &objSize)) goto bad;
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1609
	if (__isSmallInteger(nBytes)) {
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1610
	    if (__intVal(nBytes) < objSize) {
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1611
		objSize = __intVal(nBytes);
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1612
	    }
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1613
	}
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1614
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1615
# ifdef DO_WRAP_CALLS
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1616
	if (extPtr) {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1617
	    buffer = extPtr + offs;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1618
	} else {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1619
	    allocatedBuffer = buffer = (char *)malloc(objSize);
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1620
	}
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1621
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1622
	do {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1623
	    __threadErrno = 0;
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1624
	    n = STX_WSA_CALL4("recv", recv, sock, buffer, objSize, flags);
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1625
	} while ((n < 0) && (__threadErrno == EINTR));
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1626
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1627
	if (allocatedBuffer) {
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1628
	    if (n > 0) {
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1629
		bcopy(allocatedBuffer, (char *)__InstPtr(aDataBuffer) + offs, n);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1630
	    }
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1631
	    free(allocatedBuffer);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1632
	}
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1633
# else
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1634
	__BEGIN_INTERRUPTABLE__
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1635
	do {
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1636
	    if (extPtr) {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1637
		n = recv(sock, extPtr + offs, objSize, flags);
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1638
	    } else {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1639
		n = recv(sock, (char *)__InstPtr(aDataBuffer) + offs, objSize, flags);
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1640
	    }
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1641
	} while ((n < 0) && (errno == EINTR));
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1642
	__END_INTERRUPTABLE__
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1643
# endif
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1644
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1645
	if (n < 0) {
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1646
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1647
	}
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1648
	nReceived = __MKSMALLINT(n);
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1649
    }
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1650
#endif
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1651
bad: ;
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1652
%}.
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1653
    nReceived notNil ifTrue:[
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1654
	nReceived < 0 ifTrue:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1655
	    'Socket [warning]: ' infoPrint.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1656
	    (OperatingSystem errorTextForNumber:lastErrorNumber) infoPrintCR.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1657
	].
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1658
	^ nReceived
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1659
    ].
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1660
    "
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  1661
     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
  1662
    "
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1663
    self primitiveFailed
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1664
!
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1665
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1666
receiveFrom:anAddressBuffer buffer:aDataBuffer
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1667
    "receive datagramm data - put address of originating host into
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1668
     anAddressBuffer, data into aBuffer.
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1669
     Both must be ByteArray-like. The addressBuffer must
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1670
     provide space for a valid address for my domain (i.e. for inet, a 4-byte byteArray).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1671
     Return the number of bytes received, or a negative number on error.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1672
     On error, the unix error code is left in the lastErrorNumber
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1673
     instance variable."
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1674
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1675
    ^ 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
  1676
!
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
  1677
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1678
receiveFrom:anAddressBuffer buffer:aDataBuffer start:startIndex for:nBytes
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1679
    "receive datagramm data
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1680
     - put address of originating host into anAddressBuffer, data into aBuffer.
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1681
     For backward compatibility, the addressBuffer may be a non-SocketAddress;
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  1682
     then, it must be a byteArray with appropriate size for the addressBytes.
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  1683
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1684
     Return the number of bytes received, or a negative number on error.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1685
     On error, the unix error code is left in the lastErrorNumber
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1686
     instance variable.
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1687
     The thread blocks until data arrives - you may want to wait before
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1688
     receiving, using #readWait or #readWaitWithTimeout:."
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1689
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  1690
    |domainClass addr addrLen nReceived|
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  1691
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  1692
    domainClass := self class socketAddressClassForDomain:domain.
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  1693
    domainClass isNil ifTrue:[
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1694
        ^ self error:'invalid (unsupported) domain'.
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  1695
    ].
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  1696
    (anAddressBuffer isKindOf:SocketAddress) ifTrue:[
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1697
        anAddressBuffer class == domainClass ifFalse:[
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1698
            ^ self error:'addressBuffer class mismatch (domain)'.
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1699
        ].
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1700
        addr := anAddressBuffer.
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  1701
    ] ifFalse:[
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1702
        anAddressBuffer notNil ifTrue:[
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1703
            addr := domainClass new.
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1704
        ].
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  1705
    ].
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  1706
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1707
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1708
#ifndef NO_SOCKET
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  1709
    OBJ fp = __INST(filePointer);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1710
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1711
    if (fp != nil) {
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1712
        SOCKET sock;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1713
        int objSize;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1714
        union sockaddr_u sa;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1715
        unsigned int alen = 0;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1716
        int n, offs;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1717
        int flags = 0;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1718
        char *extPtr;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1719
        unsigned char *allocatedBuffer = NULL;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1720
        unsigned char *buffer = NULL;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1721
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1722
        sock = SOCKET_FROM_FILE_OBJECT(fp);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1723
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1724
        if (! setupBufferParameters(aDataBuffer, startIndex, &extPtr, &offs, &objSize)) goto bad;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1725
        if (__isSmallInteger(nBytes)) {
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1726
            if (__intVal(nBytes) < objSize) {
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1727
                objSize = __intVal(nBytes);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1728
            }
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1729
        }
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1730
# ifdef DO_WRAP_CALLS
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1731
        if (extPtr) {
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1732
            buffer = extPtr + offs;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1733
        } else {
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1734
            allocatedBuffer = buffer = (char *)malloc(objSize);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1735
        }
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1736
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1737
        do {
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1738
            __threadErrno = 0;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1739
            alen = sizeof(sa);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1740
            n = STX_WSA_CALL6("recvfrom", recvfrom, sock, buffer, objSize, flags, (struct sockaddr *)&sa, &alen);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1741
        } while ((n < 0) && (__threadErrno == EINTR));
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1742
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1743
        if (allocatedBuffer) {
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1744
            if (n > 0) {
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1745
                bcopy(allocatedBuffer, (char *)__InstPtr(aDataBuffer) + offs, n);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1746
            }
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1747
            free(allocatedBuffer);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1748
        }
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1749
# else
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1750
        __BEGIN_INTERRUPTABLE__
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1751
        do {
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1752
            alen = sizeof(sa);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1753
            if (extPtr) {
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1754
                n = recvfrom(sock, extPtr + offs, objSize, flags, (struct sockaddr *) &sa, &alen);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1755
            } else {
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1756
                n = recvfrom(sock, (char *)__InstPtr(aDataBuffer) + offs, objSize, flags, (struct sockaddr *) &sa, &alen);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1757
            }
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1758
        } while ((n < 0) && (errno == EINTR));
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1759
        __END_INTERRUPTABLE__
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1760
# endif
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1761
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1762
        if (n >= 0) {
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1763
            if (__isNonNilObject(addr)) {
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1764
                char *addrPtr;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1765
                OBJ oClass;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1766
                int nInstVars, nInstBytes, objSize;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1767
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1768
                oClass = __qClass(addr);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1769
                if (! __isBytes(addr) )
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1770
                    goto bad;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1771
                nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1772
                nInstBytes = OHDR_SIZE + (nInstVars * sizeof(OBJ));
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1773
                objSize = __qSize(addr) - nInstBytes;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1774
                addrPtr = (char *)__InstPtr(addr) + nInstBytes;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1775
                if (objSize < alen)
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1776
                    goto bad;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1777
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1778
                /*
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1779
                 * extract the datagrams address
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1780
                 */
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1781
                bcopy((char *)&sa, addrPtr, alen);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1782
                addrLen = __MKSMALLINT(alen);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1783
            }
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1784
        }
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1785
        if (n < 0) {
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1786
            __INST(lastErrorNumber) = __MKSMALLINT(errno);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1787
        }
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1788
        nReceived = __MKSMALLINT(n);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1789
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1790
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1791
bad: ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1792
%}.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1793
    nReceived notNil ifTrue:[
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1794
        nReceived < 0 ifTrue:[
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1795
            'Socket [warning]: ' infoPrint.
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1796
            (OperatingSystem errorTextForNumber:lastErrorNumber) infoPrintCR.
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1797
        ].
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1798
        addrLen notNil ifTrue:[
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1799
            (addr == anAddressBuffer) ifFalse:[
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1800
                self obsoleteFeatureWarning:'please use a socketAddress argument'.
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1801
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1802
                " can be a ByteArray for backward compatibility "
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1803
                anAddressBuffer replaceFrom:1 to:addrLen with:(addr hostAddress).
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1804
            ].
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1805
        ].
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  1806
        ^ nReceived
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1807
    ].
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  1808
    "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1809
     arrive here if you try to receive into an invalid buffer
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1810
     (i.e. not ByteArray-like),
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1811
     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
  1812
     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
  1813
    "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1814
    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
  1815
!
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  1816
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1817
sendBuffer:aDataBuffer start:startIndex for:nBytes flags:flags
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1818
    "send data.
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1819
     Both must be ByteArray-like. The bytes in the addressBuffer must
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1820
     be a valid address for my domain (i.e. for inet, a 4-byte byteArray).
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1821
     Return the number of bytes transmitted, or a negative number on error.
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1822
     On error, the unix error code is left in the lastErrorNumber
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1823
     instance variable."
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1824
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1825
    |nReceived portNo|
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1826
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1827
%{
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1828
#ifndef NO_SOCKET
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1829
    OBJ fp = __INST(filePointer);
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1830
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1831
    if ((fp != nil)
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1832
     && __isSmallInteger(startIndex)
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1833
     && __isSmallInteger(nBytes)) {
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1834
	SOCKET sock;
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1835
	int objSize;
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1836
	int n;
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1837
	char *extPtr;
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1838
	int _flags = 0;
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1839
	int offs;
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1840
	unsigned long norder;
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1841
	unsigned char *buffer;
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1842
	unsigned char *allocatedBuffer;
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1843
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1844
	_flags = __longIntVal(flags);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1845
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1846
	sock = SOCKET_FROM_FILE_OBJECT(fp);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1847
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1848
	if (! setupBufferParameters(aDataBuffer, startIndex, &extPtr, &offs, &objSize)) goto bad;
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1849
	if (__isSmallInteger(nBytes)) {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1850
	    if (__intVal(nBytes) < objSize) {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1851
		objSize = __intVal(nBytes);
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1852
	    }
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1853
	}
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1854
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1855
# ifdef DGRAM_DEBUG
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1856
	printf("sending %d bytes ...\n", nBytes);
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1857
# endif
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1858
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1859
#ifdef DO_WRAP_CALLS
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1860
	if (extPtr) {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1861
	    buffer = extPtr + offs;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1862
	} else {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1863
	    allocatedBuffer = buffer = (char *)malloc(objSize);
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1864
	    bcopy((char *)__InstPtr(aDataBuffer) + offs, allocatedBuffer, objSize);
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1865
	}
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1866
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1867
	do {
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1868
	    __threadErrno = 0;
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1869
	    n = STX_WSA_CALL4("send", send, sock, buffer, objSize, _flags);
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1870
	} while ((n < 0) && (__threadErrno == EINTR));
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1871
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1872
	if (allocatedBuffer) {
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1873
	    free(allocatedBuffer);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1874
	}
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1875
#else
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1876
	__BEGIN_INTERRUPTABLE__
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1877
	do {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1878
	    if (extPtr) {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1879
		n = send(sock, extPtr + offs, objSize, _flags);
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1880
	    } else {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1881
		n = send(sock, (char *)__InstPtr(aDataBuffer) + offs, objSize, _flags);
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1882
	    }
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1883
	} while ((n < 0) && (errno == EINTR));
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1884
	__END_INTERRUPTABLE__
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1885
#endif
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1886
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1887
	if (n < 0) {
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1888
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1889
	}
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1890
	RETURN (__MKSMALLINT(n));
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1891
    }
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1892
#endif
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1893
bad: ;
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1894
%}.
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1895
    "
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1896
     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
  1897
    "
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1898
    self primitiveFailed
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1899
!
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1900
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1901
sendTo:anAddressBuffer buffer:buffer
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1902
    "send datagramm data - fetch address of destination host from
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1903
     anAddressBuffer, data from aDataBuffer.
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1904
     Both must be ByteArray-like. The bytes in the addressBuffer must
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1905
     be a valid address for my domain (i.e. for inet, a 4-byte byteArray).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1906
     Return the number of bytes transmitted, or a negative number on error.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1907
     On error, the unix error code is left in the lastErrorNumber
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1908
     instance variable.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1909
     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
  1910
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1911
    ^ 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
  1912
!
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  1913
817
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  1914
sendTo:anAddressBuffer buffer:buffer start:startIndex for:count
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  1915
    "send datagramm data - fetch address of destination host from
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1916
     anAddressBuffer, data from aDataBuffer.
817
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  1917
     Both must be ByteArray-like. The bytes in the addressBuffer must
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  1918
     be a valid address for my domain (i.e. for inet, a 4-byte byteArray).
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  1919
     Return the number of bytes transmitted, or a negative number on error.
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  1920
     On error, the unix error code is left in the lastErrorNumber
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  1921
     instance variable.
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  1922
     Flags is currently ignored; it is there for ST-80 compatibility."
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  1923
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1924
    ^ self sendTo:anAddressBuffer buffer:buffer start:startIndex for:count flags:0
817
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  1925
!
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  1926
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1927
sendTo:anAddressBuffer buffer:aDataBuffer start:startIndex for:nBytes flags:flags
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1928
    "send datagramm data - fetch address of destination host from
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1929
     anAddressBuffer, data from aDataBuffer starting at startIndex,
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1930
     sending count bytes.
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1931
     Both must be ByteArray-like. The bytes in the addressBuffer must
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1932
     be a valid address for my domain (i.e. for inet, a 4-byte byteArray).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1933
     Return the number of bytes transmitted, or a negative number on error.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1934
     On error, the unix error code is left in the lastErrorNumber
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1935
     instance variable."
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1936
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  1937
    |domainClass addr|
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  1938
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  1939
    domainClass := self class socketAddressClassForDomain:domain.
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  1940
    domainClass isNil ifTrue:[
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1941
	^ self error:'invalid (unsupported) domain'.
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  1942
    ].
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  1943
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  1944
    (anAddressBuffer isKindOf:SocketAddress) ifTrue:[
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1945
	addr := anAddressBuffer.
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  1946
    ] ifFalse:[
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1947
	anAddressBuffer isByteArray ifFalse:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1948
	    ^ self error:'bad socketAddress argument'
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1949
	].
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1950
	addr := domainClass hostAddress:anAddressBuffer.
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1951
    ].
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1952
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1953
#ifndef NO_SOCKET
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  1954
    OBJ fp = __INST(filePointer);
21
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1955
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  1956
    if ((fp != nil)
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1957
     && __isSmallInteger(startIndex)
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1958
     && __isSmallInteger(nBytes)) {
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1959
	SOCKET sock;
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1960
	int objSize;
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1961
	struct sockaddr *sockaddr_ptr;
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1962
	union sockaddr_u sa;
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1963
	int alen = 0;
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1964
	int sockAddrOffs, sockaddr_size;
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1965
	int n;
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1966
	char *extPtr;
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1967
	int _flags = 0;
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1968
	int offs;
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1969
	unsigned long norder;
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1970
	unsigned char *buffer;
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1971
	unsigned char *allocatedBuffer;
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  1972
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1973
	_flags = __longIntVal(flags);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1974
	sock = SOCKET_FROM_FILE_OBJECT(fp);
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1975
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1976
	if (! __isBytes(addr)) {
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1977
	    sockaddr_size = 0;
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1978
	    sockaddr_ptr = (struct sockaddr *)0;
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1979
	} else {
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1980
	    int nIndex;
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1981
	    OBJ cls;
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1982
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1983
	    sockAddrOffs = 0;
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1984
	    if ((cls = __qClass(addr)) != @global(ByteArray))
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1985
		sockAddrOffs += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1986
	    nIndex = __qSize(addr) - OHDR_SIZE;
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  1987
	    sockaddr_size = nIndex - sockAddrOffs;
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1988
	    if (sockaddr_size > sizeof(sa)) {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1989
		fprintf(stderr, "bad socketAddr\n");
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1990
		goto bad;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1991
	    }
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1992
	    bcopy((__byteArrayVal(addr) + sockAddrOffs), &sa, sockaddr_size);
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1993
	    sockaddr_ptr = (struct sockaddr *)(&sa);
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1994
	}
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1995
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  1996
	if (! setupBufferParameters(aDataBuffer, startIndex, &extPtr, &offs, &objSize)) goto bad;
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1997
	if (__isSmallInteger(nBytes)) {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1998
	    if (__intVal(nBytes) < objSize) {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  1999
		objSize = __intVal(nBytes);
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  2000
	    }
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  2001
	}
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  2002
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2003
#ifdef DO_WRAP_CALLS
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  2004
	if (extPtr) {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  2005
	    buffer = extPtr + offs;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  2006
	} else {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  2007
	    allocatedBuffer = buffer = (char *)malloc(objSize);
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  2008
	    bcopy((char *)__InstPtr(aDataBuffer) + offs, allocatedBuffer, objSize);
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  2009
	}
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2010
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  2011
	do {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  2012
	    __threadErrno = 0;
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  2013
	    n = STX_WSA_CALL6("sendto", sendto, sock, buffer, objSize, _flags, sockaddr_ptr, sockaddr_size);
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  2014
	} while ((n < 0) && (__threadErrno == EINTR));
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2015
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2016
	if (allocatedBuffer) {
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2017
	    free(allocatedBuffer);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2018
	}
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  2019
#else
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2020
	__BEGIN_INTERRUPTABLE__
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  2021
	do {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  2022
	    if (extPtr) {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  2023
		n = sendto(sock, extPtr + offs, objSize, _flags, sockaddr_ptr, sockaddr_size);
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  2024
	    } else {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  2025
		n = sendto(sock, (char *)__InstPtr(aDataBuffer) + offs, objSize, _flags, sockaddr_ptr, sockaddr_size);
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  2026
	    }
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  2027
	} while ((n < 0) && (errno == EINTR));
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  2028
	__END_INTERRUPTABLE__
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  2029
#endif
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  2030
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  2031
	if (n < 0) {
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  2032
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  2033
	}
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  2034
	RETURN (__MKSMALLINT(n));
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2035
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  2036
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2037
bad: ;
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  2038
%}.
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  2039
    "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2040
     arrive here if you try to send from an invalid buffer
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  2041
     (i.e. not ByteArray-like),
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  2042
     or if the addressBuffer is nonNil AND not a ByteArray/String
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2043
     or if the addressBuffer is nonNil AND too small.
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  2044
    "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2045
    self primitiveFailed
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2046
! !
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2047
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2048
!Socket methodsFor:'low level'!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2049
507
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  2050
bindAnonymously
1505
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
  2051
    "bind to any address. A free port will be allocated.
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
  2052
     Our own socket address will be determined after conection set up.
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
  2053
     This is the default after the socket has been created"
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
  2054
507
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  2055
    ^ self
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2056
	bindTo:nil
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2057
	address:nil
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2058
	reuseAddress:false
509
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2059
!
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2060
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2061
bindAnonymouslyToAddress:addressString
1505
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
  2062
    "bind to address addressString.
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
  2063
     A free port will be allocated"
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
  2064
509
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2065
    ^ self
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2066
	bindTo:nil
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2067
	address:addressString
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2068
	reuseAddress:false
507
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  2069
!
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  2070
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  2071
bindTo:aSocketAddress
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2072
    "ST80 compatible bind, expecting a socketAddress argument.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2073
     The socketAddress object (an instance of SocketAddress)
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2074
     is supposed to respond to #portOrName and #address requests."
71
claus
parents: 63
diff changeset
  2075
claus
parents: 63
diff changeset
  2076
    ^ self bindTo:(aSocketAddress portOrName)
claus
parents: 63
diff changeset
  2077
	   address:(aSocketAddress address)
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2078
	   reuseAddress:true
71
claus
parents: 63
diff changeset
  2079
!
claus
parents: 63
diff changeset
  2080
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2081
bindTo:portNrOrNameString address:addressString
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2082
    "low level bind - returns true if ok, false otherwise.
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  2083
     Currently only non-address binding is supported;
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2084
     i.e. the address must always be nil.
71
claus
parents: 63
diff changeset
  2085
claus
parents: 63
diff changeset
  2086
     The interpretation of portNrOrName depends on the domain:
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2087
	inet domain uses (4byte) byteArray like internet numbers,
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2088
	unix domain uses pathname strings,
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2089
	others use whatever will come up in the future
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2090
     "
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2091
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  2092
    ^ self
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  2093
	bindTo:portNrOrNameString
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  2094
	address:addressString
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2095
	reuseAddress:true
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2096
!
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2097
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2098
bindTo:portNrOrNameOrNil address:hostOrPathNameOrSocketAddrOrNil reuseAddress:reuse
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2099
    "low level bind - returns true if ok, false otherwise.
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  2100
     Currently only non-address binding is supported;
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2101
     i.e. address must always be nil.
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2102
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2103
     The interpretation of portNrOrName depends on the domain:
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2104
        inet domain uses (4byte) byteArray like internet numbers,
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2105
        unix domain uses pathname strings,
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2106
        others use whatever will come up in the future
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2107
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2108
     The reuse boolean argument controls if the SO_REUSEADDR socket option
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2109
     is to be set (to avoid the 'bind: address in use' error).
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2110
    "
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2111
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2112
    |ok addr addrName domainClass|
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2113
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2114
    filePointer isNil ifTrue:[
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2115
        ^ self errorNotOpen
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2116
    ].
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2117
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2118
    domainClass := self class socketAddressClassForDomain:domain.
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2119
    domainClass isNil ifTrue:[
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2120
        ^ self error:'invalid (unsupported) domain'.
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2121
    ].
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2122
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2123
    " backward compatibility: support for byteArray and string arg "
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2124
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2125
    hostOrPathNameOrSocketAddrOrNil isNil ifTrue:[
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2126
        addr := domainClass anyHost.
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2127
    ] ifFalse:[
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2128
        hostOrPathNameOrSocketAddrOrNil isString ifTrue:[
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2129
            addr := domainClass hostName:hostOrPathNameOrSocketAddrOrNil.
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2130
            addrName := hostOrPathNameOrSocketAddrOrNil.
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2131
        ] ifFalse:[
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2132
            (hostOrPathNameOrSocketAddrOrNil isKindOf:SocketAddress) ifTrue:[
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2133
                addr := hostOrPathNameOrSocketAddrOrNil.
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2134
            ] ifFalse:[
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2135
                hostOrPathNameOrSocketAddrOrNil isByteArray ifFalse:[
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2136
                    ^ self error:'bad host (socketAddress) argument'
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2137
                ].
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2138
                addr := domainClass hostAddress:hostOrPathNameOrSocketAddrOrNil.
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2139
            ].
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2140
        ].
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2141
    ].
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2142
    portNrOrNameOrNil notNil ifTrue:[
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2143
        addr port:portNrOrNameOrNil.
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2144
    ].
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  2145
    (portNrOrNameOrNil isNil or:[portNrOrNameOrNil == 0]) ifTrue:[
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2146
        addr := addr copy.
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  2147
    ].
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2148
1120
b43bcd84bca8 gethostbyname beeds more than 64kb stack
martin
parents: 1119
diff changeset
  2149
%{  /* STACK: 100000 */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  2150
#ifndef NO_SOCKET
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2151
    OBJ fp = __INST(filePointer);
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2152
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2153
    if (! __isBytes(addr)) {
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2154
        addr = nil;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2155
        fprintf(stderr, "Socket: bad sddr\n");
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2156
        RETURN (false);
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2157
    }
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2158
    if (fp != nil) {
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2159
        SOCKET sock;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2160
        union sockaddr_u sa;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2161
        int sockaddr_size;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2162
        int ret;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2163
        int sockAddrOffs;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2164
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2165
        {
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2166
            int nIndex;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2167
            OBJ cls;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2168
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2169
            sockAddrOffs = 0;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2170
            if ((cls = __qClass(addr)) != @global(ByteArray))
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2171
                sockAddrOffs += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2172
            nIndex = __qSize(addr) - OHDR_SIZE;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2173
            sockaddr_size = nIndex - sockAddrOffs;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2174
            if (sockaddr_size > sizeof(sa)) {
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2175
                fprintf(stderr, "Socket: bad socketAddr\n");
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2176
                RETURN (false);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2177
            }
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2178
            bcopy((__byteArrayVal(addr) + sockAddrOffs), &sa, sockaddr_size);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2179
        }
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2180
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2181
        sock = SOCKET_FROM_FILE_OBJECT(fp);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2182
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2183
# ifdef SO_REUSEADDR
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2184
        if (reuse == true) {
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2185
            int on = 1;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2186
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2187
            if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) {
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2188
                DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n"));
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2189
            }
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2190
        }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2191
# endif /* SO_REUSEADDR */
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2192
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  2193
# ifdef BIND_BLOCKS
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  2194
#  ifdef DO_WRAP_CALLS
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2195
        do {
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2196
            __threadErrno = 0;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2197
            ret = STX_WSA_CALL3("bind", bind, sock, &sa, sockaddr_size);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2198
        } while ((ret < 0) && (__threadErrno == EINTR));
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  2199
#  else
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2200
        __BEGIN_INTERRUPTABLE__
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2201
        do {
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2202
            ret = bind(sock, (struct sockaddr *)&sa, sockaddr_size);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2203
        } while ((ret < 0) && (errno == EINTR));
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2204
        __END_INTERRUPTABLE__
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  2205
#  endif
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  2206
# else
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2207
        ret = bind(sock, (struct sockaddr *)&sa, sockaddr_size);
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2208
# endif
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2209
        if (ret < 0) {
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2210
            DBGPRINTF(("SOCKET: bind failed errno=%d\n", errno));
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2211
            __INST(lastErrorNumber) = __MKSMALLINT(errno);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2212
            RETURN (false);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2213
        } else {
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2214
            ok = true;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2215
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2216
            if (! __isSmallInteger(portNrOrNameOrNil)
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2217
                || (portNrOrNameOrNil == __MKSMALLINT(0))) {
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2218
                unsigned int alen = sockaddr_size;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2219
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2220
                /*
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2221
                 * anonymous port - get the actual portNr
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2222
                 */
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2223
                if (getsockname(sock, (struct sockaddr *)&sa, &alen) < 0) {
1536
Claus Gittinger <cg@exept.de>
parents: 1535
diff changeset
  2224
# ifdef WIN32
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2225
                    errno = WSAGetLastError();
1536
Claus Gittinger <cg@exept.de>
parents: 1535
diff changeset
  2226
# endif
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2227
                    fprintf(stderr, "SOCKET: cannot get socketname: %d\n", errno);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2228
                }
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2229
                bcopy(&sa, (__byteArrayVal(addr) + sockAddrOffs), alen);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2230
            }
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2231
        }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2232
    }
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2233
#endif /* NO_SOCKET */
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2234
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2235
getOutOfHere: ;
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  2236
%}.
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2237
    ok ~~ true ifTrue:[
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2238
        ^ false
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2239
    ].
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2240
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2241
    peer := addr.
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2242
    port := addr port.
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2243
    peerName := addrName.
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2244
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2245
    ^ true
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2246
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2247
    "
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2248
     (Socket domain:#inet type:#stream)
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2249
         bindTo:9999
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2250
         address:nil
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2251
    "
1474
1ad407692b0b Protect #closeFile.
Stefan Vogel <sv@exept.de>
parents: 1462
diff changeset
  2252
! !
1ad407692b0b Protect #closeFile.
Stefan Vogel <sv@exept.de>
parents: 1462
diff changeset
  2253
1ad407692b0b Protect #closeFile.
Stefan Vogel <sv@exept.de>
parents: 1462
diff changeset
  2254
!Socket protectedMethodsFor:'low level'!
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2255
1558
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2256
closeFile
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2257
    "low level close"
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2258
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2259
%{  /* NOCONTEXT */
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2260
#ifndef NO_SOCKET
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2261
    OBJ t;
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2262
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2263
    t = __INST(filePointer);
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2264
    if (t != nil) {
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2265
	FILE *fp;
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2266
	SOCKET sock;
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2267
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2268
	__INST(filePointer) = nil;
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2269
	fp = __FILEVal(t);
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2270
	sock = SOCKET_FROM_FILE(fp);
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2271
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2272
# ifdef xxDO_WRAP_CALLS
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2273
	{ int ret;
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2274
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2275
	  do {
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2276
	    __threadErrno = 0;
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2277
	    ret = STX_C_CALL1("fclose", fclose, fp);
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2278
	  } while ((ret < 0) && (__threadErrno == EINTR));
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2279
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2280
#  ifdef WIN32
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2281
	  do {
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2282
	    __threadErrno = 0;
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2283
	    ret = STX_WSA_CALL1("closesocket", closesocket, sock);
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2284
	  } while ((ret < 0) && (__threadErrno == EINTR));
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2285
	  closesocket(sock);
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2286
#  endif
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2287
	}
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2288
# else /* !DO_WRAP_CALLS */
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2289
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2290
	DBGFPRINTF((stderr, "SOCKET: fflush %x (%d)\n", fp, fileno(fp)));
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2291
	fflush(fp);
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2292
	/* shutdown(fileno(fp), 2); */
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2293
#  ifdef xxWIN32
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2294
	closesocket(sock);
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2295
#  endif
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2296
	DBGFPRINTF((stderr, "SOCKET: fclose %x (%d)\n", fp, sock));
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2297
	if (@global(FileOpenTrace) == true) {
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2298
	    fprintf(stderr, "fclose [Socket] %x\n", fp);
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2299
	}
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2300
	fclose(fp);
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2301
#  ifdef WIN32
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2302
	DBGFPRINTF((stderr, "SOCKET: closesocket (%d)\n", sock));
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2303
	closesocket(sock);
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2304
#  endif
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2305
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2306
# endif /* !DO_WRAP_CALLS */
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2307
    }
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2308
#endif /* NO_SOCKET */
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2309
%}
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2310
! !
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2311
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2312
!Socket methodsFor:'low level'!
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2313
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2314
getSocketError
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2315
    "get the SO_ERROR form the socket, which indicates the
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2316
     result of an asynchronous operation"
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2317
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2318
%{
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2319
#ifndef NO_SOCKET
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2320
    OBJ fp;
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2321
    int err;
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2322
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2323
    fp = __INST(filePointer);
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2324
    if (fp == nil) {
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2325
        err = EBADF;
1558
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2326
    } else {
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2327
        unsigned int sz;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2328
        SOCKET sock;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2329
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2330
        sock = SOCKET_FROM_FILE_OBJECT(fp);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2331
        sz = sizeof(err);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2332
        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
  2333
# ifdef WIN32
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2334
            errno = WSAGetLastError();
1558
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2335
# endif
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2336
            err = errno;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2337
        }
1558
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2338
    }
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2339
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2340
    RETURN(__MKSMALLINT(err));
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2341
#endif
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2342
%}
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2343
!
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2344
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2345
listenFor:aNumber
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2346
    "same as listenWithBacklog: - for ST-80 compatibility"
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2347
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2348
    ^ self listenWithBacklog:aNumber
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2349
!
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2350
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2351
listenWithBacklog:aNumber
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2352
    "start listening; return true if ok, false on error"
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2353
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2354
    filePointer isNil ifTrue:[
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2355
	^ self errorNotOpen
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2356
    ].
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2357
%{
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2358
#ifndef NO_SOCKET
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2359
    OBJ fp = __INST(filePointer);
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2360
    SOCKET sock;
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2361
    int ret;
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2362
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2363
    if (! __isSmallInteger(aNumber)) {
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2364
	DBGPRINTF(("SOCKET: invalid arg\n"));
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2365
	RETURN (false);
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2366
    }
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2367
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2368
    sock = SOCKET_FROM_FILE_OBJECT(fp);
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2369
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2370
#ifdef LISTEN_BLOCKS
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2371
# ifdef DO_WRAP_CALLS
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2372
    do {
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2373
	__threadErrno = 0;
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2374
	ret = STX_WSA_CALL2("listen", listen, sock, __intVal(aNumber));
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2375
    } while ((ret < 0) && (__threadErrno == EINTR));
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2376
# else
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2377
    __BEGIN_INTERRUPTABLE__
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2378
    do {
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2379
	ret = listen(sock, __intVal(aNumber));
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2380
    } while ((ret < 0) && (errno == EINTR));
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2381
    __END_INTERRUPTABLE__
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2382
# endif
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2383
#else
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2384
    ret = listen(sock, __intVal(aNumber));
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2385
#endif
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2386
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2387
    if (ret < 0) {
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2388
	DBGPRINTF(("SOCKET: listen call failed errno=%d\n", errno));
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2389
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2390
	RETURN (false);
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2391
    }
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2392
#else
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2393
    RETURN (false);
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2394
#endif
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2395
%}.
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2396
    listening := true.
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2397
    ^ true
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2398
! !
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2399
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2400
!Socket protectedMethodsFor:'low level'!
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2401
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2402
setSocketOption:option argument:arg1 argument:arg2
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2403
    |ok|
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2404
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2405
%{  /* STACK: 32000 */
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2406
    OBJ fp = __INST(filePointer);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2407
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2408
    if (fp != nil) {
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  2409
	SOCKET sock;
1532
36cfd144f135 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1531
diff changeset
  2410
	int opt = -1;
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2411
	int level = -1;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2412
	int usize = -1;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2413
	int ret;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2414
	union u {
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2415
	    BOOL        u_bool;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2416
	    int         u_int;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2417
	    struct linger u_linger;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2418
	} u;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2419
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2420
	sock = SOCKET_FROM_FILE_OBJECT(fp);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2421
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2422
# ifdef SO_BROADCAST
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2423
	if (option == @symbol(SO_BROADCAST)) {
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2424
	    /* Enables transmission and receipt of broadcast messages on the socket. */
1532
36cfd144f135 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1531
diff changeset
  2425
	    opt = SO_BROADCAST;
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2426
	    level = SOL_SOCKET;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2427
	    usize = sizeof(u.u_bool);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2428
	    if (arg1 == true) u.u_bool = TRUE;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2429
	    else if (arg1 == false) u.u_bool = FALSE;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2430
	    else goto argError;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2431
	}
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2432
# endif /* SO_BROADCAST */
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2433
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2434
# ifdef SO_CONDITIONAL
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2435
#  if 0
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2436
	if (option == @symbol(SO_CONDITIONAL)) {
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2437
	    /* Enables sockets to delay the acknowledgment of a connection until after the WSAAccept condition function is called. */
1532
36cfd144f135 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1531
diff changeset
  2438
	    opt = SO_CONDITIONAL;
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2439
	    level = SOL_SOCKET;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2440
	    usize = sizeof(u.u_bool);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2441
	    if (arg1 == true) u.u_bool = TRUE;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2442
	    else if (arg1 == false) u.u_bool = FALSE;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2443
	    else goto argError;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2444
	}
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2445
#  endif
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2446
# endif /* SO_CONDITIONAL */
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2447
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2448
# ifdef SO_DEBUG
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2449
	if (option == @symbol(SO_DEBUG)) {
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2450
	    /* Records debugging information. */
1532
36cfd144f135 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1531
diff changeset
  2451
	    opt = SO_DEBUG;
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2452
	    level = SOL_SOCKET;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2453
	    usize = sizeof(u.u_bool);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2454
	    if (arg1 == true) u.u_bool = TRUE;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2455
	    else if (arg1 == false) u.u_bool = FALSE;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2456
	    else goto argError;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2457
	}
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2458
# endif /* SO_DEBUG */
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2459
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2460
# ifdef SO_DONTLINGER
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2461
	    if (option == @symbol(SO_DONTLINGER)) {
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2462
		/* Does not block close waiting for unsent data to be sent.
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2463
		   Setting this option is equivalent to setting SO_LINGER with l_onoff set to zero. */
1532
36cfd144f135 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1531
diff changeset
  2464
		opt = SO_DONTLINGER;
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2465
		level = SOL_SOCKET;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2466
		usize = sizeof(u.u_bool);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2467
		if (arg1 == true) u.u_bool = TRUE;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2468
		else if (arg1 == false) u.u_bool = FALSE;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2469
		else goto argError;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2470
	    }
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2471
# endif /* SO_DONTLINGER */
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2472
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2473
# ifdef SO_DONTROUTE
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2474
	if (option == @symbol(SO_DONTROUTE)) {
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2475
	    /* Does not route: sends directly to interface.
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2476
	       Succeeds but is ignored on AF_INET sockets;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2477
	       fails on AF_INET6 sockets with WSAENOPROTOOPT.
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2478
	       Not supported on ATM sockets (results in an error). */
1532
36cfd144f135 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1531
diff changeset
  2479
	    opt = SO_DONTROUTE;
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2480
	    level = SOL_SOCKET;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2481
	    usize = sizeof(u.u_bool);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2482
	    if (arg1 == true) u.u_bool = TRUE;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2483
	    else if (arg1 == false) u.u_bool = FALSE;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2484
	    else goto argError;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2485
	}
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2486
# endif /* SO_DONTROUTE */
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2487
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2488
# ifdef SO_KEEPALIVE
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2489
	if (option == @symbol(SO_KEEPALIVE)) {
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2490
	    /* Sends keep-alives. Not supported on ATM sockets (results in an error). */
1532
36cfd144f135 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1531
diff changeset
  2491
	    opt = SO_KEEPALIVE;
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2492
	    level = SOL_SOCKET;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2493
	    usize = sizeof(u.u_bool);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2494
	    if (arg1 == true) u.u_bool = TRUE;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2495
	    else if (arg1 == false) u.u_bool = FALSE;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2496
	    else goto argError;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2497
	}
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2498
# endif /* SO_KEEPALIVE */
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2499
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2500
# ifdef SO_LINGER
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2501
	if (option == @symbol(SO_LINGER)) {
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2502
	    /* Lingers on close if unsent data is present. */
1532
36cfd144f135 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1531
diff changeset
  2503
	    opt = SO_LINGER;
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2504
	    level = SOL_SOCKET;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2505
	    usize = sizeof(u.u_linger);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2506
	    if (arg1 == true) u.u_linger.l_onoff = TRUE;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2507
	    else if (arg1 == false) u.u_linger.l_onoff = FALSE;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2508
	    else goto argError;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2509
	    if (arg2 == nil) u.u_linger.l_linger = 0;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2510
	    else if (__isSmallInteger(arg2))u.u_linger.l_linger = __intVal(arg2);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2511
	    else goto argError;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2512
	    DBGPRINTF(("SOCKET: SO_LINGER %d %d\n", u.u_linger.l_onoff, u.u_linger.l_linger));
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2513
	}
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2514
# endif /* SO_LINGER */
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2515
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2516
# ifdef SO_OOBINLINE
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2517
	if (option == @symbol(SO_OOBINLINE)) {
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2518
	    /* Receives OOB data in the normal data stream. */
1532
36cfd144f135 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1531
diff changeset
  2519
	    opt = SO_OOBINLINE;
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2520
	    level = SOL_SOCKET;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2521
	    usize = sizeof(u.u_bool);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2522
	    if (arg1 == true) u.u_bool = TRUE;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2523
	    else if (arg1 == false) u.u_bool = FALSE;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2524
	    else goto argError;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2525
	}
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2526
# endif /* SO_OOBINLINE */
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2527
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2528
# ifdef SO_RCVBUF
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2529
	if (option == @symbol(SO_RCVBUF)) {
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2530
	    /* Specifies the total per-socket buffer space reserved for receives.
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2531
	       This is unrelated to SO_MAX_MSG_SIZE or the size of a TCP window. */
1532
36cfd144f135 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1531
diff changeset
  2532
	    opt = SO_RCVBUF;
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2533
	    level = SOL_SOCKET;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2534
	    usize = sizeof(u.u_int);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2535
	    if (__isSmallInteger(arg1))u.u_int = __intVal(arg1);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2536
	    else goto argError;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2537
	}
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2538
# endif /* SO_RCVBUF */
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2539
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2540
# ifdef SO_SNDBUF
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2541
	if (option == @symbol(SO_SNDBUF)) {
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2542
	    /* Specifies the total per-socket buffer space reserved for sends.
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2543
	       This is unrelated to SO_MAX_MSG_SIZE or the size of a TCP window. */
1532
36cfd144f135 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1531
diff changeset
  2544
	    opt = SO_SNDBUF;
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2545
	    level = SOL_SOCKET;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2546
	    usize = sizeof(u.u_int);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2547
	    if (__isSmallInteger(arg1))u.u_int = __intVal(arg1);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2548
	    else goto argError;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2549
	}
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2550
# endif /* SO_SNDBUF */
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2551
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2552
# ifdef SO_REUSEADDR
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2553
	if (option == @symbol(SO_REUSEADDR)) {
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2554
	    /* Allows the socket to be bound to an address that is already in use.  */
1532
36cfd144f135 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1531
diff changeset
  2555
	    opt = SO_REUSEADDR;
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2556
	    level = SOL_SOCKET;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2557
	    usize = sizeof(u.u_bool);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2558
	    if (arg1 == true) u.u_bool = TRUE;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2559
	    else if (arg1 == false) u.u_bool = FALSE;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2560
	    else goto argError;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2561
	}
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2562
# endif /* SO_OOBINLINE */
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2563
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2564
# ifdef SO_EXCLUSIVEADDRUSE
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2565
	if (option == @symbol(SO_EXCLUSIVEADDRUSE)) {
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2566
	    /* Enables a socket to be bound for exclusive access.
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2567
	       Does not require administrative privilege.  */
1532
36cfd144f135 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1531
diff changeset
  2568
	    opt = SO_EXCLUSIVEADDRUSE;
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2569
	    level = SOL_SOCKET;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2570
	    usize = sizeof(u.u_bool);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2571
	    if (arg1 == true) u.u_bool = TRUE;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2572
	    else if (arg1 == false) u.u_bool = FALSE;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2573
	    else goto argError;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2574
	}
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2575
# endif /* SO_OOBINLINE */
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2576
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2577
	if (usize == -1) goto argError;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2578
1533
a64cbf0e29b0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1532
diff changeset
  2579
	ok = ( setsockopt( sock, level, opt, &u, usize) >= 0) ? true : false;
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2580
    }
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2581
argError: ;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2582
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2583
%}.
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2584
    ok isNil ifTrue:[
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2585
	self primitiveFailed
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2586
    ].
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2587
    ok ifFalse:[
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2588
	'setsocketoption failed' infoPrintCR.
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2589
    ].
1474
1ad407692b0b Protect #closeFile.
Stefan Vogel <sv@exept.de>
parents: 1462
diff changeset
  2590
! !
1ad407692b0b Protect #closeFile.
Stefan Vogel <sv@exept.de>
parents: 1462
diff changeset
  2591
1ad407692b0b Protect #closeFile.
Stefan Vogel <sv@exept.de>
parents: 1462
diff changeset
  2592
!Socket methodsFor:'low level'!
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2593
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  2594
shutDown
1339
cc973a42aa54 shutdown: added
Claus Gittinger <cg@exept.de>
parents: 1338
diff changeset
  2595
    "shutDown and close the socket.
cc973a42aa54 shutdown: added
Claus Gittinger <cg@exept.de>
parents: 1338
diff changeset
  2596
     This does not wait for the data to be delivered."
cc973a42aa54 shutdown: added
Claus Gittinger <cg@exept.de>
parents: 1338
diff changeset
  2597
cc973a42aa54 shutdown: added
Claus Gittinger <cg@exept.de>
parents: 1338
diff changeset
  2598
    self shutdown:2.
cc973a42aa54 shutdown: added
Claus Gittinger <cg@exept.de>
parents: 1338
diff changeset
  2599
    self close
cc973a42aa54 shutdown: added
Claus Gittinger <cg@exept.de>
parents: 1338
diff changeset
  2600
!
cc973a42aa54 shutdown: added
Claus Gittinger <cg@exept.de>
parents: 1338
diff changeset
  2601
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  2602
shutdown: howNum
1339
cc973a42aa54 shutdown: added
Claus Gittinger <cg@exept.de>
parents: 1338
diff changeset
  2603
    "shutDown the socket - inform it that no more I/O will be performed.
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  2604
	 0 - read side   (no further reads)
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  2605
	 1 - write side  (no further writes)
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  2606
	 2 - both        (no further I/O at all)
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  2607
     shutDown:2
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2608
	discards any pending data
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2609
	(as opposed to close, which might wait until data is delivered as set by LINGER)"
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2610
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2611
%{
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2612
#ifndef NO_SOCKET
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2613
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2614
    OBJ fp;
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2615
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2616
    fp = __INST(filePointer);
1339
cc973a42aa54 shutdown: added
Claus Gittinger <cg@exept.de>
parents: 1338
diff changeset
  2617
    if ((fp != nil) && __isSmallInteger(howNum)) {
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  2618
	SOCKET sock;
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2619
	int ret;
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  2620
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2621
	sock = SOCKET_FROM_FILE_OBJECT(fp);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2622
# ifdef DO_WRAP_CALLS
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2623
	do {
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2624
	    __threadErrno = 0;
1541
61e23e2a40dd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1540
diff changeset
  2625
	    DBGFPRINTF((stderr, "SOCKET: shutDown...\n"));
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  2626
	    ret = STX_WSA_CALL2("shutdown", shutdown, sock, __intVal(howNum));
1541
61e23e2a40dd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1540
diff changeset
  2627
	    DBGFPRINTF((stderr, "SOCKET: shutDown -> %d (%d)\n", ret, __threadErrno));
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2628
	} while ((ret < 0) && (__threadErrno == EINTR));
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2629
# else
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  2630
	__BEGIN_INTERRUPTABLE__
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2631
	shutdown(sock, __intVal(howNum));
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  2632
	__END_INTERRUPTABLE__
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2633
# endif
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2634
    }
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2635
#endif
1339
cc973a42aa54 shutdown: added
Claus Gittinger <cg@exept.de>
parents: 1338
diff changeset
  2636
%}.
1505
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
  2637
!
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
  2638
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
  2639
tryToBindTo:portNrOrNameOrNil
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
  2640
    (self bindTo:portNrOrNameOrNil address:nil) ifFalse:[
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
  2641
	self close.
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
  2642
	^ nil
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
  2643
    ].
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
  2644
    ^ self.
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2645
! !
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2646
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2647
!Socket methodsFor:'low level-accepting'!
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2648
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2649
accept
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2650
    "create a new TCP socket from accepting on the receiver.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2651
     This method will suspend the current process if no connection is waiting.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2652
     For ST-80 compatibility"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2653
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2654
    |newSock|
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2655
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2656
    OperatingSystem isMSWINDOWSlike ifTrue:[
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2657
	^ self waitForNewConnectionWithTimeout:nil
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2658
    ].
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2659
    newSock := self class new.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2660
    (newSock acceptOn:self) ifFalse:[^ nil].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2661
    ^ newSock
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2662
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2663
    "
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2664
     |sock newSock|
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2665
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2666
     sock := Socket provide:8004.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2667
     sock listenFor:5.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2668
     newSock := sock accept.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2669
    "
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2670
!
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2671
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2672
acceptOn:aSocket
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2673
    "accept a connection on a server port (created with:'Socket>>onIPPort:')
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2674
     usage is: (Socket basicNew acceptOn:(Socket onIPPort:9999)).
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2675
     This method will suspend the current process if no connection is waiting.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2676
     Return the true if ok; false if not."
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2677
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2678
    OperatingSystem isMSWINDOWSlike ifTrue:[
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2679
	^ self primAcceptOn:aSocket blocking:true.
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2680
    ].
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  2681
    aSocket readWait.
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2682
    ^ self primAcceptOn:aSocket blocking:false.
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2683
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2684
    "Modified: / 11.3.1996 / 14:21:31 / stefan"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2685
    "Modified: / 1.8.1998 / 23:39:10 / cg"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2686
!
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2687
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2688
blockingAccept
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2689
    "create a new TCP socket from accepting on the receiver.
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2690
     This method will suspend the current process if no connection is waiting.
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2691
     For ST-80 compatibility"
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2692
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2693
    |newSock|
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2694
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2695
    newSock := self class new.
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2696
    (newSock blockingAcceptOn:self) ifFalse:[^ nil].
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2697
    ^ newSock
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2698
!
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2699
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2700
blockingAcceptOn:aSocket
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2701
    "accept a connection on a server port (created with:'Socket>>onIPPort:')
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2702
     usage is: (Socket basicNew acceptOn:(Socket onIPPort:9999)).
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2703
     This method will suspend the current process if no connection is waiting.
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2704
     Return the true if ok; false if not."
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2705
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2706
    ^ self primAcceptOn:aSocket blocking:true.
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2707
!
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2708
1558
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2709
pollingWaitForNewConnectionOrDataOnAny:otherConnections timeout:timeoutSeconds
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2710
    "stupid MSDOS does not support select on sockets (sigh).
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2711
     Must poll here."
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2712
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2713
    |millis newConnection|
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2714
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2715
    millis := timeoutSeconds * 1000.
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2716
    [millis > 0] whileTrue:[
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2717
	otherConnections size > 0 ifTrue:[
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2718
	    otherConnections do:[:aConnection |
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2719
		aConnection canReadWithoutBlocking ifTrue:[
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2720
		    ^ aConnection
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2721
		]
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2722
	    ].
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2723
	].
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2724
	newConnection := self blockingAccept.
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2725
	newConnection notNil ifTrue:[^ newConnection].
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2726
	Delay waitForMilliseconds:20.
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2727
	millis := millis - 20.
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2728
    ].
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2729
    ^ nil.
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2730
!
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2731
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2732
pollingWaitForNewConnectionWithTimeout:timeoutSeconds
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2733
    "stupid MSDOS does not support select on sockets (sigh).
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2734
     Must poll here."
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2735
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2736
    |millis newConnection|
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2737
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2738
    timeoutSeconds notNil ifTrue:[
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2739
	millis := timeoutSeconds * 1000.
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
    [millis isNil or:[millis > 0]] whileTrue:[
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2742
	newConnection := self blockingAccept.
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2743
	newConnection notNil ifTrue:[^ newConnection].
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2744
	Delay waitForMilliseconds:20.
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2745
	millis notNil ifTrue:[
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2746
	    millis := millis - 20.
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2747
	]
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2748
    ].
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2749
    ^ nil.
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2750
!
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  2751
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2752
primAcceptOn:aSocket blocking:blocking
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2753
    "accept a connection on a server port (created with:'Socket>>onIPPort:')
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2754
     usage is: (Socket basicNew acceptOn:(Socket onIPPort:9999)).
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  2755
     Return the true if ok; false if not."
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2756
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2757
    |serverSocketFd addr addrLen domainClass|
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2758
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2759
    filePointer notNil ifTrue:[
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2760
        ^ self errorAlreadyOpen
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2761
    ].
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2762
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2763
    domain := aSocket domain.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2764
    socketType := aSocket type.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2765
    serverSocketFd := aSocket fileDescriptor.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2766
    serverSocketFd isNil ifTrue:[
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2767
        ^ self error:'invalid server socket'
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2768
    ].
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2769
    (serverSocketFd isMemberOf:SmallInteger) ifFalse:[
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2770
        ^ self error:'invalid server socket'
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2771
    ].
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2772
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2773
    domainClass := self class socketAddressClassForDomain:domain.
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2774
    domainClass isNil ifTrue:[
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2775
        ^ self error:'invalid (unsupported) domain'.
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2776
    ].
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2777
    addrLen := domainClass socketAddressSize.
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2778
    addr := domainClass new.
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2779
1120
b43bcd84bca8 gethostbyname beeds more than 64kb stack
martin
parents: 1119
diff changeset
  2780
%{  /* STACK: 100000 */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  2781
#ifndef NO_SOCKET
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2782
    FILE *fp;
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2783
    int flags;
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  2784
    SOCKET sock, newSock;
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2785
    union sockaddr_u sa;
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2786
    unsigned int alen, alen0;
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2787
    struct hostent *he ;
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2788
    char dotted[20] ;
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2789
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2790
    if (!__isSmallInteger(addrLen)) {
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2791
        DBGPRINTF(("SOCKET: bad addrLen\n"));
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2792
        RETURN (false);
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2793
    }
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2794
    alen0 = __intVal(addrLen);
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2795
    sock = SOCKET_FROM_FD(__intVal(serverSocketFd));
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2796
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2797
    if (blocking == false) {
1338
f81ec8de617f Use fcntl instead of ioctl when setting O_NONBLOCK
Stefan Vogel <sv@exept.de>
parents: 1336
diff changeset
  2798
# if defined(O_NONBLOCK) && defined(SET_NDELAY)
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2799
        flags = fcntl(sock, F_GETFL);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2800
        fcntl(sock, F_SETFL, flags | O_NONBLOCK);
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  2801
# endif
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2802
    }
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2803
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2804
# ifdef DO_WRAP_CALLS
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2805
    do {
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2806
        __threadErrno = 0;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2807
        alen = alen0;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2808
        newSock = STX_WSA_CALL3("accept", accept, sock, &sa, &alen);
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2809
    } while ((newSock < 0) && (__threadErrno == EINTR));
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2810
# else
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2811
    __BEGIN_INTERRUPTABLE__
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2812
    do {
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2813
        alen = alen0;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2814
        newSock = accept(sock, (struct sockaddr *) &sa, &alen);
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2815
    } while ((newSock < 0) && (errno == EINTR));
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2816
    __END_INTERRUPTABLE__
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2817
# endif
1541
61e23e2a40dd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1540
diff changeset
  2818
    DBGFPRINTF((stderr, "SOCKET: accept newSock=%d\n", newSock));
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2819
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2820
    if (blocking == false) {
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  2821
# if defined(O_NDELAY) && defined(SET_NDELAY)
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2822
        fcntl(sock, F_SETFL, flags);
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  2823
# endif
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2824
    }
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2825
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2826
    if (newSock < 0) {
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2827
        DBGPRINTF(("SOCKET: accept call failed errno=%d\n", errno));
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2828
        __INST(lastErrorNumber) = __MKSMALLINT(errno);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2829
        RETURN (false);
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2830
    }
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2831
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2832
    if (__isNonNilObject(addr)) {
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2833
        OBJ oClass;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2834
        int nInstVars, nInstBytes, objSize;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2835
        char *cp;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2836
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2837
        oClass = __qClass(addr);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2838
        if (! __isBytes(addr) ) {
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2839
            DBGPRINTF(("SOCKET: bad addr\n"));
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2840
            closesocket(newSock);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2841
            RETURN (false);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2842
        }
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2843
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2844
        nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2845
        nInstBytes = OHDR_SIZE + (nInstVars * sizeof(OBJ));
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2846
        objSize = __qSize(addr) - nInstBytes;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2847
        cp = (char *)__InstPtr(addr) + nInstBytes;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2848
        if (objSize < alen) {
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2849
            DBGPRINTF(("SOCKET: bad addr\n"));
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2850
            closesocket(newSock);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2851
            RETURN (false);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2852
        }
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2853
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2854
        /*
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2855
         * extract the partners address
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2856
         */
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2857
        bcopy((char *)&sa, cp, alen);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2858
        addrLen = __MKSMALLINT(alen);
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2859
    }
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2860
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  2861
    /*
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  2862
     * make it a FILE *
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2863
     */
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2864
# ifdef WIN32
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2865
    {
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2866
        HANDLE h;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2867
        int _fd = _open_osfhandle(newSock, 0);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2868
        fp = fdopen(_fd, "r+");
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2869
    }
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2870
# else
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2871
    fp = fdopen(newSock, "r+");
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2872
# endif
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2873
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2874
    if (! fp) {
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2875
        DBGPRINTF(("SOCKET: fdopen call failed\n"));
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2876
        __INST(lastErrorNumber) = __MKSMALLINT(errno);
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2877
#  ifdef DO_WRAP_CALLS
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2878
        {
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2879
          int ret;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2880
          do {
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2881
              __threadErrno = 0;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2882
              ret = STX_WSA_CALL1("closesocket", closesocket, newSock);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2883
          } while ((ret < 0) && (__threadErrno == EINTR));
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2884
        }
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2885
#  else
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2886
        closesocket(newSock);
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2887
#  endif
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2888
        DBGFPRINTF((stderr, "SOCKET: close (fdopen failed) (%d)\n", newSock));
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2889
        RETURN (false);
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  2890
    }
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2891
1035
5b0605675dc6 @globalfor classvar stuff
Stefan Vogel <sv@exept.de>
parents: 1029
diff changeset
  2892
    if (@global(FileOpenTrace) == true) {
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2893
# ifdef WIN32
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2894
        {
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2895
            HANDLE h;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2896
            int _fd = fileno(fp);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2897
            h = (HANDLE)_get_osfhandle(_fd);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2898
            fprintf(stderr, "fdopen [Socket] -> %x (fd: %d) (H: %x)\n", fp, _fd, h);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2899
        }
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2900
# else
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2901
        fprintf(stderr, "fdopen [Socket] -> %x (fd: %d)\n", fp, newSock);
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2902
# endif
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2903
    }
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  2904
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  2905
# ifdef BUGGY_STDIO_LIB
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  2906
    setbuf(fp, NULL);
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  2907
    __INST(buffered) = false;
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  2908
# endif
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  2909
1486
61ee314126a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1485
diff changeset
  2910
# if 0
61ee314126a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1485
diff changeset
  2911
    // The original code was:
61ee314126a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1485
diff changeset
  2912
    __INST(filePointer) = __MKOBJ((INT)fp); __STORESELF(filePointer);
61ee314126a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1485
diff changeset
  2913
    // but for that, gcc generates wrong code, which loads self (volatile) into
61ee314126a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1485
diff changeset
  2914
    // a register (bp), then calls __MKOBJ, then stores indirect bp.
61ee314126a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1485
diff changeset
  2915
    // That is wrong if a scavenge occurs in MKOBJ, as bp is now still pointing to the old
61ee314126a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1485
diff changeset
  2916
    // object.
61ee314126a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1485
diff changeset
  2917
# endif
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  2918
    {
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2919
        OBJ t;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2920
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2921
        t = __MKOBJ(fp);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2922
        __INST(filePointer) = t;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2923
        __STORE(self, t);
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  2924
    }
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  2925
#endif /* not NO_SOCKET */
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2926
%}.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2927
    mode := #readwrite.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2928
    Lobby register:self.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2929
    binary := false.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2930
    port := aSocket port.
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
  2931
1282
7e4ffdfd19f6 remove historic leftover
Claus Gittinger <cg@exept.de>
parents: 1280
diff changeset
  2932
    addr notNil ifTrue:[
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  2933
        peer := addr.
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
  2934
    ].
7e5f2f6b177d getHostByAddr - call is now done lazy, when the socket is asked for the peer
Claus Gittinger <cg@exept.de>
parents: 1186
diff changeset
  2935
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2936
    ^ true
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2937
!
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2938
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2939
waitForNewConnectionOrDataOnAny:otherConnections timeout:timeoutSeconds
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2940
    "suspend the current process, until either a new connection comes
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2941
     in at the receiver, or data arrives on any of the otherConnections.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2942
     For a new connection, an accept is performed and the new socket is returned.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2943
     For an old connection, that socket is returned.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2944
     In any case, the caller gets a socket to operate on as return value,
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2945
     or nil, if a timeout occured.
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  2946
     This method implements the inner wait-primitive of a multi-connection
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2947
     server application."
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2948
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2949
    " first, a quick check if data is already available "
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2950
1035
5b0605675dc6 @globalfor classvar stuff
Stefan Vogel <sv@exept.de>
parents: 1029
diff changeset
  2951
    |wasBlocked sema|
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2952
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2953
    OperatingSystem isMSWINDOWSlike ifTrue:[
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2954
	"/ stupid MSDOS does not support select on sockets (sigh)
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2955
	"/ Must poll here.
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2956
	^ self pollingWaitForNewConnectionOrDataOnAny:otherConnections timeout:timeoutSeconds
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2957
    ].
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  2958
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2959
    self canReadWithoutBlocking ifTrue:[
1170
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  2960
	^ self accept.
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2961
    ].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2962
    otherConnections do:[:aConnection |
1170
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  2963
	aConnection canReadWithoutBlocking ifTrue:[
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  2964
	    ^ aConnection
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  2965
	]
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2966
    ].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2967
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2968
    [
1170
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  2969
	"/ check again - prevent incoming interrupts from disturbing our setup
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  2970
	wasBlocked := OperatingSystem blockInterrupts.
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  2971
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  2972
	self canReadWithoutBlocking ifTrue:[
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  2973
	    ^ self accept.
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  2974
	].
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  2975
	otherConnections do:[:aConnection |
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  2976
	    aConnection canReadWithoutBlocking ifTrue:[
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  2977
		^ aConnection
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  2978
	    ]
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  2979
	].
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  2980
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  2981
	"/ nope - must wait.
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  2982
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  2983
	sema := Semaphore new name:'multiReadWait'.
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  2984
	otherConnections do:[:aConnection |
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  2985
	    Processor signal:sema onInput:(aConnection fileDescriptor).
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  2986
	].
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  2987
	Processor signal:sema onInput:(self fileDescriptor).
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  2988
	timeoutSeconds notNil ifTrue:[
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  2989
	    Processor signal:sema afterSeconds:timeoutSeconds
1170
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  2990
	].
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  2991
	Processor activeProcess state:#ioWait.
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  2992
	sema wait.
1136
cda53253bd0f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1120
diff changeset
  2993
    ] ensure:[
1170
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  2994
	sema notNil ifTrue:[Processor disableSemaphore:sema].
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  2995
	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2996
    ].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2997
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2998
    "/ see who it was ...
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2999
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3000
    self canReadWithoutBlocking ifTrue:[
1170
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3001
	^ self accept.
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3002
    ].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3003
    otherConnections do:[:aConnection |
1170
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3004
	aConnection canReadWithoutBlocking ifTrue:[
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3005
	    ^ aConnection
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3006
	]
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3007
    ].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3008
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3009
    "/ none - a timeout
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3010
    ^ nil
867
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3011
!
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3012
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3013
waitForNewConnectionWithTimeout:timeoutSeconds
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3014
    "suspend the current process, until a new connection comes
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3015
     in at the receiver or a timeout occurs.
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3016
     For a new connection, an accept is performed and the new socket is returned.
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3017
     Returns nil, if a timeout occured.
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  3018
     This method implements the inner wait-primitive of a single-connection
867
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3019
     server application."
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3020
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3021
    OperatingSystem isMSWINDOWSlike ifTrue:[
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3022
	"/ stupid MSDOS does not support select on sockets (sigh)
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3023
	"/ Must poll here.
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3024
	^ self pollingWaitForNewConnectionWithTimeout:timeoutSeconds
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3025
    ].
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3026
867
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3027
    (self readWaitWithTimeout:timeoutSeconds) ifTrue:[
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3028
	"/ a timeout occurred - no connection within timeout
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3029
	^ nil
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3030
    ].
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3031
    ^ self accept.
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3032
! !
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3033
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3034
!Socket methodsFor:'low level-connecting'!
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
  3035
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  3036
connectTo:hostOrPathName port:portNrOrName
1224
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3037
    "low level connect; connect to port, portNrOrNameOrNil on host, hostName.
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3038
     For backward compatibility, host may be also a string or a byteArray,
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3039
     but it is recommended to pass socketAddress instances.
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3040
71
claus
parents: 63
diff changeset
  3041
     Return true if ok, false otherwise.
1224
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3042
     The current process will block (but not the whole Smalltalk) until the connection is established.
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  3043
     See also: #connectTo:port:withTimeout: for a somewhat nicer interface."
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3044
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3045
    ^ self connectTo:hostOrPathName port:portNrOrName withTimeout:nil
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3046
!
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3047
1224
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3048
connectTo:hostOrPathNameOrSocketAddr port:portNrOrNameOrNil withTimeout:timeout
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3049
    "low level connect; connect to port, portNrOrNameOrNil on host, hostName.
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3050
     For backward compatibility, host may be also a string or a byteArray,
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3051
     but it is recommended to pass socketAddress instances.
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3052
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3053
     Return true if ok, false otherwise.
1224
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3054
     The current process will block (but not the whole Smalltalk) until the connection is established,
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3055
     or timeout millliseconds have passed."
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3056
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3057
    |isAsync err domainClass addr addrName|
430
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  3058
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3059
    filePointer isNil ifTrue:[
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3060
	^ self errorNotOpen
1224
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3061
    ].
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3062
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3063
    domainClass := self class socketAddressClassForDomain:domain.
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3064
    domainClass isNil ifTrue:[
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3065
	^ self error:'invalid (unsupported) domain'.
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3066
    ].
1224
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3067
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3068
    "/ backward compatibility: support for byteArray and string arg
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3069
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3070
    hostOrPathNameOrSocketAddr isString ifTrue:[
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3071
	addr := domainClass hostName:hostOrPathNameOrSocketAddr port:portNrOrNameOrNil.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3072
	addrName := hostOrPathNameOrSocketAddr.
1224
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3073
    ] ifFalse:[
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3074
	hostOrPathNameOrSocketAddr isByteArray ifFalse:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3075
	    ^ self error:'bad host (socketAddress) argument'
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3076
	].
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3077
	(hostOrPathNameOrSocketAddr isKindOf:SocketAddress) ifTrue:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3078
	    addr := hostOrPathNameOrSocketAddr.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3079
	    portNrOrNameOrNil notNil ifTrue:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3080
		addr port:portNrOrNameOrNil.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3081
	    ].
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3082
	] ifFalse:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3083
	    addr := domainClass hostAddress:hostOrPathNameOrSocketAddr port:portNrOrNameOrNil.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3084
	].
1224
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3085
    ].
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3086
1120
b43bcd84bca8 gethostbyname beeds more than 64kb stack
martin
parents: 1119
diff changeset
  3087
%{  /* STACK: 100000 */
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3088
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3089
#ifndef NO_SOCKET
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3090
    OBJ fp = __INST(filePointer);
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  3091
    union sockaddr_u sa;
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3092
    SOCKET sock;
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3093
    int a;
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3094
    int ret, oldFlags;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3095
    int on = 1;
115
a9d85df931c4 added Unix domain support
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  3096
    int sockaddr_size;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3097
1224
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3098
    if (!__isNonNilObject(addr) || !__isBytes(addr)) {
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3099
	DBGPRINTF(("SOCKET: invalid addrBytes\n"));
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3100
	RETURN (false);
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3101
    }
1224
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3102
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3103
    {
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  3104
	int sockAddrOffs, nIndex;
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3105
	OBJ cls;
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3106
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  3107
	sockAddrOffs = 0;
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3108
	if ((cls = __qClass(addr)) != @global(ByteArray))
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  3109
	    sockAddrOffs += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3110
	nIndex = __qSize(addr) - OHDR_SIZE;
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  3111
	sockaddr_size = nIndex - sockAddrOffs;
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  3112
	if (sockaddr_size > sizeof(sa)) {
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  3113
	    fprintf(stderr, "Socket: bad socketAddr\n");
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  3114
	    RETURN (false);
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  3115
	}
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  3116
	bcopy((__byteArrayVal(addr) + sockAddrOffs), &sa, sockaddr_size);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3117
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3118
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3119
    sock = SOCKET_FROM_FILE_OBJECT(fp);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3120
1224
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3121
# if defined(O_NONBLOCK)
1537
8eeeb380aaf5 *** empty log message ***
penk
parents: 1536
diff changeset
  3122
#  if !defined(WIN32)
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3123
    /*
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3124
     * set to non-blocking and wait later
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3125
     */
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3126
    oldFlags = fcntl(sock, F_GETFL, 0);
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3127
    /* on SUNOS4.x, would use fcntl(osfd, F_SETFL, flags | FNDELAY); */
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3128
    fcntl(sock, F_SETFL, oldFlags | O_NONBLOCK);
1537
8eeeb380aaf5 *** empty log message ***
penk
parents: 1536
diff changeset
  3129
#  endif
1224
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3130
# endif
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3131
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  3132
    /*
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  3133
     * connect
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3134
     */
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3135
# ifdef DO_WRAP_CALLS
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3136
    do {
1541
61e23e2a40dd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1540
diff changeset
  3137
	DBGFPRINTF((stderr, "SOCKET: connect...\n"));
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3138
	__threadErrno = 0;
1542
5f6c1dd993c4 NOINT flag for connect (WIN32).
penk
parents: 1541
diff changeset
  3139
	ret = STX_WSA_NOINT_CALL3("connect", connect, sock, &sa, sockaddr_size);
1541
61e23e2a40dd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1540
diff changeset
  3140
	DBGFPRINTF((stderr, "SOCKET: connect -> %d (%d)\n", ret, __threadErrno));
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3141
    } while ((ret < 0) && (__threadErrno == EINTR));
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3142
# else
81
claus
parents: 79
diff changeset
  3143
    __BEGIN_INTERRUPTABLE__
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3144
    do {
1504
92005eec5c9d fixed moving-object-when-interrupted-with-scavenge bugs;
Claus Gittinger <cg@exept.de>
parents: 1503
diff changeset
  3145
	ret = connect(sock, (struct sockaddr *)&sa, sockaddr_size);
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  3146
    } while ((ret < 0)
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3147
	     && ((errno == EINTR)
1224
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3148
# ifdef EAGAIN
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3149
		 || (errno == EAGAIN)
1224
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3150
# endif
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3151
		));
81
claus
parents: 79
diff changeset
  3152
    __END_INTERRUPTABLE__
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3153
#endif
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3154
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  3155
    if (ret < 0) {
1224
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3156
# if defined(EINPROGRESS) || defined(EALREADY)
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3157
	if (0
1224
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3158
#  ifdef EINPROGRESS
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  3159
	    || (errno == EINPROGRESS)
1224
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3160
#  endif
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3161
#  ifdef EALREADY
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3162
	    || (errno == EALREADY)
1224
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3163
#  endif
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3164
	) {
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3165
	    /*
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3166
	     * This was a nonblocking operation that will take some time.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3167
	     * Do a select on read to get informed when the operation is ready.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3168
	     */
1541
61e23e2a40dd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1540
diff changeset
  3169
	    DBGFPRINTF((stderr, "SOCKET: isAsync is true\n"));
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3170
	    isAsync = true;
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3171
	} else
1224
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3172
# endif /* EINPROGRESS or EALREADY */
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3173
	{
1541
61e23e2a40dd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1540
diff changeset
  3174
	    DBGFPRINTF((stderr, "SOCKET: connect failed ret=%d errno=%d __threadErrno=%d\n",
1540
1b511ad12399 *** empty log message ***
penk
parents: 1539
diff changeset
  3175
			ret, errno, __threadErrno ));
1224
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3176
# ifdef DUMP_ADDRESS
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3177
	    {
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3178
		char *cp = (char *)(&sa);
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3179
		int i;
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3180
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3181
		printf("address data:\n");
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3182
		for (i=0; i<sockaddr_size; i++) {
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3183
		    printf(" %02x\n", *cp++);
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3184
		}
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3185
	    }
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3186
# endif
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3187
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3188
	    RETURN (false);
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3189
	}
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3190
    }
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3191
1224
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3192
# if defined(O_NONBLOCK)
1537
8eeeb380aaf5 *** empty log message ***
penk
parents: 1536
diff changeset
  3193
#  if !defined(WIN32)
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3194
    fcntl(sock, F_SETFL, oldFlags);
1537
8eeeb380aaf5 *** empty log message ***
penk
parents: 1536
diff changeset
  3195
#  endif
1224
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3196
# endif
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3197
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3198
# else /* NO_SOCKET */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3199
    RETURN (false);
1224
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3200
# endif /* NO_SOCKET */
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  3201
%}.
430
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  3202
    isAsync == true ifTrue:[
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3203
	(self writeWaitWithTimeoutMs:timeout) ifTrue:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3204
	    "/ a timeout occured
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3205
	    "/ should cancel the connect?
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3206
	    ^ false.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3207
	].
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3208
	err := self getSocketError.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3209
	err ~~ 0 ifTrue:[
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3210
	    lastErrorNumber := err.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3211
	    ^ false.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3212
	].
430
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  3213
    ].
1224
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3214
    port := portNrOrNameOrNil.
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3215
    peer := addr.
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3216
    peerName := addrName.
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3217
    ^ true
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3218
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3219
    "
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3220
       |sock|
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3221
       sock := Socket newTCP.
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3222
       sock connectTo:'localhost' port:21 withTimeout:1000.
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3223
       sock
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3224
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3225
       |sock|
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3226
       sock := Socket newTCP.
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3227
       sock connectTo:'localhost' port:9876 withTimeout:2000.
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3228
       sock
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3229
    "
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3230
! !
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3231
1462
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  3232
!Socket methodsFor:'printing & storing'!
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  3233
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  3234
printOn:aStream
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  3235
    aStream nextPutAll:'Socket(protocol='.
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  3236
    protocol printOn:aStream.
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  3237
    aStream nextPutAll:' port='.
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  3238
    port printOn:aStream.
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  3239
    aStream nextPutAll:' peer='.
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  3240
    peer printOn:aStream.
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  3241
    aStream nextPutAll:')'.
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  3242
! !
5602fce52b42 squeak stuff
Claus Gittinger <cg@exept.de>
parents: 1413
diff changeset
  3243
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3244
!Socket methodsFor:'queries'!
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3245
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3246
domain
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3247
    "return the sockets addressing domain (i.e. #inet, #unix, #x25, #appletalk)"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3248
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3249
    ^ domain
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3250
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3251
1505
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
  3252
getFullSocketAddress
1535
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3253
    "implemented for swazoo project (primitive code cant be loaded as extension)
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3254
     Answer my own address (I am bound to this address).
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3255
     Note that this address may change after a connect or accept."
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3256
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3257
    |error domainClass addr addrLen|
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3258
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3259
    filePointer isNil ifTrue:[
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3260
        ^ self errorNotOpen
1535
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3261
    ].
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3262
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3263
    domainClass := self class socketAddressClassForDomain:domain.
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3264
    domainClass isNil ifTrue:[
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3265
        ^ self error:'invalid (unsupported) domain'.
1535
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3266
    ].
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3267
    addrLen := domainClass socketAddressSize.
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3268
    addr := domainClass new.
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3269
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3270
%{
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3271
#ifndef NO_SOCKET
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3272
    OBJ fp = __INST(filePointer);
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3273
    SOCKET sock;
1535
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3274
    int ret;
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3275
    union sockaddr_u sa;
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3276
    unsigned int alen, alen0;
1535
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3277
    char *addrP;
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3278
    int addrObjSize, nAddrInstBytes;
1535
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3279
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3280
    if (!__isSmallInteger(addrLen)) {
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3281
        DBGPRINTF(("SOCKET: bad addrLen\n"));
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3282
        error = @symbol(badArgument);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3283
        goto err;
1535
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3284
    }
1536
Claus Gittinger <cg@exept.de>
parents: 1535
diff changeset
  3285
    alen = alen0 = __intVal(addrLen);
1535
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3286
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3287
    if (!__isNonNilObject(addr) || !__isBytes(addr)) {
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3288
        DBGPRINTF(("SOCKET: bad addr\n"));
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3289
        error = @symbol(badArgument);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3290
        goto err;
1535
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3291
    }
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3292
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3293
    {
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3294
        OBJ addrClass;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3295
        int nAddrInstVars;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3296
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3297
        addrClass = __qClass(addr);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3298
        nAddrInstVars = __intVal(__ClassInstPtr(addrClass)->c_ninstvars);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3299
        nAddrInstBytes = OHDR_SIZE + (nAddrInstVars * sizeof(OBJ));
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3300
        addrObjSize = __qSize(addr) - nAddrInstBytes;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3301
        if (addrObjSize < alen0) {
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3302
            DBGPRINTF(("SOCKET: bad addr/alen\n"));
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3303
            error = @symbol(badArgument);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3304
            goto err;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3305
        }
1535
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3306
    }
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3307
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3308
    sock = SOCKET_FROM_FILE_OBJECT(fp);
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3309
# ifdef WIN32
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3310
    __threadErrno = 0;
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3311
# endif
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3312
    ret = getsockname(sock, (struct sockaddr *)&sa, &alen);
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3313
    if (ret < 0) {
1536
Claus Gittinger <cg@exept.de>
parents: 1535
diff changeset
  3314
# ifdef WIN32
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3315
        errno = WSAGetLastError();
1536
Claus Gittinger <cg@exept.de>
parents: 1535
diff changeset
  3316
# endif
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3317
        DBGPRINTF(("SOCKET: getsocketname failed ret=%d errno=%d\n", ret, errno));
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3318
        error = __MKSMALLINT(errno);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3319
        goto err;
1535
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3320
    }
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3321
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3322
    if (addrObjSize < alen) {
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3323
        DBGPRINTF(("SOCKET: bad addr\n"));
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3324
        error = @symbol(badArgument);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3325
        goto err;
1535
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3326
    }
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3327
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3328
    addrP = (char *)__InstPtr(addr) + nAddrInstBytes;
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3329
    bcopy((char *)&sa, addrP, alen);
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3330
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3331
    addrLen = __MKSMALLINT(alen);
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3332
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3333
err:;
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3334
#else /* NO_SOCKET */
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3335
    error = @symbol(notImplemented);
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3336
#endif /* NO_SOCKET */
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3337
%}.
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3338
    error notNil ifTrue:[
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3339
        ^ self errorReporter reportOn:error
1535
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3340
    ].
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3341
    ^ addr
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3342
!
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3343
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3344
getName
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3345
    "return the name; here, we return the ports name"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3346
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3347
    ^ port printString
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3348
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3349
102
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  3350
getPeer
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  3351
    "ST-80 compatibility: return an IPSocketAddress instance representing
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  3352
     my hostname/port combination.
155
fcf846c707b7 interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
  3353
     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
  3354
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
  3355
    peer isNil ifTrue:[
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3356
	peer := self class peerFromDomain:domain name:peerName port:port.
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3357
    ].
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
  3358
    ^ peer
102
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  3359
!
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  3360
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3361
getPeerName
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3362
    "return the peer name; thats the hostname (or dotted name) of the
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3363
     partners host after an accept."
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3364
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
  3365
    peerName isNil ifTrue:[
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3366
	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
  3367
    ].
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3368
    ^ peerName
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3369
!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3370
1146
71a9df78ba9e bad spelling
Stefan Vogel <sv@exept.de>
parents: 1136
diff changeset
  3371
getSocketAddress
71a9df78ba9e bad spelling
Stefan Vogel <sv@exept.de>
parents: 1136
diff changeset
  3372
    "implemented for swazoo project primitive code cant load as extension
1170
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3373
     answer my own address (I am bound to this address).
1146
71a9df78ba9e bad spelling
Stefan Vogel <sv@exept.de>
parents: 1136
diff changeset
  3374
     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
  3375
1535
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3376
    ^ self getFullSocketAddress hostAddress
f6aa0fc8c3cc getSocketAddress
Claus Gittinger <cg@exept.de>
parents: 1533
diff changeset
  3377
    "/ ^ self getFullSocketAddress copyFrom:5 to:8
1029
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  3378
!
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  3379
1146
71a9df78ba9e bad spelling
Stefan Vogel <sv@exept.de>
parents: 1136
diff changeset
  3380
getSocketAdress
1505
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
  3381
    "BAD SPELLING, of #getSocketAddress, kept for compatibility with swazoo"
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
  3382
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
  3383
    <resource: #obsolete>
1146
71a9df78ba9e bad spelling
Stefan Vogel <sv@exept.de>
parents: 1136
diff changeset
  3384
71a9df78ba9e bad spelling
Stefan Vogel <sv@exept.de>
parents: 1136
diff changeset
  3385
    ^ self getSocketAddress
71a9df78ba9e bad spelling
Stefan Vogel <sv@exept.de>
parents: 1136
diff changeset
  3386
!
71a9df78ba9e bad spelling
Stefan Vogel <sv@exept.de>
parents: 1136
diff changeset
  3387
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3388
isActive
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3389
    "return true, if the receiver has a connection"
81
claus
parents: 79
diff changeset
  3390
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3391
    ^ filePointer notNil
81
claus
parents: 79
diff changeset
  3392
!
claus
parents: 79
diff changeset
  3393
1110
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  3394
isConnected
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  3395
    "return true, if the receiver has a connection"
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  3396
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  3397
    ^ self isActive
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  3398
      and:[port notNil
1224
530a6f9723a1 use SocketAddress in #connect
Claus Gittinger <cg@exept.de>
parents: 1221
diff changeset
  3399
      and:[peerName notNil or:[peer notNil]]]
1110
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  3400
!
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  3401
1558
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3402
old_getFullSocketAddress
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3403
    "implemented for swazoo project primitive code cant load as extension
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3404
     answer my own address (I am bound to this address).
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3405
     Note that this address may change after connect or accept."
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3406
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3407
    |socketAddress error|
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3408
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3409
    filePointer isNil ifTrue:[
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3410
	^ self errorNotOpen
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3411
    ].
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3412
    socketAddress := ByteArray new:16.
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3413
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3414
%{
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3415
#ifndef NO_SOCKET
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3416
    OBJ fp = __INST(filePointer);
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3417
    SOCKET sock;
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3418
    int sockaddr_size;
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3419
    int ret;
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3420
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3421
    if (!__isNonNilObject(socketAddress) ||
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3422
	(__intVal(__ClassInstPtr(__qClass(socketAddress))->c_flags) & ARRAYMASK) != BYTEARRAY) {
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3423
	error = @symbol(badArgument1);
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3424
	goto err;
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3425
    }
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3426
    sockaddr_size = __byteArraySize(socketAddress);
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3427
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3428
    sock = SOCKET_FROM_FILE_OBJECT(fp);
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3429
    ret = getsockname(sock, (struct sockaddr *)__byteArrayVal(socketAddress), &sockaddr_size);
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3430
    if (ret < 0) {
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3431
# ifdef WIN32
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3432
	errno = WSAGetLastError();
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3433
# endif
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3434
	DBGPRINTF(("SOCKET: getsocketname failed errno=%d\n", errno));
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3435
	error = __MKSMALLINT(errno);
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3436
    }
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3437
err:;
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3438
#else /* NO_SOCKET */
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3439
    error = @symbol(notImplemented);
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3440
#endif /* NO_SOCKET */
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3441
%}.
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3442
    error notNil ifTrue:[
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3443
	^ self errorReporter reportOn:error
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3444
    ].
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3445
    ^ socketAddress
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3446
!
a563aac90660 No need to ask Socket>>#networkXXXOrderIsMSB, because the return value is
Stefan Vogel <sv@exept.de>
parents: 1542
diff changeset
  3447
71
claus
parents: 63
diff changeset
  3448
port
claus
parents: 63
diff changeset
  3449
    "return the port number (or name for unix-sockets) to which the socket is bound"
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3450
1505
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
  3451
"/ sometimes maybe we do am lazy fetch of the port
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
  3452
"/    port == 0 ifTrue:[ |p|
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
  3453
"/        p := self getPort.
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
  3454
"/        p notNil ifTrue:[
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
  3455
"/            port := p
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
  3456
"/        ]
Stefan Vogel <sv@exept.de>
parents: 1504
diff changeset
  3457
"/    ].
71
claus
parents: 63
diff changeset
  3458
    ^ port
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3459
!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3460
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3461
type
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3462
    "return the sockets connection type (i.e. #datagram, #stream etc)"
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3463
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3464
    ^ socketType
81
claus
parents: 79
diff changeset
  3465
! !
claus
parents: 79
diff changeset
  3466
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3467
!Socket methodsFor:'socket setup'!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3468
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3469
domain:domainArg type:typeArg
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3470
    "set up socket with domain and type.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3471
     This is a low level entry; no binding, listening or connect
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3472
     is done. Both arguments must be symbols from one of
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3473
     #inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3474
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3475
    ^ self domain:domainArg type:typeArg protocol:0 reuseAddress:true
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3476
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3477
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3478
domain:domainArg type:typeArg protocol:protocolNumber
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3479
    "set up socket with domain, type and protocol number.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3480
     This is a low level entry; no binding, listening or connect
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3481
     is done. Both arguments must be symbols from one of
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3482
     #inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3483
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3484
    ^ self domain:domainArg type:typeArg protocol:protocolNumber reuseAddress:true
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3485
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3486
    "
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3487
     Socket new domain:#inet type:#stream
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3488
     Socket new domain:#unix type:#stream
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3489
    "
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3490
!
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3491
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3492
domain:domainArg type:typeArg protocol:protocolNumber reuseAddress:reuse
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3493
    "set up socket with domain, type and protocol number.
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3494
     This is a low level entry; no binding, listening or connect
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3495
     is done. Both arguments must be symbols from one of
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3496
     #inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp.
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3497
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3498
     The reuse boolean argument controls if the SO_REUSEADDR socket option
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3499
     is to be set (to avoid the 'bind: address in use' error)."
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3500
1280
b973855bfe74 moved all socket constant queries from SocketHandle
Claus Gittinger <cg@exept.de>
parents: 1278
diff changeset
  3501
    |domainName domainCode typeCode|
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3502
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3503
    filePointer notNil ifTrue:[
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3504
	^ self errorAlreadyOpen
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3505
    ].
1280
b973855bfe74 moved all socket constant queries from SocketHandle
Claus Gittinger <cg@exept.de>
parents: 1278
diff changeset
  3506
    domainName := SocketAddress domainCodeFromName:domainArg.
b973855bfe74 moved all socket constant queries from SocketHandle
Claus Gittinger <cg@exept.de>
parents: 1278
diff changeset
  3507
    domainCode := OperatingSystem domainCodeOf:domainName.
b973855bfe74 moved all socket constant queries from SocketHandle
Claus Gittinger <cg@exept.de>
parents: 1278
diff changeset
  3508
    typeCode := OperatingSystem socketTypeCodeOf:typeArg.
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3509
%{
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3510
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3511
#ifndef NO_SOCKET
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3512
    FILE *fp;
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3513
    int dom, typ, pf, proto = 0;
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3514
    int on = 1;
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3515
    SOCKET sock;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3516
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  3517
    if (! __isSmallInteger(domainCode)) {
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3518
	DBGPRINTF(("SOCKET: bad domain\n"));
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3519
	RETURN ( nil );
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3520
    }
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  3521
    if (! __isSmallInteger(typeCode)) {
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3522
	DBGPRINTF(("SOCKET: bad type\n"));
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3523
	RETURN ( nil );
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3524
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3525
    if (protocolNumber != nil) {
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3526
	if (!__isSmallInteger(protocolNumber)) {
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3527
	    DBGPRINTF(("SOCKET: bad protocol\n"));
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3528
	    RETURN ( nil );
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3529
	}
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3530
	proto = __intVal(protocolNumber);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3531
    }
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  3532
81
claus
parents: 79
diff changeset
  3533
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3534
    /*
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3535
     * get address and protocol-family
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3536
     */
1280
b973855bfe74 moved all socket constant queries from SocketHandle
Claus Gittinger <cg@exept.de>
parents: 1278
diff changeset
  3537
    dom = __intVal(domainCode);
b973855bfe74 moved all socket constant queries from SocketHandle
Claus Gittinger <cg@exept.de>
parents: 1278
diff changeset
  3538
    typ = __intVal(typeCode);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3539
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3540
# ifdef SOCKET_BLOCKS
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3541
#  ifdef DO_WRAP_CALLS
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3542
    do {
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3543
	__threadErrno = 0;
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3544
	sock = STX_WSA_CALL3("socket", socket, dom, typ, proto);
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3545
    } while ((sock < 0) && (__threadErrno == EINTR));
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3546
#  else
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3547
    __BEGIN_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3548
    do {
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3549
	DBGPRINTF(("SOCKET: opening socket domain=%d type=%d proto=%d\n", dom, typ, proto));
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3550
	sock = socket(dom, typ, proto);
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3551
#   if defined(EPROTONOSUPPORT) /* for SGI */
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3552
	if ((proto != 0) && (sock < 0) && (errno == EPROTONOSUPPORT)) {
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3553
	    DBGPRINTF(("SOCKET: retry with UNSPEC protocol\n"));
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3554
	    proto = 0;
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3555
	    sock = socket(dom, typ, 0);
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3556
	}
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3557
#   endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3558
    } while ((sock < 0) && (errno == EINTR));
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3559
    __END_INTERRUPTABLE__
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3560
#  endif
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3561
# else
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3562
    sock = socket(dom, typ, proto);
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3563
#  if defined(EPROTONOSUPPORT) /* for SGI */
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3564
    if ((proto != 0) && (sock < 0) && (errno == EPROTONOSUPPORT)) {
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3565
	DBGPRINTF(("SOCKET: retry with UNSPEC protocol\n"));
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3566
	proto = 0;
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3567
	sock = socket(dom, typ, 0);
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3568
    }
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3569
#  endif
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3570
# endif
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3571
1541
61e23e2a40dd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1540
diff changeset
  3572
    DBGFPRINTF((stderr, "SOCKET: create newSock=%d\n", sock));
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3573
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3574
# ifdef WIN32
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3575
    if (sock == INVALID_SOCKET)
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3576
# else
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3577
    if (sock < 0)
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3578
# endif
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3579
    {
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3580
	DBGPRINTF(("SOCKET: socket(dom=%d typ=%d proto=%d) call failed errno=%d\n", dom, typ, proto, errno));
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3581
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3582
    } else {
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3583
# ifdef SO_REUSEADDR
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3584
	if (reuse == true) {
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3585
	    DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR\n"));
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3586
	    if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) {
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3587
		DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n"));
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3588
	    }
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3589
	}
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3590
# endif /* SO_REUSEADDR */
711
487b2bff9d31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 693
diff changeset
  3591
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3592
# ifdef 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
  3593
#  ifdef SO_LINGER
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3594
	{
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3595
	    struct linger l;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3596
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3597
	    l.l_onoff = 1;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3598
	    l.l_linger = 30;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3599
	    setsockopt( sock, SOL_SOCKET, SO_LINGER, &l, sizeof(l));
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3600
	}
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3601
#  endif
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3602
# endif
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3603
# ifdef WIN32
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3604
	/*
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3605
	 * make it blocking
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3606
	 */
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3607
	{
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3608
	    int zero = 0;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3609
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3610
	    ioctlsocket(sock, FIONBIO, &zero);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3611
	}
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3612
# endif
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  3613
	/*
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  3614
	 * make it a FILE *
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3615
	 */
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3616
# ifdef WIN32
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3617
	{
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3618
	    int _fd = _open_osfhandle(sock, 0);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3619
	    fp = fdopen(_fd, "r+");
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3620
	}
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3621
# else
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3622
	fp = fdopen(sock, "r+");
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3623
# endif
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3624
	if (! fp) {
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3625
	    DBGPRINTF(("SOCKET: fdopen call failed\n"));
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3626
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3627
# ifdef DO_WRAP_CALLS
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3628
	    { int ret;
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3629
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3630
	      do {
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3631
		__threadErrno = 0;
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3632
		ret = STX_WSA_CALL1("closesocket", closesocket, sock);
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3633
	      } while ((ret < 0) && (__threadErrno == EINTR));
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3634
	    }
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3635
# else
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3636
	    __BEGIN_INTERRUPTABLE__
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3637
	    closesocket(sock);
1541
61e23e2a40dd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1540
diff changeset
  3638
	    DBGFPRINTF((stderr, "SOCKET: close (fdopen failed) (%d)\n", sock));
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3639
	    __END_INTERRUPTABLE__
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3640
# endif
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3641
	} else {
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3642
	    if (@global(FileOpenTrace) == true) {
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3643
		fprintf(stderr, "fdopen [Socket] -> %x\n", fp);
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3644
	    }
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3645
1486
61ee314126a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1485
diff changeset
  3646
# if 0
61ee314126a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1485
diff changeset
  3647
	    // The original code was:
61ee314126a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1485
diff changeset
  3648
	    __INST(filePointer) = __MKOBJ((INT)fp); __STORESELF(filePointer);
61ee314126a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1485
diff changeset
  3649
	    // but for that, gcc generates wrong code, which loads self (volatile) into
61ee314126a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1485
diff changeset
  3650
	    // a register (bp), then calls __MKOBJ, then stores indirect bp.
61ee314126a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1485
diff changeset
  3651
	    // That is wrong if a scavenge occurs in MKOBJ, as bp is now still pointing to the old
61ee314126a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1485
diff changeset
  3652
	    // object.
61ee314126a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1485
diff changeset
  3653
# endif
1485
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  3654
	    {
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  3655
		OBJ t;
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  3656
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  3657
		t = __MKOBJ(fp);
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  3658
		__INST(filePointer) = t;
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  3659
		__STORE(self, t);
d8578cf3504b gcc3.3.1 insn-scheduler bug workaround
Claus Gittinger <cg@exept.de>
parents: 1474
diff changeset
  3660
	    }
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3661
	}
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3662
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3663
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3664
%}.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3665
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3666
    "all ok?"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3667
    filePointer notNil ifTrue:[
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3668
	domain := domainArg.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3669
	socketType := typeArg.
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3670
	Lobby register:self.
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3671
    ] ifFalse:[
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3672
	^ nil
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3673
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3674
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3675
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3676
     Socket new domain:#inet type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3677
     Socket new domain:#unix type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3678
    "
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3679
! !
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3680
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3681
!Socket methodsFor:'specials'!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3682
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3683
readWaitWithTimeoutMs:timeoutMilliSeconds
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3684
    "suspend the current process, until a new connection comes
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3685
     in at the receiver or a timeout occurs.
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3686
     For a new connection, an accept is performed and the new socket is returned.
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3687
     Returns nil, if a timeout occured.
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3688
     This method implements the inner wait-primitive of a single-connection
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3689
     server application."
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3690
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3691
    |millis|
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3692
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3693
    OperatingSystem isMSWINDOWSlike ifTrue:[
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3694
	"/ stupid MSDOS does not support select on sockets (sigh)
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3695
	"/ Must poll here.
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3696
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3697
	 millis := timeoutMilliSeconds.
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3698
	[millis isNil or:[millis > 0]] whileTrue:[
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3699
	    self canReadWithoutBlocking ifTrue:[^ false].
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3700
	    Delay waitForMilliseconds:20.
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3701
	    millis notNil ifTrue:[
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3702
		millis := millis - 20.
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3703
	    ]
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3704
	].
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3705
	^ true.
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3706
    ].
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3707
    ^ super readWaitWithTimeoutMs:timeoutMilliSeconds
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3708
!
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3709
1335
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3710
receiveBufferSize
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3711
    "get the send buffer size - for special applications only.
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3712
     Not all operatingSystems offer this functionality
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3713
     (returns nil, if unsupported)"
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3714
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3715
    filePointer isNil ifTrue:[
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3716
        ^ self errorNotOpen
1335
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
%{
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3719
#if defined(SO_RCVBUF) && defined(SOL_SOCKET)
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3720
    {
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3721
        OBJ fp = __INST(filePointer);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3722
        SOCKET sock;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3723
        int opt;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3724
        unsigned int size;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3725
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3726
        sock = SOCKET_FROM_FILE_OBJECT(fp);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3727
        if (getsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *)&opt, &size) >= 0) {
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3728
            RETURN( __MKSMALLINT(opt) );
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3729
        }
1335
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3730
    }
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3731
#endif
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3732
%}.
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3733
    ^ nil
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3734
!
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3735
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3736
receiveBufferSize:size
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3737
    "set the receive buffer size - for special applications only.
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3738
     Not all operatingSystems offer this functionality
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3739
     (returns false, if unsupported)"
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3740
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3741
    filePointer isNil ifTrue:[
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3742
	^ self errorNotOpen
1335
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3743
    ].
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3744
%{
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3745
#if defined(SO_RCVBUF) && defined(SOL_SOCKET)
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3746
    if (__isSmallInteger(size)) {
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3747
	OBJ fp = __INST(filePointer);
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3748
	SOCKET sock;
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3749
	int opt;
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3750
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3751
	sock = SOCKET_FROM_FILE_OBJECT(fp);
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3752
	opt = __intVal(size);
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3753
	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
  3754
	    RETURN(true);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3755
	}
1335
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3756
    }
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3757
#endif
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3758
%}.
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3759
    ^ false
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3760
!
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3761
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3762
receiveTimeout:seconds
71
claus
parents: 63
diff changeset
  3763
    "set the receive timeout - for special applications only.
claus
parents: 63
diff changeset
  3764
     Not all operatingSystems offer this functionality
claus
parents: 63
diff changeset
  3765
     (returns false, if unsupported)"
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3766
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3767
    |millis|
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3768
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3769
    filePointer isNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3770
	^ self errorNotOpen
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3771
    ].
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3772
    millis := (seconds * 1000) rounded.
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3773
%{
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3774
#if defined(SO_RCVTIMEO) && defined(SOL_SOCKET) && defined(HZ)
58
bd6753bf0401 *** empty log message ***
claus
parents: 51
diff changeset
  3775
    if (__isSmallInteger(millis)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3776
	OBJ fp = __INST(filePointer);
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3777
	SOCKET sock;
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3778
	int opt;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3779
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3780
	sock = SOCKET_FROM_FILE_OBJECT(fp);
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3781
	opt = __intVal(millis) / (1000 / HZ);
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3782
	if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (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
  3783
	    RETURN(true);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3784
	}
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
1335
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3791
sendBufferSize
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3792
    "get the send buffer size - for special applications only.
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3793
     Not all operatingSystems offer this functionality
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3794
     (returns nil, if unsupported)"
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3795
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3796
    filePointer isNil ifTrue:[
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3797
        ^ self errorNotOpen
1335
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3798
    ].
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3799
%{
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3800
#if defined(SO_SNDBUF) && defined(SOL_SOCKET)
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3801
    {
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3802
        OBJ fp = __INST(filePointer);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3803
        SOCKET sock;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3804
        int opt;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3805
        unsigned int size;
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3806
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3807
        sock = SOCKET_FROM_FILE_OBJECT(fp);
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3808
        if (getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *)&opt, &size) >= 0) {
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3809
            RETURN( __MKSMALLINT(opt) );
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
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
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3817
sendBufferSize:size
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3818
    "set the send buffer size - for special applications only.
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3819
     Not all operatingSystems offer this functionality
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3820
     (returns false, if unsupported)"
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3821
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3822
    filePointer isNil ifTrue:[
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3823
	^ self errorNotOpen
1335
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3824
    ].
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3825
%{
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3826
#if defined(SO_SNDBUF) && defined(SOL_SOCKET)
0fafb78d7a80 sockopt utilities added
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
  3827
    if (__isSmallInteger(size)) {
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3828
	OBJ fp = __INST(filePointer);
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3829
	SOCKET sock;
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3830
	int opt;
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3831
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
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
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3843
sendTimeout:seconds
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3844
    "set the send timeout - for special applications only.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3845
     Not all operatingSystems offer this functionality
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3846
     (returns false, if unsupported)"
81
claus
parents: 79
diff changeset
  3847
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3848
    |millis|
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3849
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3850
    filePointer isNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3851
	^ self errorNotOpen
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3852
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3853
    millis := (seconds * 1000) rounded.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3854
%{
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3855
#if defined(SO_SNDTIMEO) && defined(SOL_SOCKET) && defined(HZ)
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3856
    if (__isSmallInteger(millis)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3857
	OBJ fp = __INST(filePointer);
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3858
	SOCKET sock;
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3859
	int opt;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3860
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3861
	sock = SOCKET_FROM_FILE_OBJECT(fp);
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3862
	opt = __intVal(millis) / (1000 / HZ);
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3863
	if (setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (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
  3864
	    RETURN(true);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3865
	}
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3866
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3867
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3868
%}.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3869
    ^ false
1340
eb9b1f1340e5 setTCP_NODELAY
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
  3870
!
eb9b1f1340e5 setTCP_NODELAY
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
  3871
1342
7c9682a7183d setTCP_CORK
Claus Gittinger <cg@exept.de>
parents: 1341
diff changeset
  3872
setTCPCork:aBoolean
7c9682a7183d setTCP_CORK
Claus Gittinger <cg@exept.de>
parents: 1341
diff changeset
  3873
    "enable/disable TCP_CORK (do-not-send-partial-frames)
7c9682a7183d setTCP_CORK
Claus Gittinger <cg@exept.de>
parents: 1341
diff changeset
  3874
     For special applications only.
7c9682a7183d setTCP_CORK
Claus Gittinger <cg@exept.de>
parents: 1341
diff changeset
  3875
     Not all OperatingSystems offer this functionality
7c9682a7183d setTCP_CORK
Claus Gittinger <cg@exept.de>
parents: 1341
diff changeset
  3876
     (returns false, if unsupported)"
7c9682a7183d setTCP_CORK
Claus Gittinger <cg@exept.de>
parents: 1341
diff changeset
  3877
7c9682a7183d setTCP_CORK
Claus Gittinger <cg@exept.de>
parents: 1341
diff changeset
  3878
    filePointer isNil ifTrue:[
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3879
	^ self errorNotOpen
1342
7c9682a7183d setTCP_CORK
Claus Gittinger <cg@exept.de>
parents: 1341
diff changeset
  3880
    ].
7c9682a7183d setTCP_CORK
Claus Gittinger <cg@exept.de>
parents: 1341
diff changeset
  3881
%{
7c9682a7183d setTCP_CORK
Claus Gittinger <cg@exept.de>
parents: 1341
diff changeset
  3882
#if defined(IPPROTO_TCP) && defined(TCP_CORK)
7c9682a7183d setTCP_CORK
Claus Gittinger <cg@exept.de>
parents: 1341
diff changeset
  3883
    int onOff = (aBoolean == true);
7c9682a7183d setTCP_CORK
Claus Gittinger <cg@exept.de>
parents: 1341
diff changeset
  3884
7c9682a7183d setTCP_CORK
Claus Gittinger <cg@exept.de>
parents: 1341
diff changeset
  3885
    if ((aBoolean == true) || (aBoolean == false)) {
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3886
	OBJ fp = __INST(filePointer);
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3887
	SOCKET sock;
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3888
	int onOff = (aBoolean == true);
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3889
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3890
	sock = SOCKET_FROM_FILE_OBJECT(fp);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3891
	if (setsockopt(sock, IPPROTO_TCP, TCP_CORK, (char *)&onOff, sizeof(int)) >= 0) {
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3892
	    RETURN(true);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3893
	}
1342
7c9682a7183d setTCP_CORK
Claus Gittinger <cg@exept.de>
parents: 1341
diff changeset
  3894
    }
7c9682a7183d setTCP_CORK
Claus Gittinger <cg@exept.de>
parents: 1341
diff changeset
  3895
#endif
7c9682a7183d setTCP_CORK
Claus Gittinger <cg@exept.de>
parents: 1341
diff changeset
  3896
%}.
7c9682a7183d setTCP_CORK
Claus Gittinger <cg@exept.de>
parents: 1341
diff changeset
  3897
    ^ false
7c9682a7183d setTCP_CORK
Claus Gittinger <cg@exept.de>
parents: 1341
diff changeset
  3898
!
7c9682a7183d setTCP_CORK
Claus Gittinger <cg@exept.de>
parents: 1341
diff changeset
  3899
1341
fff1730b546c setTCP_NODELAY
Claus Gittinger <cg@exept.de>
parents: 1340
diff changeset
  3900
setTCPNoDelay:aBoolean
1340
eb9b1f1340e5 setTCP_NODELAY
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
  3901
    "enable/disable TCP_NODELAY (i.e. disable/enable the Nagle algorithm)
eb9b1f1340e5 setTCP_NODELAY
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
  3902
     For special applications only.
eb9b1f1340e5 setTCP_NODELAY
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
  3903
     Not all OperatingSystems offer this functionality
eb9b1f1340e5 setTCP_NODELAY
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
  3904
     (returns false, if unsupported)"
eb9b1f1340e5 setTCP_NODELAY
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
  3905
eb9b1f1340e5 setTCP_NODELAY
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
  3906
    filePointer isNil ifTrue:[
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3907
	^ self errorNotOpen
1340
eb9b1f1340e5 setTCP_NODELAY
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
  3908
    ].
eb9b1f1340e5 setTCP_NODELAY
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
  3909
%{
1342
7c9682a7183d setTCP_CORK
Claus Gittinger <cg@exept.de>
parents: 1341
diff changeset
  3910
#if defined(IPPROTO_TCP) && defined(TCP_NODELAY)
1340
eb9b1f1340e5 setTCP_NODELAY
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
  3911
    int onOff = (aBoolean == true);
eb9b1f1340e5 setTCP_NODELAY
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
  3912
eb9b1f1340e5 setTCP_NODELAY
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
  3913
    if ((aBoolean == true) || (aBoolean == false)) {
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3914
	OBJ fp = __INST(filePointer);
1539
c0e89dcb58b3 non blocking stuff done right here;
Claus Gittinger <cg@exept.de>
parents: 1538
diff changeset
  3915
	SOCKET sock;
1343
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3916
	int onOff = (aBoolean == true);
cc3bed115c0a definitions cleanup with stxOSDefs.h
penk
parents: 1342
diff changeset
  3917
1529
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3918
	sock = SOCKET_FROM_FILE_OBJECT(fp);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3919
	if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *)&onOff, sizeof(int)) >= 0) {
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3920
	    RETURN(true);
911273d090c1 Re-unified Win32 and Unix code into single Socket.st.
Claus Gittinger <cg@exept.de>
parents: 1505
diff changeset
  3921
	}
1340
eb9b1f1340e5 setTCP_NODELAY
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
  3922
    }
eb9b1f1340e5 setTCP_NODELAY
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
  3923
#endif
eb9b1f1340e5 setTCP_NODELAY
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
  3924
%}.
eb9b1f1340e5 setTCP_NODELAY
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
  3925
    ^ false
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3926
! !
82
claus
parents: 81
diff changeset
  3927
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  3928
!Socket class methodsFor:'documentation'!
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  3929
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  3930
version
1560
50c1e959ede8 Avoid compiler signed/unsigned warnings (gcc4)
Stefan Vogel <sv@exept.de>
parents: 1558
diff changeset
  3931
    ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.220 2005-06-28 13:25:08 stefan Exp $'
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  3932
! !