Socket.st
author Claus Gittinger <cg@exept.de>
Mon, 17 Jan 2000 12:20:18 +0100
changeset 867 56ca0cc52fa7
parent 859 b71ab9e436cb
child 869 a6e5cbe9f558
permissions -rw-r--r--
category renamining
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
63
7dd3d5b7877e *** empty log message ***
claus
parents: 58
diff changeset
    13
NonPositionableExternalStream subclass:#Socket
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
    14
	instanceVariableNames:'domain socketType protocol port serviceName peerName'
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
    15
	classVariableNames:''
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
    16
	poolDictionaries:''
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
    17
	category:'Streams-External'
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    18
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    19
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    20
!Socket primitiveDefinitions!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    21
%{
444
9ba31a1fba38 always unbuffered on linux
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
    22
9ba31a1fba38 always unbuffered on linux
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
    23
#ifdef LINUX
9ba31a1fba38 always unbuffered on linux
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
    24
# define BUGGY_STDIO_LIB
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    25
# include <linux/version.h>
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    26
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    27
# ifndef KERNEL_VERSION
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    28
#  define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    29
# endif
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    30
#endif /* LINUX */
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    31
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    32
#include <stdio.h>
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    33
#include <errno.h>
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    34
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
    35
#define UNIX_LIKE
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
    36
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
    37
#if defined(transputer)
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
    38
# undef UNIX_LIKE
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
    39
# define NO_SOCKET
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
    40
#endif
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
    41
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    42
/*
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    43
 * which protocols can we support ?
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    44
 */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    45
#ifndef NO_SOCKET
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    46
# define WANT__AF_INET
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    47
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    48
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    49
#ifdef UNIX_LIKE
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    50
# define WANT__AF_UNIX
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    51
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    52
563
23a6b265bdd0 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 559
diff changeset
    53
#ifdef __VMS__
23a6b265bdd0 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 559
diff changeset
    54
# undef WANT__AF_UNIX
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
    55
# define WANT_AF_DECnet
563
23a6b265bdd0 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 559
diff changeset
    56
#endif
23a6b265bdd0 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 559
diff changeset
    57
527
f48fd11817e2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 526
diff changeset
    58
#ifdef LINUX
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    59
# ifndef LINUX_VERSION_CODE
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    60
   /* PRE 2.0 Linux kernel. */
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    61
# else
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    62
#  if LINUX_VERSION_CODE < KERNEL_VERSION(2,0,0)
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    63
   /* PRE 2.0 Linux kernel. */
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    64
#  else
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    65
#   if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    66
#    define WANT__AF_APPLETALK
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    67
#    define xxWANT__AF_X25
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    68
#    define xxWANT__AF_AX25
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    69
#    define xxWANT__AF_IPX
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    70
#    define WANT__AF_INET6 */
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    71
#   endif /* >= 2.1.0 */
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    72
#  endif /* pre 2.0.0 */
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    73
# endif /* pre 2.0.0 */
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    74
#endif /* LINIX */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    75
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
    76
#ifdef solaris2_0
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
    77
# define xxxWANT__AF_DECNET
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
    78
#endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
    79
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    80
#ifdef LINUX
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    81
/* kludge to avoid some redefines ... */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    82
# define _ARPA_NAMESER_H
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    83
# define _NETINET_TCP_H
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    84
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    85
739
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    86
#if !defined(NO_SOCKET)
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    87
# include <fcntl.h>
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    88
# include <sys/types.h>
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    89
# define _SYS_TYPES_H_INCLUDED_
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    90
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    91
# if defined(IRIS) && !defined(IRIX5)
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    92
   /* no socket.h on 4.0.5h ?!?!? */
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    93
#  ifndef AF_UNIX
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    94
#   define AF_UNIX 1
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    95
#  endif
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    96
#  ifndef AF_INET
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    97
#   define AF_INET 2
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    98
#  endif
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
    99
739
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   100
#  ifndef SOCK_STREAM
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   101
#   define SOCK_STREAM 1
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   102
#  endif
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   103
#  ifndef SOCK_DGRAM
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   104
#   define SOCK_DGRAM  2
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   105
#  endif
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   106
#  ifndef SOCK_RAW
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   107
#   define SOCK_RAW    3
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   108
#  endif
656
fcd2139d83a5 borland-C support
Claus Gittinger <cg@exept.de>
parents: 653
diff changeset
   109
# else
739
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   110
#  include <sys/socket.h>
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   111
# endif
739
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   112
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   113
# ifdef NEXT3
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   114
#  include <netinet/in_systm.h>
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   115
# endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   116
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   117
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   118
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   119
/*
528
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   120
 * see what we want ...
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   121
 */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   122
#ifdef WANT__AF_UNIX
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   123
# ifdef AF_UNIX
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   124
#  ifndef PF_UNIX
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   125
#   define PF_UNIX AF_UNIX
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   126
#  endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   127
# endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   128
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   129
# undef AF_UNIX
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   130
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   131
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   132
#ifdef WANT__AF_INET
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   133
# ifdef AF_INET
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   134
#  ifndef PF_INET
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   135
#   define PF_INET AF_INET
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   136
#  endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   137
# endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   138
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   139
# undef AF_INET
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   140
#endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   141
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   142
#ifdef WANT__AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   143
# ifdef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   144
#  ifndef PF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   145
#   define PF_INET6 AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   146
#  endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   147
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   148
#else
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   149
# undef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   150
#endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   151
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   152
#ifdef WANT__AF_DECnet
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   153
# ifdef AF_DECnet
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   154
#  ifndef PF_DECnet
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   155
#   define PF_DECnet AF_DECnet
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   156
#  endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   157
# endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   158
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   159
# undef AF_DECnet
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   160
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   161
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   162
#ifdef WANT__AF_APPLETALK
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   163
# ifdef AF_APPLETALK
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   164
#  ifndef PF_APPLETALK
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   165
#   define PF_APPLETALK AF_APPLETALK
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   166
#  endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   167
# endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   168
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   169
# undef AF_APPLETALK
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   170
#endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   171
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
   172
#ifdef WANT__AF_X25     /* X.25 */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   173
# ifdef AF_X25
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   174
#  ifndef PF_X25
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   175
#   define PF_X25 AF_X25
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   176
#  endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   177
# endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   178
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   179
# undef AF_X25
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   180
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   181
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
   182
#ifdef WANT__AF_NS      /* Xerox XNS */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   183
# ifdef AF_NS
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   184
#  ifndef PF_NS
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   185
#   define PF_NS AF_NS
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   186
#  endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   187
# endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   188
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   189
# undef AF_NS
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   190
#endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   191
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
   192
#ifdef WANT__AF_SNA     /* IBM SNA */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   193
# ifdef AF_SNA
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   194
#  ifndef PF_SNA
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   195
#   define PF_SNA AF_SNA
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   196
#  endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   197
# endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   198
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   199
# undef AF_SNA
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   200
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   201
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
   202
#ifdef WANT__AF_RAW     /* RAW packets */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   203
# ifdef AF_RAW
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   204
#  ifndef PF_RAW
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   205
#   define PF_RAW AF_RAW
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   206
#  endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   207
# endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   208
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   209
# undef AF_RAW
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   210
#endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   211
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
   212
#ifdef WANT__AF_ISO     /* ? */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   213
# ifdef AF_ISO
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   214
#  ifndef PF_ISO
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   215
#   define PF_ISO AF_ISO
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   216
#  endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   217
# endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   218
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   219
# undef AF_ISO
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   220
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   221
823
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   222
#ifdef WANT__AF_NETBIOS /* NETBIOS */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   223
# ifdef AF_NETBIOS
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   224
#  ifndef PF_NETBIOS
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   225
#   define PF_NETBIOS AF_NETBIOS
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   226
#  endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   227
# endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   228
#else
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
   229
# undef AF_NETBIOS
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   230
#endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   231
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   232
#ifdef WANT__AF_CCITT /* ? */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   233
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   234
#  ifndef PF_CCITT
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   235
#   define PF_CCITT AF_CCITT
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   236
#  endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   237
# endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   238
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   239
# undef AF_CCITT
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   240
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   241
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   242
#ifdef WANT__AF_IPX /* Novell IPX */
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   243
# ifdef AF_IPX
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   244
#  ifndef PF_IPX
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   245
#   define PF_IPX AF_IPX
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   246
#  endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   247
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   248
#else
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
   249
# undef AF_IPX
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   250
#endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   251
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   252
#ifdef WANT__AF_AX25 /* Amateur Radio AX.25 */
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   253
# ifdef AF_AX25
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   254
#  ifndef PF_AX25
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   255
#   define PF_AX25 AF_AX25
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   256
#  endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   257
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   258
#else
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
   259
# undef AF_AX25
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   260
#endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   261
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   262
#ifdef WANT__AF_NETROM /* Amateur Radio NET/ROM */
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   263
# ifdef AF_NETROM
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   264
#  ifndef PF_NETROM
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   265
#   define PF_NETROM AF_NETROM
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   266
#  endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   267
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   268
#else
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
   269
# undef AF_NETROM
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   270
#endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   271
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   272
#ifdef WANT__AF_BRIDGE /* multiprotocol bridge */
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   273
# ifdef AF_BRIDGE
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   274
#  ifndef PF_BRIDGE
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   275
#   define PF_BRIDGE AF_BRIDGE
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   276
#  endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   277
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   278
#else
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
   279
# undef AF_BRIDGE
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   280
#endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   281
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   282
#ifdef WANT__AF_BSC /* BISYNC 2780/3780 */
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   283
# ifdef AF_BSC
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   284
#  ifndef PF_BSC
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   285
#   define PF_BSC AF_BSC
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   286
#  endif
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   287
# endif
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   288
#else
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   289
# undef AF_BSC
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   290
#endif
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   291
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   292
#ifdef WANT__AF_ROSE /* Amateur Radio X.25 PLP */
814
d0e45218532d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
   293
# ifdef AF_ROSE
d0e45218532d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
   294
#  ifndef PF_ROSE
d0e45218532d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
   295
#   define PF_ROSE AF_ROSE
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   296
#  endif
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   297
# endif
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   298
#else
814
d0e45218532d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
   299
# undef AF_ROSE
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   300
#endif
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   301
823
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   302
#ifdef WANT__AF_ATM /* ATM Services */
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   303
# ifdef AF_ATM
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   304
#  ifndef PF_ATM
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   305
#   define PF_ATM AF_ATM
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   306
#  endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   307
# endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   308
#else
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   309
# undef AF_ATM
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   310
#endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   311
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   312
#ifdef WANT__AF_BAN /* BAN / VINES IP Services */
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   313
# ifdef AF_BAN
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   314
#  ifndef PF_BAN
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   315
#   define PF_BAN AF_BAN
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   316
#  endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   317
# endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   318
#else
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   319
# undef AF_BAN
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   320
#endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   321
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   322
#ifdef WANT__AF_VOICEVIEW /* VoiceView Services W95 only */
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   323
# ifdef AF_VOICEVIEW
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   324
#  ifndef PF_VOICEVIEW
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   325
#   define PF_VOICEVIEW AF_VOICEVIEW
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   326
#  endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   327
# endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   328
#else
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   329
# undef AF_VOICEVIEW
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   330
#endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   331
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   332
528
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   333
/*
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   334
 * now, include what we have to ...
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   335
 * undef support, if no include file is present
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   336
 * (or I dont know yet, where to find it)
528
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   337
 */
739
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   338
823
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   339
#ifdef AF_UNIX
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   340
# ifdef UNIX
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   341
#  include <sys/un.h>
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   342
# else
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   343
#  undef AF_UNIX
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   344
# endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   345
#endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   346
739
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   347
#ifdef AF_INET
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   348
# include <netdb.h>
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   349
# if defined(LINUX) && defined(AF_INET6)
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   350
#  include <linux/in.h>
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   351
# else
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   352
#  include <netinet/in.h>
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   353
# endif
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   354
# if ! (defined(SYSV3) && defined(mc88k))
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   355
#  include <netinet/tcp.h>
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   356
# endif
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   357
#endif
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   358
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   359
#ifdef AF_INET6
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   360
# if defined(LINUX) && defined(__GLIBC__)
739
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   361
#  include <linux/in6.h>
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   362
# else
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   363
#  undef AF_INET6
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   364
# endif
739
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   365
#endif
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   366
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   367
#ifdef AF_APPLETALK
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   368
# ifdef LINUX
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   369
#  include <asm/types.h>
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   370
#  include <linux/atalk.h>
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   371
# else
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   372
#  undef AF_APPLETALK
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   373
# endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   374
#endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   375
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   376
#ifdef AF_DECNET
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   377
# ifdef solaris2_0
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   378
#  include <X11/dni8.h>
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   379
# else
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   380
#  undef AF_DECNET
465
3673e44dbd2f remove windows ^M characters
Claus Gittinger <cg@exept.de>
parents: 464
diff changeset
   381
# endif
739
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   382
#endif
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   383
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   384
#ifdef AF_X25
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   385
# ifdef LINUX
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   386
#  include <linux/x25.h>
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   387
# else
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   388
#  undef AF_X25
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   389
# endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   390
#endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   391
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   392
#ifdef AF_AX25
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   393
# ifdef LINUX
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   394
#  include <linux/ax25.h>
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   395
# else
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   396
#  undef AF_AX25
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   397
# endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   398
#endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   399
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   400
#ifdef AF_IPX
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   401
# ifdef LINUX
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   402
#  include <linux/ipx.h>
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   403
# else
823
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   404
#  ifdef WIN32
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   405
#   include <wsipx.h>
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   406
#  else
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   407
#   undef AF_IPX
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   408
#  endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   409
# endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   410
#endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   411
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   412
#ifdef AF_NETBIOS
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   413
# ifdef WIN32
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   414
#  include <wsnetbs.h>
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   415
# else
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   416
#  undef AF_NETBIOS
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   417
# endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   418
#endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   419
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   420
#ifdef AF_ATM
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   421
# ifdef WIN32
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   422
#  include <ws2atm.h>
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   423
# else
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   424
#  undef AF_ATM
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   425
# endif
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   426
#endif
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   427
823
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   428
#ifdef AF_BAN
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   429
# ifdef WIN32
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   430
#  include <wsvns.h>
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   431
# else
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   432
#  undef AF_BAN
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   433
# endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   434
#endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   435
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   436
#ifdef AF_VOICEVIEW
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   437
# ifdef WIN32
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   438
#  include <wsvv.h>
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   439
# else
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   440
#  undef AF_VOICEVIEW
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   441
# endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   442
#endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   443
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   444
#undef AF_SNA     /* not yet implemented */
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   445
#undef AF_RAW     /* not yet implemented */
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   446
#undef AF_NETROM  /* not yet implemented */
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   447
#undef AF_BRIDGE  /* not yet implemented */
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   448
#undef AF_BSC     /* not yet implemented */
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   449
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   450
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   451
/*
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   452
 * see what is leftOver
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   453
 */
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   454
union sockaddr_u {
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   455
#ifdef AF_UNIX
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   456
	struct sockaddr_un un;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   457
#endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   458
#ifdef AF_INET
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   459
	struct sockaddr_in in;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   460
#endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   461
#ifdef AF_INET6
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   462
	struct sockaddr_in6 in6;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   463
#endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   464
#ifdef AF_APPLETALK
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   465
	struct sockaddr_at at;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   466
#endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   467
#ifdef AF_DECNET
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   468
	struct sockaddr_dn dn;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   469
#endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   470
#ifdef AF_X25
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   471
	struct sockaddr_x25 x25;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   472
#endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   473
#ifdef AF_AX25
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   474
	struct sockaddr_ax25 ax25;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   475
#endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   476
#ifdef AF_IPX
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   477
	struct sockaddr_ipx ipx;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   478
#endif
823
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   479
#ifdef AF_NETBIOS
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   480
	struct sockaddr_nb nb;
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   481
#endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   482
#ifdef AF_ATM
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   483
	struct sockaddr_atm atm;
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   484
#endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   485
#ifdef AF_BAN
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   486
	struct sockaddr_vns vns;
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   487
#endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   488
#ifdef AF_VOICEVIEW
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   489
	struct sockaddr_vv vv;
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   490
#endif
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   491
};
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   492
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   493
739
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   494
#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
   495
# define USE_H_ERRNO
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   496
#endif
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   497
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   498
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   499
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   500
/*
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   501
 * on some systems errno is a macro ... check for it here
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   502
 */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   503
#ifndef errno
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   504
 extern errno;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   505
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   506
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   507
#ifdef USE_H_ERRNO
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   508
# ifndef h_errno
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   509
 extern h_errno;
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   510
# endif
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   511
#endif
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   512
720
967fad20a8f1 newest stdio uses __new
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   513
#ifdef xxLINUX
967fad20a8f1 newest stdio uses __new
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   514
/* use inline string macros ... */
967fad20a8f1 newest stdio uses __new
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   515
# define __STRINGDEFS__
967fad20a8f1 newest stdio uses __new
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   516
# include <linuxIntern.h>
967fad20a8f1 newest stdio uses __new
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   517
#endif
967fad20a8f1 newest stdio uses __new
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   518
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   519
/*
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   520
 * gethostbyname seems to have trouble
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   521
 * sometimes, if interrupted while a request
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   522
 * is on its way the name server.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   523
 * (although specified in the man-page, 
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   524
 * a check on TRY_AGAIN fails on iris)
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   525
 */
692
85d64f84be0c oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
   526
#ifdef LINUX
85d64f84be0c oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
   527
85d64f84be0c oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
   528
# define GETHOSTBYNAME(hp, name) \
85d64f84be0c oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
   529
	hp = gethostbyname((char *) name);
85d64f84be0c oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
   530
85d64f84be0c oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
   531
# define GETHOSTBYADDR(hp, addr, alen, af) \
85d64f84be0c oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
   532
	hp = gethostbyaddr(addr, alen, af);
85d64f84be0c oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
   533
85d64f84be0c oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
   534
#else
85d64f84be0c oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
   535
693
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   536
# ifdef IRIX5_3
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   537
#  define GETHOSTBYNAME(hp, name) \
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   538
	do { \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   539
	    __BEGIN_INTERRUPTABLE__  \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   540
	    hp = gethostbyname((char *) name); \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   541
	    __END_INTERRUPTABLE__ \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   542
	} while ((hp == NULL) && \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   543
		 ((h_errno == TRY_AGAIN) || (errno == ECONNREFUSED)));
650
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   544
693
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   545
#  define GETHOSTBYADDR(hp, addr, alen, af) \
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
   546
	do { \
650
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   547
	    __BEGIN_INTERRUPTABLE__ \
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   548
	    hp = gethostbyaddr(addr, alen, af); \
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   549
	    __END_INTERRUPTABLE__ \
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   550
	} while ((hp == NULL) && \
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   551
		((h_errno == TRY_AGAIN) || (errno == ECONNREFUSED)));
693
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   552
# else
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   553
#  ifdef USE_H_ERRNO
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   554
#   define GETHOSTBYNAME(hp, name) \
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   555
	do { \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   556
	    __BEGIN_INTERRUPTABLE__  \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   557
	    hp = gethostbyname((char *) name); \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   558
	    __END_INTERRUPTABLE__ \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   559
	} while ((hp == NULL) && (h_errno == TRY_AGAIN));
650
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   560
693
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   561
#   define GETHOSTBYADDR(hp, addr, alen, af) \
650
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   562
	do { \
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   563
	    __BEGIN_INTERRUPTABLE__  \
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   564
	    hp = gethostbyaddr(addr, alen, af); \
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   565
	    __END_INTERRUPTABLE__ \
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   566
	} while ((hp == NULL) && (h_errno == TRY_AGAIN));
693
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   567
#  else
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   568
#   define GETHOSTBYNAME(hp, name) \
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   569
	__BEGIN_INTERRUPTABLE__  \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   570
	hp = gethostbyname((char *) name); \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   571
	__END_INTERRUPTABLE__ 
650
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   572
693
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   573
#   define GETHOSTBYADDR(hp, addr, alen, af) \
650
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   574
	__BEGIN_INTERRUPTABLE__ \
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   575
	hp = gethostbyaddr(addr, alen, af); \
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   576
	__END_INTERRUPTABLE__
693
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   577
#  endif
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   578
# endif
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   579
#endif
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   580
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   581
#ifdef DEBUG
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   582
# define DBGPRINTF(x)    { if (__debugging__) printf x; }
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
   583
# define DBGFPRINTF(x)   { if (__debugging__) fprintf x; }
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   584
#else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   585
# define DBGPRINTF(x)    /* as nothing */
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
   586
# define DBGFPRINTF(x)   /* as nothing */
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   587
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   588
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   589
%}
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   590
! !
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   591
511
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   592
!Socket primitiveVariables!
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   593
%{
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   594
static int __debugging__ = 0;
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   595
%}
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   596
! !
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   597
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
   598
!Socket class methodsFor:'documentation'!
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   599
31
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   600
copyright
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   601
"
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   602
 COPYRIGHT (c) 1992 by Claus Gittinger
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   603
	      All Rights Reserved
31
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   604
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   605
 This software is furnished under a license and may be used
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   606
 only in accordance with the terms of that license and with the
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   607
 inclusion of the above copyright notice.   This software may not
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   608
 be provided or otherwise made available to, or used by, any
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   609
 other person.  No title to or ownership of the software is
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   610
 hereby transferred.
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   611
"
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   612
!
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   613
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   614
documentation
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   615
"
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
   616
    This class provides access to sockets for interprocess communication.
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   617
    The message protocol is preliminary, until someone tells me how
31
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   618
    other smalltalk's socket interfaces look like.
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   619
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   620
    Currently, only IP and UNIX domain sockets are supported.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   621
    Code for appletalk is included, but was never tested ...
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   622
    More may be added in the future.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   623
    (the code is prepared for things like SNA or decNet;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   624
     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
   625
     Implementing those is pretty straight forward, once the address
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   626
     data structures are known.)
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
   627
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   628
    Due to historic reasons (I started this class, before I got hold of some
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   629
    code using ST-80 Sockets i.e. RemoteInvocation), there is some old interface
71
claus
parents: 63
diff changeset
   630
    still provided. 
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
   631
    This will vanish; use the #family:type: or #newTCPxxx and #newUDPxxx interfaces,
71
claus
parents: 63
diff changeset
   632
    together with the bind/listen and accept calls,
claus
parents: 63
diff changeset
   633
    which are meant to be compatible to ST-80's UnixSocketAccessor interface.
claus
parents: 63
diff changeset
   634
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
   635
    ST/X does not use IPSocketAddress, UDSocketAddress etc; all addressing
71
claus
parents: 63
diff changeset
   636
    is done by passing appropriate string- or byteArray objects containing
claus
parents: 63
diff changeset
   637
    the addresses. This may change, too.
claus
parents: 63
diff changeset
   638
claus
parents: 63
diff changeset
   639
    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
   640
	  (mhmh - how can I test those ?)
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
   641
	  change to raise more signals on errors.
529
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   642
	  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
   643
		 net please test this (and send bug fixes ...)
259
6d36f3ac42a2 documentation
Claus Gittinger <cg@exept.de>
parents: 220
diff changeset
   644
6d36f3ac42a2 documentation
Claus Gittinger <cg@exept.de>
parents: 220
diff changeset
   645
    [author:]
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   646
	Claus Gittinger
48
18b9353c9d07 *** empty log message ***
claus
parents: 44
diff changeset
   647
"
18b9353c9d07 *** empty log message ***
claus
parents: 44
diff changeset
   648
!
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   649
48
18b9353c9d07 *** empty log message ***
claus
parents: 44
diff changeset
   650
examples
18b9353c9d07 *** empty log message ***
claus
parents: 44
diff changeset
   651
"
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   652
    example (get help info from an nntp server):
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   653
									[exBegin]
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   654
	|sock host|
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   655
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   656
	host := OperatingSystem getEnvironment:'NNTPSERVER'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   657
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   658
	sock := Socket newTCPclientToHost:host port:'nntp'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   659
	Transcript showCR:sock nextLine.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   660
	sock buffered:false.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   661
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   662
	sock nextPutAll:'HELP'; cr.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   663
	[:exit |
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   664
	    |line|
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   665
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   666
	    line := sock nextLine.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   667
	    line = '.' ifTrue:[exit value:nil].
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   668
	    Transcript showCR:line.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   669
	] loopWithExit.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   670
	sock close
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   671
									[exEnd]
209
2152fceba563 finger example
Claus Gittinger <cg@exept.de>
parents: 208
diff changeset
   672
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   673
209
2152fceba563 finger example
Claus Gittinger <cg@exept.de>
parents: 208
diff changeset
   674
    example (connect to finger daemon, get users entry):
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   675
									[exBegin]
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   676
	|sock host entry|
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   677
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   678
	host := OperatingSystem getHostName.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   679
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   680
	sock := Socket newTCPclientToHost:host port:'finger'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   681
	sock isNil ifTrue:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   682
	    self warn:'no finger daemon is running'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   683
	    ^ self
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   684
	].
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   685
	sock useCRLF:true.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   686
	sock buffered:false.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   687
	sock isNil ifTrue:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   688
	    Transcript showCR:'cannot connect to local finger daemon'
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   689
	] ifFalse:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   690
	    sock nextPutAll:(OperatingSystem getLoginName).
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   691
	    sock cr.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   692
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   693
	    entry := sock nextLine.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   694
	    Transcript showCR:entry.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   695
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   696
	    sock close
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   697
	]
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   698
									[exEnd]
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   699
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   700
    example (connect to an ftp server):
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   701
									[exBegin]
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   702
	|sock host|
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   703
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   704
	host := OperatingSystem getHostName.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   705
	sock := Socket newTCPclientToHost:host port:'ftp'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   706
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   707
	sock buffered:false.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   708
	Transcript showCR:sock nextLine.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   709
	sock nextPutAll:('USER ' , 'anonymous'); cr.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   710
	Transcript showCR:sock nextLine.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   711
	sock nextPutAll:('PASS ' , 'fooBar'); cr.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   712
	Transcript showCR:sock nextLine.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   713
	sock nextPutAll:'LIST'; cr.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   714
	Transcript showCR:sock nextLine.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   715
	sock close.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   716
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   717
	'dont know enough of the ftp protocol to continue here ...'
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   718
									[exEnd]
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   719
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   720
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
   721
    example (connect to an snmp server [UDP]):
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   722
									[exBegin]
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   723
	|sock port|
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   724
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   725
	sock := Socket newUDP.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   726
	port := Socket portOfService:'snmp'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   727
	sock connectTo:(OperatingSystem getHostName) port:port.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   728
	sock buffered:false.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   729
	Transcript showCR:'got it'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   730
	sock close.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   731
									[exEnd]
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   732
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   733
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   734
    example (await connection from a client and read some data):
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   735
	|connectSock sock|
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   736
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   737
	connectSock := Socket newTCPserverAtPort:9998.  
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   738
	connectSock isNil ifTrue:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   739
	    Transcript showCR:'socket setup failed.'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   740
	] ifFalse:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   741
	    Transcript showCR:'listen ..'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   742
	    (connectSock listenFor:5) ifFalse:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   743
		Transcript showCR:'listen failed.'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   744
	    ] ifTrue:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   745
		Transcript showCR:'wait'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   746
		connectSock readWait.  
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   747
		Transcript showCR:'accept'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   748
		sock := connectSock accept.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   749
		sock isNil ifTrue:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   750
		    Transcript showCR:'accept failed.'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   751
		] ifFalse:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   752
		    sock buffered:false.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   753
		    Transcript showCR:'server: got it'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   754
		    'can now do transfer via sock'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   755
		    Transcript showCR:'read'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   756
		    Transcript showCR:('got: ' , sock nextLine).
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   757
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   758
		    Transcript showCR:'close'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   759
		    sock close
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   760
		].
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   761
		connectSock close.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   762
	    ]
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   763
	]
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   764
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   765
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   766
    example (connect to above server and send some data):
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   767
	|sock|
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   768
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   769
	sock := Socket newTCPclientToHost:(OperatingSystem getHostName) port:9998.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   770
	sock isNil ifTrue:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   771
	    Transcript showCR:'nope'
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   772
	] ifFalse:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   773
	    sock buffered:false.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   774
	    Transcript showCR:'client: got it'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   775
	    'can now do transfer via sock'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   776
	    Transcript showCR:'sending <hello>'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   777
	    sock nextPutLine:'hello'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   778
	    sock close
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   779
	]
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
   780
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
   781
    example: UNIX domain socket (await connection from a client and read some data):
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
   782
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   783
	|connectSock sock|
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   784
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   785
	'/tmp/ud_socket' asFilename remove.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   786
	connectSock := Socket newUNIXserverAt:'/tmp/ud_socket'.  
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   787
	connectSock isNil ifTrue:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   788
	    Transcript showCR:'socket setup failed.'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   789
	] ifFalse:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   790
	    Transcript showCR:'listen ..'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   791
	    (connectSock listenFor:5) ifFalse:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   792
		Transcript showCR:'listen failed.'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   793
	    ] ifTrue:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   794
		Transcript showCR:'wait'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   795
		connectSock buffered:false.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   796
		connectSock readWait.  
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   797
		Transcript showCR:'accept'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   798
		sock := connectSock accept.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   799
		sock isNil ifTrue:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   800
		    Transcript showCR:'accept failed.'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   801
		] ifFalse:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   802
		    sock buffered:false.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   803
		    Transcript showCR:'server: got it'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   804
		    'can now do transfer via sock'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   805
		    Transcript showCR:'read'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   806
		    Transcript showCR:('got: ' , sock nextLine).
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   807
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   808
		    Transcript showCR:'close'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   809
		    sock close
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   810
		].
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   811
		connectSock close.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   812
	    ]
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   813
	]
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
   814
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
   815
118
142d5c273454 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 117
diff changeset
   816
    example (connect to above server and send some data;
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   817
	     Notice, this fails, if above server code is executed in the same ST/X image
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   818
		     (at least on LINUX), since the OS does not correctly handle
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   819
		     a connect from within an interrupted accept system call
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   820
		     On SGI's SVR4, this works ok
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   821
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   822
	|sock|
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   823
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   824
	sock := Socket newUNIXclientTo:'/tmp/ud_socket'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   825
	sock isNil ifTrue:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   826
	    Transcript showCR:'nope'
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   827
	] ifFalse:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   828
	    sock buffered:false.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   829
	    Transcript showCR:'client: got it'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   830
	    'can now do transfer via sock'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   831
	    Transcript showCR:'sending <hello>'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   832
	    sock nextPutLine:'hello'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   833
	    sock close
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   834
	]
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   835
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   836
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   837
    example: pingWalk (try to ping hosts on the local network)
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   838
									[exBegin]
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   839
	|myName myAddress list top hosts walkProcess port|
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   840
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   841
	myName := OperatingSystem getHostName.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   842
	myAddress := Socket ipAddressOfHost:myName.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   843
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   844
	port := Socket portOfService:'echo'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   845
	port isNil ifTrue:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   846
	    self error:'dont know echo port'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   847
	    ^ self
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   848
	].
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   849
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   850
	top := StandardSystemView new.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   851
	top label:'PING net walk'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   852
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   853
	list := ScrollableView for:ListView in:top.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   854
	list origin:0.0@0.0 corner:1.0@1.0.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   855
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   856
	top openAndWait.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   857
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   858
	walkProcess := [
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   859
	    |l low hi direction tryHostID dottedName hostName conn addr|
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   860
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   861
	    l := SortedCollection new.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   862
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   863
	    ' only works with type C-net
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   864
	      the code below could simply do 1 to:254 do:[:hostID }
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   865
	      but, to probe likely hosts earlier, the probing is done
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   866
	      ping-pong like around my ip-address (assuming, that other machines
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   867
	      have numbers around my own)'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   868
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   869
	    low := hi := (myAddress at:4).
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   870
	    direction := 1.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   871
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   872
	    [low > 0 or:[hi < 255]] whileTrue:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   873
		direction > 0 ifTrue:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   874
		    hi := hi + 1.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   875
		    tryHostID := hi.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   876
		    direction := -1.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   877
		] ifFalse:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   878
		    low := low - 1.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   879
		    tryHostID := low.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   880
		    direction := 1.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   881
		].
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   882
		(tryHostID between:1 and:254) ifTrue:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   883
		    dottedName := (myAddress at:1) printString
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   884
				  , '.' , (myAddress at:2) printString
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   885
				  , '.' , (myAddress at:3) printString
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   886
				  , '.' , tryHostID printString.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   887
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   888
		    top label:'PING net walk - trying ' , dottedName.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   889
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   890
		    top windowGroup withCursor:Cursor wait do:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   891
			conn := Socket newTCPclientToHost:dottedName port:port withTimeout:1000.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   892
			conn notNil ifTrue:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   893
			    addr := Socket ipAddressOfHost:dottedName.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   894
			    hostName := Socket hostWithIpAddress:addr.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   895
			    hostName isNil ifTrue:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   896
				hostName :='?'
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   897
			    ].
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   898
			    l add:(dottedName paddedTo:15 with:Character space) 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   899
				   , ' ' 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   900
				   , (hostName paddedTo:15 with:Character space)
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   901
				   , ' up & reachable'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   902
			    list list:l.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   903
			    conn close.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   904
			]
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   905
		    ].
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   906
		].
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   907
	    ].
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   908
	    top label:'PING reachable hosts'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   909
	] forkAt:(Processor userBackgroundPriority).
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   910
	walkProcess name:'ping net walker'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   911
									[exEnd]
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   912
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   913
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   914
	This example creates a simple UDP server that accepts 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   915
	single packets from anybody and broadcasts them to all 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   916
	clients that have connected so far. 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   917
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   918
									[exBegin]
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   919
	| socket address buffer msgSize clients |
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   920
	clients := Set new.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   921
	address := IPSocketAddress new.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   922
	buffer := String new: 1024.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   923
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   924
	socket := self newUDPserverAtPort: 6666.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   925
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   926
	Transcript showCR: 'server starting'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   927
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   928
	[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   929
	    [true] whileTrue: [
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   930
		(socket readWaitWithTimeoutMs: 200) ifFalse: [
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   931
		    msgSize := socket 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   932
			    receiveFrom: address 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   933
			    buffer: buffer 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   934
			    start: 1 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   935
			    for: buffer size.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   936
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   937
		    clients add: address copy.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   938
		    clients do: [ :clientAddress | 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   939
			    socket 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   940
				    sendTo: clientAddress 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   941
				    buffer: buffer 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   942
				    start: 1 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   943
				    for: msgSize]]
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   944
	    ]
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   945
	] valueNowOrOnUnwindDo:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   946
	    Transcript showCR: 'server shutting down'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   947
	    socket close
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   948
	]
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   949
									[exEnd]
817
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
   950
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
   951
   send a datagram to above server:
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   952
									[exBegin]
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   953
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   954
	| socket address buffer host msg |
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   955
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   956
	host := Dialog
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   957
		request: 'What is the name of the server''s host?'
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   958
		initialAnswer: 'localhost'.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   959
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   960
	socket := self newUDP.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   961
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   962
	address := IPSocketAddress hostName: host port: 6666.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   963
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   964
	buffer := ByteArray new: 1000.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   965
	[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   966
	    [(msg := Dialog request: 'Say something') isEmpty] whileFalse:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   967
		| replySize stream |
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   968
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   969
		socket writeWait.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   970
		stream := buffer writeStream.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   971
		stream nextPutAll: msg.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   972
		socket sendTo:address buffer:buffer start:1 for:stream position.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   973
		socket readWait.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   974
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   975
		replySize := socket receiveFrom:address buffer:buffer.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   976
		replySize > 0 ifTrue: [
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   977
		    Transcript cr; nextPutAll: 'Server acknowledged: '.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   978
		    Transcript show: ((buffer copyFrom: 1 to: replySize) asString) 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   979
		]
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   980
	    ]
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   981
	] valueNowOrOnUnwindDo: [socket close].
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   982
	Transcript cr
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   983
									[exEnd]
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   984
"
817
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
   985
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   986
! !
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   987
867
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
   988
!Socket class methodsFor:'Compatibility ST80'!
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
   989
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   990
family:domainSymbol type:typeSymbol
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   991
    "create a socket for domain and type - ST80 simply uses a different name.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   992
     Domain must be one of the symbols: #inet, #unix, #ns, #appletalk or #ns;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   993
     Type must be #stream, #datagram or #raw
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
   994
811
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   995
     XXX: currently only the #inet and #unix domains is supported"
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
   996
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   997
    ^ self domain:domainSymbol type:typeSymbol
51
24f978f1d849 *** empty log message ***
claus
parents: 48
diff changeset
   998
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   999
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1000
     Socket family:#inet type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1001
     Socket family:#inet type:#datagram
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1002
     Socket family:#unix type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1003
    "
867
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  1004
!
115
a9d85df931c4 added Unix domain support
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1005
617
6ccbaa111a74 added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 604
diff changeset
  1006
getHostname
6ccbaa111a74 added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 604
diff changeset
  1007
    "return the computers hostname string"
6ccbaa111a74 added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 604
diff changeset
  1008
6ccbaa111a74 added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 604
diff changeset
  1009
    ^ OperatingSystem getHostName
6ccbaa111a74 added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 604
diff changeset
  1010
6ccbaa111a74 added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 604
diff changeset
  1011
    "Created: / 27.2.1998 / 02:32:17 / cg"
6ccbaa111a74 added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 604
diff changeset
  1012
!
6ccbaa111a74 added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 604
diff changeset
  1013
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1014
sockStream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1015
    "return the type code for stream sockets"
51
24f978f1d849 *** empty log message ***
claus
parents: 48
diff changeset
  1016
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1017
    ^ #stream
44
b4db396f9255 EINTR stuff
claus
parents: 42
diff changeset
  1018
! !
b4db396f9255 EINTR stuff
claus
parents: 42
diff changeset
  1019
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  1020
!Socket class methodsFor:'Signal constants'!
21
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1021
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1022
brokenConnectionSignal
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1023
    "return the signal used to tell broken connections.
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1024
     Since in unix, this is the same as the broken pipe signal,
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1025
     return that one.
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1026
     (for other Operatingsystems, this may change ..)"
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1027
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1028
    ^ PipeStream brokenPipeSignal
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1029
! !
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1030
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  1031
!Socket class methodsFor:'debugging'!
71
claus
parents: 63
diff changeset
  1032
claus
parents: 63
diff changeset
  1033
debug:aBoolean
claus
parents: 63
diff changeset
  1034
    "turn on/off internal debugprints.
claus
parents: 63
diff changeset
  1035
     This method is for ST/X debugging only and
claus
parents: 63
diff changeset
  1036
     may  be removed in later versions"
claus
parents: 63
diff changeset
  1037
claus
parents: 63
diff changeset
  1038
%{  /* NOCONTEXT */
claus
parents: 63
diff changeset
  1039
claus
parents: 63
diff changeset
  1040
    __debugging__ = (aBoolean == true);
claus
parents: 63
diff changeset
  1041
%}
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  1042
    "
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  1043
     Socket debug:true
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  1044
     Socket debug:false
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  1045
    "
71
claus
parents: 63
diff changeset
  1046
! !
claus
parents: 63
diff changeset
  1047
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  1048
!Socket class methodsFor:'easy tcp/ip instance creation'!
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1049
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1050
connectTo:service on:host
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1051
    "standard & easy client setup: 
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1052
	create new client tcp socket, bind and connect; 
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1053
	return the socket.
811
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1054
     The thread block (interruptable), until the connection is 
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1055
     established."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1056
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1057
    ^ (self new) for:host port:(self portOfService:service).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1058
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1059
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1060
     Socket connectTo:9995 on:'clam'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1061
     Socket connectTo:'finger' on:'clam'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1062
     Socket connectTo:'ftp' on:'clam'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1063
     Socket connectTo:'nntp' on:(OperatingSystem getEnvironment:'NNTPSERVER')
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1064
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1065
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1066
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1067
provide:service
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1068
    "standard & easy server setup: 
811
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1069
     create a new TCP server socket providing a service."
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1070
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1071
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1072
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1073
    newSock := (self new) for:nil port:(self portOfService:service).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1074
    newSock notNil ifTrue:[
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1075
	newSock listenFor:5.
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1076
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1077
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1078
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1079
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1080
     Socket provide:9995
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1081
     (Socket provide:9996) accept
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1082
     Socket provide:'nntp'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1083
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1084
! !
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1085
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  1086
!Socket class methodsFor:'general instance creation'!
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1087
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1088
domain:domainSymbol type:type
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1089
    "create a socket for domain and type -
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1090
     neither any connect nor binding is done.
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1091
     Domain must be one of the symbols: 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1092
	#inet, #unix, #appletalk, #decnet, #xns, ...;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1093
     Type must be:
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1094
	#stream, #datagram or #raw
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1095
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1096
     XXX: currently only the #inet domain is supported"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1097
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1098
    ^ self new domain:domainSymbol type:type
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1099
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1100
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1101
     Socket domain:#inet type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1102
     Socket domain:#inet type:#datagram
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1103
     Socket domain:#unix type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1104
     Socket domain:#appletalk type:#stream
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1105
     Socket domain:#decnet type:#stream
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1106
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1107
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1108
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1109
new
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1110
    "create a TCP socket"
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1111
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1112
    ^ super new buffered:false 
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1113
!
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1114
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1115
newTCP
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1116
    "create a TCP socket - no binding or other setup is done,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1117
     neither connect nor connect-wait is done."
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
    ^ self new domain:#inet type:#stream 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1120
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1121
    "Socket newUDP"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1122
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1123
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1124
newTCP:aServiceOrNil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1125
    "create a TCP socket for a service -
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1126
     neither connect nor connect-wait is done."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1127
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1128
    |newSock|
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
    newSock := self newTCP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1131
    (newSock notNil and:[aServiceOrNil notNil]) ifTrue:[
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1132
	(newSock bindTo:(self portOfService:aServiceOrNil) address:nil) ifFalse:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1133
	    ^ nil
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1134
	]
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1135
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1136
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1137
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1138
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1139
    "Socket newTCP:'nntp'"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1140
    "Socket newTCP:9995"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1141
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1142
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1143
newTCPclientToAddress:aHostAddress port:aService
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1144
    "create a new TCP client socket connecting to a service.
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1145
     Return a socket instance if ok, nil on failure.
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1146
     Block until a connection is established (but only the current thread;
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1147
     not the whole smalltalk). 
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1148
     See also: #newTCPclientToAddress:port:withTimeout:"
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1149
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1150
    ^ self newTCPclientToAddress:aHostAddress port:aService withTimeout:nil
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1151
!
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1152
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1153
newTCPclientToAddress:aHostAddress port:aService withTimeout:millis
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1154
    "create a new TCP client socket connecting to a service.
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1155
     Return a socket instance if ok, nil on failure.
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1156
     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
  1157
     and return nil."
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1158
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1159
    ^ self newTCPclientToHost:aHostAddress port:aService withTimeout:millis
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1160
!
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1161
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1162
newTCPclientToHost:hostname port:aService
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1163
    "create a new TCP client socket connecting to a service.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1164
     Return a socket instance if ok, nil on failure.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1165
     Block until a connection is established (but only the current thread;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1166
     not the whole smalltalk). 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1167
     See also: #newTCPclientToHost:port:withTimeout:"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1168
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1169
    ^ self newTCPclientToHost:hostname port:aService withTimeout:nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1170
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1171
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1172
      Socket newTCPclientToHost:'localhost' port:'nntp'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1173
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1174
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1175
    "Created: 31.10.1995 / 18:54:11 / cg"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1176
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1177
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1178
newTCPclientToHost:hostname port:aService withTimeout:millis
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1179
    "create a new TCP client socket connecting to a service.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1180
     Return a socket instance if ok, nil on failure.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1181
     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
  1182
     and return nil.."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1183
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1184
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1185
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1186
    newSock := self newTCP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1187
    newSock notNil ifTrue:[
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1188
	(newSock connectTo:hostname 
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1189
		 port:(self portOfService:aService protocol:'tcp') 
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1190
		 withTimeout:millis
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1191
	) ifFalse:[
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1192
	    newSock close.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1193
	    ^ nil
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1194
	]
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1195
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1196
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1197
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1198
same as:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1199
    ^ (self new) for:hostname port:(self portOfService:aPort).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1200
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1201
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1202
      Socket newTCPclientToHost:'slsv6bt' port:'nntp'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1203
      Socket newTCPclientToHost:'localhost' port:'nntp' withTimeout:1000
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1204
    "
604
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
  1205
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
  1206
    "Modified: / 16.1.1998 / 09:47:06 / stefan"
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1207
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1208
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  1209
newTCPserverAtAnonymousPort
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  1210
    "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
  1211
     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
  1212
811
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1213
    ^ self newTCPserverAtPort:0
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  1214
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  1215
!
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  1216
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1217
newTCPserverAtPort:aService
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1218
    "create a new TCP server socket providing service."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1219
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1220
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1221
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1222
    newSock := self newTCP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1223
    newSock notNil ifTrue:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1224
	(newSock bindTo:(self portOfService:aService) address:nil) ifFalse:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1225
	    ^ nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1226
	]
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1227
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1228
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1229
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1230
same as:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1231
    ^ (self new) for:nil port:aPort
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1232
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1233
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1234
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1235
newUDP
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1236
    "create a UDP socket - no binding or other setup is done,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1237
     neither connect nor connect-wait is done."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1238
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1239
    ^ self new domain:#inet type:#datagram
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1240
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1241
    "Socket newUDP"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1242
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1243
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1244
newUDP:aServiceOrNil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1245
    "create a UDP socket for a service -
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1246
     neither connect nor connect-wait is done."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1247
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1248
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1249
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1250
    newSock := self newUDP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1251
    (newSock notNil and:[aServiceOrNil notNil]) ifTrue:[
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1252
	(newSock bindTo:(self portOfService:aServiceOrNil) address:nil) ifFalse:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1253
	    ^ nil
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1254
	]
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1255
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1256
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1257
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1258
    "Socket newUDP:nil"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1259
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1260
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1261
newUDPserverAtPort:aService
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1262
    "create a new UDP server socket providing service."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1263
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1264
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1265
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1266
    newSock := self newUDP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1267
    newSock notNil ifTrue:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1268
	(newSock bindTo:(self portOfService:aService) address:nil) ifFalse:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1269
	    ^ nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1270
	]
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1271
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1272
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1273
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1274
same as:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1275
    ^ (self new) for:nil udpPort:aPort
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1276
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1277
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1278
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1279
newUNIX
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1280
    "create a UNIX domain socket - no binding or other setup is done,
811
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1281
     neither connect nor connect-wait is done.
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1282
     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
  1283
     return nil."
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1284
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1285
    ^ self new domain:#unix type:#stream 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1286
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1287
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1288
     Socket newUNIX
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1289
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1290
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1291
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1292
newUNIXclientTo:pathName 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1293
    "create a new UNIX client socket connecting to a pathname.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1294
     Return a socket instance if ok, nil on failure.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1295
     Block until a connection is established (but only the current thread;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1296
     not the whole smalltalk). 
811
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1297
     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
  1298
     return nil.
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1299
     See also: #newUNIXclientTo:withTimeout:"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1300
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1301
    ^ self newUNIXclientTo:pathName withTimeout:nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1302
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1303
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1304
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1305
newUNIXclientTo:pathName withTimeout:millis
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1306
    "create a new UNIX client socket connecting to a pathname.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1307
     Return a socket instance if ok, nil on failure.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1308
     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
  1309
     and return nil.
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1310
     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
  1311
     return nil."
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1312
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1313
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1314
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1315
    newSock := self newUNIX.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1316
    newSock notNil ifTrue:[
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1317
	(newSock connectTo:pathName port:nil withTimeout:millis) ifFalse:[
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1318
	    newSock close.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1319
	    ^ nil
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1320
	]
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1321
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1322
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1323
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1324
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1325
     |s|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1326
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1327
     s := Socket newUNIXclientTo:'/tmp/foo'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1328
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1329
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1330
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1331
newUNIXserverAt:pathName
811
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1332
    "create a new UNIX server socket providing service at a pathname.
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1333
     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
  1334
     return nil."
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1335
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1336
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1337
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1338
    newSock := self newUNIX.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1339
    newSock notNil ifTrue:[
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1340
	(newSock bindTo:pathName address:nil) ifFalse:[
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1341
	    ^ nil
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1342
	]
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1343
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1344
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1345
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1346
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1347
     |s s2|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1348
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1349
     s := Socket newUNIXserverAt:'/tmp/foo'.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1350
     s listenFor:5.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1351
     s2 := s accept.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1352
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1353
! !
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1354
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1355
!Socket class methodsFor:'host queries'!
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1356
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1357
appletalkAddressOfHost:aHostName
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1358
    "return the APPLETALK address for a hostname as a byteArray,
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1359
     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
  1360
     followed by the node byte.
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1361
     If the host is unknown, return nil.
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1362
     This is the reverse operation to #hostWithAppletalkAddress:.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1363
     WARNING: untested code - I have no appletalk to test this."
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1364
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1365
%{
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1366
#if !defined(NO_SOCKET) && defined(AF_APPLETALK)
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1367
    struct sockaddr_at sa;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1368
    struct hostent *hp ;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1369
    long addr;
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1370
    OBJ rslt;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1371
529
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1372
    sa.sat_family = -1;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1373
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1374
    if (__isString(aHostName)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1375
	bzero(&sa, sizeof(sa)) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1376
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1377
	/* do we know the host's address? */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1378
	GETHOSTBYNAME(hp, __stringVal(aHostName))
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1379
	if (hp == NULL) {
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1380
	    DBGPRINTF(("SOCKET: unknown appletalk host: %s\n", __stringVal(aHostName)));
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1381
	    RETURN ( nil );
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1382
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1383
	bcopy(hp->h_addr, (char *) &sa.sat_addr, hp->h_length) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1384
	sa.sat_family = hp->h_addrtype;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1385
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1386
752
c4176e236d83 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 741
diff changeset
  1387
    /* if the addressing family is not AF_APPLETALK, Return nil */
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1388
    if (sa.sat_family != AF_APPLETALK) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1389
	DBGPRINTF(("SOCKET: not an appletalk host\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1390
	RETURN ( nil );
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1391
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1392
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1393
    sa.sat_addr.s_net = ntohs(sa.sat_addr.s_net);    
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1394
    rslt = __BYTEARRAY_NEW_INT(3);
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1395
    if (rslt != nil) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1396
	__ByteArrayInstPtr(rslt)->ba_element[0] = (sa.sat_addr.s_net >> 8) & 0xFF;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1397
	__ByteArrayInstPtr(rslt)->ba_element[1] = (sa.sat_addr.s_net) & 0xFF;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1398
	__ByteArrayInstPtr(rslt)->ba_element[2] = (sa.sat_addr.s_node) & 0xFF;
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1399
       RETURN (rslt);
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1400
    }
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1401
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1402
%}.
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1403
    ^ nil
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1404
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1405
!
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1406
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1407
hostWithAppletalkAddress:anAddress
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1408
    "return the hostname for an APPLETALK address.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1409
     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
  1410
     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
  1411
     The last byte is the node number.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1412
     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
  1413
     This is is the reverse operation to #appletalkAddressOfHost:.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1414
     WARNING: untested code - I have no appletalk to test this."
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1415
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1416
    |b1 b2 b3 b4|
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1417
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1418
    b1 := anAddress at:1. "/ net-hi
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1419
    b2 := anAddress at:2. "/ net-low
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1420
    b3 := anAddress at:3. "/ node
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1421
%{
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1422
#if !defined(NO_SOCKET) && defined(AF_APPLETALK)
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1423
    struct sockaddr_at sa ;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1424
    struct hostent *hp ;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1425
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1426
    sa.sat_family = -1;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1427
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1428
    if (__bothSmallInteger(b1, b2) && __bothSmallInteger(b3, b4)) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1429
	bzero(&sa, sizeof(sa)) ;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1430
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1431
	sa.sat_addr.s_net = _intVal(b1) & 0xFF;
529
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1432
	sa.sat_addr.s_net = (sa.sat_addr.s_net << 8) | (_intVal(b2) & 0xFF);
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1433
	sa.sat_addr.s_net = htons(sa.sat_addr.s_net);    
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1434
	sa.sat_addr.s_node = _intVal(b3) & 0xFF;
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1435
	sa.sat_family = AF_APPLETALK;
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1436
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1437
	/* do we know the host's address? */
650
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1438
	GETHOSTBYADDR(hp, (char *) &sa.sat_addr, sizeof(sa.sat_addr), AF_APPLETALK);
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1439
	if (hp != NULL) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1440
	    sa.sat_family = hp->h_addrtype;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1441
	} else {
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1442
	    DBGPRINTF(("SOCKET: unknown appletalk address: %d.%d.%d.%d\n", 
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1443
		       _intVal(b1), _intVal(b2), _intVal(b3)));
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1444
	}
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1445
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1446
752
c4176e236d83 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 741
diff changeset
  1447
    /* if the addressing family is not AF_APPLETALK, Return nil */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1448
    if (sa.sat_family != AF_APPLETALK) {
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1449
	DBGPRINTF(("SOCKET: not an appletalk host\n"));
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1450
	RETURN ( nil );
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1451
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1452
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1453
    if (hp != NULL) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1454
	RETURN (__MKSTRING(hp->h_name));
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1455
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1456
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1457
    RETURN (nil);
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1458
%}.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1459
    "
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1460
     Socket appletalkAddressOfHost:'clam'
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1461
     Socket hostWithAppletalkAddress:#[1 2 3]  
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1462
     "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1463
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1464
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1465
hostWithIpAddress:anAddress
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1466
    "return the hostname for an IP (internet-) address.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1467
     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
  1468
     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
  1469
     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
  1470
     This is the reverse operation to #ipAddressOfHost:."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1471
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1472
    |b1 b2 b3 b4|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1473
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1474
    b1 := anAddress at:1.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1475
    b2 := anAddress at:2.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1476
    b3 := anAddress at:3.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1477
    b4 := anAddress at:4.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1478
%{
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1479
#if !defined(NO_SOCKET) && defined(AF_INET)
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1480
    struct sockaddr_in sa ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1481
    struct hostent *hp ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1482
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1483
    sa.sin_family = -1;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1484
    if (__bothSmallInteger(b1, b2) && __bothSmallInteger(b3, b4)) {
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1485
	bzero(&sa, sizeof(sa)) ;
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1486
	sa.sin_addr.s_addr = _intVal(b1) & 0xFF;
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1487
	sa.sin_addr.s_addr = (sa.sin_addr.s_addr << 8) | (_intVal(b2) & 0xFF);
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1488
	sa.sin_addr.s_addr = (sa.sin_addr.s_addr << 8) | (_intVal(b3) & 0xFF);
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1489
	sa.sin_addr.s_addr = (sa.sin_addr.s_addr << 8) | (_intVal(b4) & 0xFF);
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1490
	sa.sin_addr.s_addr = htonl(sa.sin_addr.s_addr);    
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1491
	sa.sin_family = AF_INET;
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1492
	/* do we know the host's address? */
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1493
	GETHOSTBYADDR(hp, (char *) &sa.sin_addr, sizeof(sa.sin_addr), AF_INET);
820
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1494
        
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1495
	if (hp == NULL) {
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1496
	    DBGPRINTF(("SOCKET: unknown ip address: %d.%d.%d.%d\n", 
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1497
		       _intVal(b1), _intVal(b2), _intVal(b3), _intVal(b4)));
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1498
	} else {
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1499
	    sa.sin_family = hp->h_addrtype;
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1500
	}
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1501
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1502
752
c4176e236d83 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 741
diff changeset
  1503
    /* if the addressing family is not AF_INET, Return nil */
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1504
    if (sa.sin_family != AF_INET) {
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1505
	RETURN ( nil );
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1506
    }
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1507
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1508
    if (hp != NULL) {
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1509
	RETURN (__MKSTRING(hp->h_name));
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1510
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1511
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1512
    /*
752
c4176e236d83 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 741
diff changeset
  1513
     * Return it in dot-notation
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1514
     */
448
2203a4bb620d removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
  1515
    RETURN (__MKSTRING(inet_ntoa(sa.sin_addr)));
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1516
#else
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1517
    RETURN (nil);
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1518
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1519
%}
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1520
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1521
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1522
     Socket ipAddressOfHost:'clam'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1523
     Socket hostWithIpAddress:(Socket ipAddressOfHost:'clam') 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1524
     Socket ipAddressOfHost:'porty'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1525
     Socket hostWithIpAddress:(Socket ipAddressOfHost:'porty') 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1526
     Socket hostWithIpAddress:#[1 2 3 4]  
796
c9f6b3b667fb Fix ipAddressOfHost
Stefan Vogel <sv@exept.de>
parents: 790
diff changeset
  1527
     Socket hostWithIpAddress:#[127 0 0 1]  
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1528
     Socket hostWithIpAddress:(Socket ipAddressOfHost:'1.2.3.4')  
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1529
     "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1530
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1531
820
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1532
hostWithIpV6Address:anAddress
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1533
    "return the hostname for an IPv6 (internet-) address.
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1534
     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
  1535
     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
  1536
     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
  1537
     This is the reverse operation to #ipV6AddressOfHost:."
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1538
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1539
%{
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1540
#if !defined(NO_SOCKET) && defined(AF_INET6)
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1541
    struct sockaddr_in6 sa ;
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1542
    struct hostent *hp ;
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1543
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1544
    sa.sin6_family = -1;
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1545
    if (__isByteArray(anAddress)) {
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1546
	bzero(&sa, sizeof(sa)) ;
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1547
	if (__byteArraySize(anAddress) <= sizeof(sa.sin6_addr.s6_addr))
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1548
	    goto bad;
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1549
	bcopy(sa.sin6_addr.s6_addr, __ByteArrayInstPtr(anAddress)->ba_element, sizeof(sa.sin6_addr.s6_addr));
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1550
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1551
	sa.sin6_family = AF_INET6;
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1552
	/* do we know the host's address? */
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1553
	GETHOSTBYADDR(hp, (char *) &sa.sin6_addr, sizeof(sa.sin6_addr), AF_INET6);
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1554
	if (hp == NULL) {
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1555
	    DBGPRINTF(("SOCKET: unknown ipv6 address: %d.%d.%d.%d...\n", 
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1556
		       sa.sin6_addr.s6_addr[0], 
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1557
		       sa.sin6_addr.s6_addr[1], 
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1558
		       sa.sin6_addr.s6_addr[2],
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1559
		       sa.sin6_addr.s6_addr[3] ));
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1560
	} else {
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1561
	    sa.sin6_family = hp->h_addrtype;
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1562
	}
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1563
    }
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1564
    bad: ;
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1565
    /* if the addressing family is not AF_INET6, Return nil */
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1566
    if (sa.sin6_family != AF_INET6) {
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1567
	DBGPRINTF(("SOCKET: not an ipv6 host\n")); 
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1568
	RETURN ( nil );
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1569
    }
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1570
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1571
    if (hp != NULL) {
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1572
	RETURN (__MKSTRING(hp->h_name));
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1573
    }
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1574
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1575
    /*
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1576
     * Return it in dot-notation
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1577
     */
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1578
    RETURN (__MKSTRING(inet_ntoa(sa.sin6_addr)));
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1579
#else
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1580
    RETURN (nil);
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1581
#endif
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1582
%}
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1583
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1584
    "
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1585
     Socket ipV6AddressOfHost:'clam'
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1586
     Socket hostWithIpV6Address:(Socket ipAddressOfHost:'clam') 
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1587
     Socket ipV6AddressOfHost:'porty'
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1588
     Socket hostWithIpV6Address:(Socket ipAddressOfHost:'porty') 
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1589
     Socket hostWithIpV6Address:#[1 2 3 4 5 6 7 8 9 10 11 12 13 14]  
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1590
     "
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1591
!
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1592
6
claus
parents: 4
diff changeset
  1593
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
  1594
    "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
  1595
     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
  1596
     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
  1597
     This is the reverse operation to #hostWithIpAddress:."
6
claus
parents: 4
diff changeset
  1598
claus
parents: 4
diff changeset
  1599
%{
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1600
#if !defined(NO_SOCKET) && defined(AF_INET)
6
claus
parents: 4
diff changeset
  1601
    struct sockaddr_in sa ;
claus
parents: 4
diff changeset
  1602
    struct hostent *hp ;
claus
parents: 4
diff changeset
  1603
    long addr;
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1604
    OBJ rslt;
6
claus
parents: 4
diff changeset
  1605
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1606
    sa.sin_family = -1;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1607
21
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1608
    if (__isString(aHostName)) {
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1609
	bzero(&sa, sizeof(sa)) ;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1610
	if ((addr = inet_addr((char *) __stringVal(aHostName))) != -1) {
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1611
	    /* is Internet addr in octet notation */
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1612
	    bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)); 
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1613
	    sa.sin_family = AF_INET;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1614
	} else {
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1615
	    /* do we know the host's address? */
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1616
	    GETHOSTBYNAME(hp, __stringVal(aHostName))
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1617
	    if (hp == NULL) {
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1618
		DBGPRINTF(("SOCKET: unknown ip host: %s\n", __stringVal(aHostName)));
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1619
		RETURN ( nil );
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1620
	    }
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1621
	    bcopy(hp->h_addr, (char *) &sa.sin_addr, hp->h_length) ;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1622
	    sa.sin_family = hp->h_addrtype;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1623
	}
6
claus
parents: 4
diff changeset
  1624
    }
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1625
752
c4176e236d83 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 741
diff changeset
  1626
    /* if the addressing family is not AF_INET, Return nil */
6
claus
parents: 4
diff changeset
  1627
    if (sa.sin_family != AF_INET) {
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1628
	DBGPRINTF(("SOCKET: not an ip host\n"));
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1629
	RETURN ( nil );
6
claus
parents: 4
diff changeset
  1630
    }
98
5e787ba2cb31 use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
  1631
5e787ba2cb31 use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
  1632
    sa.sin_addr.s_addr = ntohl(sa.sin_addr.s_addr);    
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1633
    rslt = __BYTEARRAY_NEW_INT(4);
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1634
    if (rslt != nil) {
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1635
	__ByteArrayInstPtr(rslt)->ba_element[0] = (sa.sin_addr.s_addr >> 24) & 0xFF;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1636
	__ByteArrayInstPtr(rslt)->ba_element[1] = (sa.sin_addr.s_addr >> 16) & 0xFF;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1637
	__ByteArrayInstPtr(rslt)->ba_element[2] = (sa.sin_addr.s_addr >> 8) & 0xFF;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1638
	__ByteArrayInstPtr(rslt)->ba_element[3] = (sa.sin_addr.s_addr >> 0) & 0xFF;
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1639
       RETURN (rslt);
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1640
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1641
#endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1642
%}.
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1643
    ^ nil
21
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1644
71
claus
parents: 63
diff changeset
  1645
    "
796
c9f6b3b667fb Fix ipAddressOfHost
Stefan Vogel <sv@exept.de>
parents: 790
diff changeset
  1646
     Socket ipAddressOfHost:'localhost' 
c9f6b3b667fb Fix ipAddressOfHost
Stefan Vogel <sv@exept.de>
parents: 790
diff changeset
  1647
     Socket ipAddressOfHost:'exept'    
98
5e787ba2cb31 use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
  1648
     Socket ipAddressOfHost:'1.2.3.4'    
5e787ba2cb31 use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
  1649
     Socket ipAddressOfHost:'193.15.16.17'    
5e787ba2cb31 use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
  1650
     Socket ipAddressOfHost:'josef'     
5e787ba2cb31 use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
  1651
     Socket ipAddressOfHost:'styx.com'  
5e787ba2cb31 use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
  1652
     Socket hostWithIpAddress:(Socket ipAddressOfHost:'localhost') 
5e787ba2cb31 use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
  1653
     Socket ipAddressOfHost:(Socket hostWithIpAddress:'127.0.0.1') 
71
claus
parents: 63
diff changeset
  1654
    "
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1655
!
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1656
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1657
ipV6AddressOfHost:aHostName
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1658
    "return the IPv6 (internet-) number for a hostname as a byteArray,
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1659
     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
  1660
     If the host is unknown, return nil.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1661
     This is the reverse operation to #hostWithIpV6Address:."
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1662
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1663
%{
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1664
#if !defined(NO_SOCKET) && defined(AF_INET6)
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1665
    struct sockaddr_in6 sa;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1666
    struct hostent *hp ;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1667
    long addr;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1668
    OBJ rslt;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1669
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1670
    sa.sin6_family = -1;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1671
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1672
    if (__isString(aHostName)) {
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1673
	bzero(&sa, sizeof(sa)) ;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1674
#if 0
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1675
	if ((addr = inet_addr((char *) __stringVal(aHostName))) != -1) {
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1676
	    /* is Internet addr in octet notation */
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1677
	    bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)); 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1678
	    sa.sin_family = AF_INET;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1679
	} else 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1680
#endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1681
	{
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1682
	    /* do we know the host's address? */
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1683
	    GETHOSTBYNAME(hp, __stringVal(aHostName))
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1684
	    if (hp == NULL) {
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1685
		DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(aHostName)));
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1686
		RETURN ( nil );
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1687
	    }
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1688
	    bcopy(hp->h_addr, (char *) &sa.sin6_addr, hp->h_length) ;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1689
	    sa.sin6_family = hp->h_addrtype;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1690
	}
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1691
    }
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1692
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1693
    /* if the addressing family is not AF_INET, Return nil */
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1694
    if (sa.sin6_family != AF_INET) {
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1695
	DBGPRINTF(("SOCKET: not an ipv6 host\n"));
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1696
	RETURN ( nil );
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1697
    }
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1698
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1699
    rslt = __BYTEARRAY_NEW_INT(hp->h_length);
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1700
    if (rslt != nil) {
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1701
	bcopy(sa.sin6_addr.s6_addr, __ByteArrayInstPtr(rslt)->ba_element, hp->h_length);
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1702
       RETURN (rslt);
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1703
    }
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1704
#endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1705
%}.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1706
    ^ nil
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1707
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1708
    "
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1709
     Socket ipV6AddressOfHost:'localhost' 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1710
     Socket ipV6AddressOfHost:'exept'    
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1711
     Socket ipV6AddressOfHost:'1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16'    
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1712
     Socket ipV6AddressOfHost:'193.15.16.17'    
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1713
     Socket ipV6AddressOfHost:'josef'     
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1714
     Socket ipV6AddressOfHost:'styx.com'  
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1715
     Socket hostWithIpV6Address:(Socket ipV6AddressOfHost:'localhost') 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1716
     Socket ipV6AddressOfHost:(Socket hostV6WithIpAddress:'127.0.0.1') 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1717
    "
531
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1718
! !
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1719
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1720
!Socket class methodsFor:'queries'!
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1721
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1722
domainOfProtocol:aProtocol
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1723
    "given a protocols name (i.e. tcp, udp etc) return the domain.
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1724
     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
  1725
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1726
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1727
     tcp/ip stuff
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1728
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1729
    (aProtocol = 'tcp') ifTrue:[^ #inet].
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1730
    (aProtocol = 'udp') ifTrue:[^ #inet].
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1731
    (aProtocol = 'ip')  ifTrue:[^ #inet].
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1732
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1733
     unix domain
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1734
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1735
    (aProtocol = 'ud')  ifTrue:[^ #unix].
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1736
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1737
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1738
     add x25 stuff (if any) here ...
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1739
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1740
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1741
     add appletalk stuff (if any) here ...
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1742
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1743
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1744
     add other stuff (if any) here ...
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1745
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1746
    ^ nil
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1747
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1748
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1749
     Socket domainOfProtocol:'tcp'
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1750
     Socket domainOfProtocol:'ucp'
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1751
     Socket domainOfProtocol:(Socket protocolOfService:'nntp')
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1752
     Socket domainOfProtocol:(Socket protocolOfService:'echo')
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1753
    "
6
claus
parents: 4
diff changeset
  1754
!
claus
parents: 4
diff changeset
  1755
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1756
networkLongOrderIsMSB
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1757
    "return true, if the network-byte-order of longs is MSB.
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1758
     To be used as in:
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1759
	'aStream nextPutLong:someValue MSB:(Socket networkLongOrderIsMSB)'."
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1760
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1761
%{  /* NOCONTEXT */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1762
#ifndef NO_SOCKET
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1763
    /*
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1764
     * mhmh - do c-compilers optimize this away ?
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1765
     */
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1766
    if (htonl(0x76543210) == 0x76543210) {
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1767
	RETURN (true);
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1768
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1769
#endif
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1770
%}.
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1771
    ^ false
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1772
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1773
    "
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1774
     Socket networkLongOrderIsMSB
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1775
    "
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1776
!
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1777
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1778
networkShortOrderIsMSB
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1779
    "return true, if the network-byte-order of shorts is MSB.
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1780
     To be used as in:
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1781
	'aStream nextPutShort:someValue MSB:(Socket networkShortOrderIsMSB)'."
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1782
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1783
%{  /* NOCONTEXT */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1784
#ifndef NO_SOCKET
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1785
    /*
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1786
     * mhmh - do c-compilers optimize this away ?
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1787
     */
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1788
    if (htons(0x3210) == 0x3210) {
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1789
	RETURN (true);
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1790
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1791
#endif
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1792
%}.
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1793
    ^ false
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1794
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1795
    "
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1796
     Socket networkShortOrderIsMSB
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1797
    "
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1798
!
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1799
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1800
portOfService:aNameOrNumber
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1801
    "returns the port-number for a given IP-service
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1802
     or nil if no such service exists;
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1803
     - used to convert service names to portNumbers"
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1804
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1805
    ^ self portOfService:aNameOrNumber protocol:nil
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1806
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1807
    "
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1808
     Socket portOfService:'finger'
74
claus
parents: 71
diff changeset
  1809
     Socket portOfService:'nntp'  
claus
parents: 71
diff changeset
  1810
     Socket portOfService:'echo' 
claus
parents: 71
diff changeset
  1811
     Socket portOfService:'snmp' 
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1812
    "
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1813
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1814
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1815
portOfService:aNameOrNumber protocol:aProtocol
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1816
    "returns the port-number for a given IP-service
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1817
     or nil if no such service exists;
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1818
     - used to convert service names to portNumbers"
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1819
604
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
  1820
%{ /* NOCONTEXT */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1821
#ifndef NO_SOCKET
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1822
    struct servent *servent = NULL;
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1823
    char *protocol;
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1824
    int tryBoth = 0;
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1825
    short portNo;
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1826
604
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
  1827
    if (__isSmallInteger(aNameOrNumber)) {
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1828
	RETURN ( aNameOrNumber );
92
Claus Gittinger <cg@exept.de>
parents: 91
diff changeset
  1829
    }
Claus Gittinger <cg@exept.de>
parents: 91
diff changeset
  1830
604
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
  1831
    if (__isString(aProtocol)) {
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1832
	protocol = (char *)__stringVal(aProtocol);
604
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
  1833
    } else {
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1834
	protocol = "tcp";
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1835
	tryBoth = 1;
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1836
    }
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1837
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1838
    if (__isString(aNameOrNumber) || __isSymbol(aNameOrNumber)) {
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1839
	servent = getservbyname((char *) __stringVal(aNameOrNumber), protocol);
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1840
	if (servent != NULL) {
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1841
	    RETURN ( __MKSMALLINT(ntohs(servent->s_port)) );
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1842
	}
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1843
	if (tryBoth) {
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1844
	    servent = getservbyname((char *) __stringVal(aNameOrNumber), "udp");
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1845
	    if (servent != NULL) {
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1846
		RETURN ( __MKSMALLINT(ntohs(servent->s_port)) );
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1847
	    }
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1848
	}
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1849
	RETURN ( nil );
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1850
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1851
#endif
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1852
    RETURN ( nil );
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1853
%}
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1854
    "
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1855
     Socket portOfService:'echo' protocol:'udp'
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1856
     Socket portOfService:'echo' protocol:'tcp'
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1857
    "
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1858
!
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1859
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1860
protocolOfService:aNameOrNumber
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1861
    "returns the protocol (as string) for a given IP-service
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1862
     or nil if no such service exists."
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1863
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1864
#ifndef NO_SOCKET
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1865
    struct servent *servent = NULL;
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1866
    short portNo;
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1867
58
bd6753bf0401 *** empty log message ***
claus
parents: 51
diff changeset
  1868
    if (__isSmallInteger(aNameOrNumber)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1869
	portNo = __intVal(aNameOrNumber);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1870
	servent = getservbyport(htons(portNo), "tcp") ;
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1871
	if (servent == NULL) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1872
	    servent = getservbyport(htons(portNo), "udp") ;
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1873
	    if (servent == NULL) {
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1874
		RETURN ( nil );
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1875
	    }
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1876
	}
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1877
    } else {
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1878
	if (__isString(aNameOrNumber)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1879
	    servent = getservbyname((char *) __stringVal(aNameOrNumber), "tcp");
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1880
	    if (servent == NULL) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1881
		servent = getservbyname((char *) __stringVal(aNameOrNumber), "udp");
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1882
		if (servent == NULL) {
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1883
		    RETURN ( nil );
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1884
		}
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1885
	    }
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1886
	}
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1887
    }
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1888
    if (servent) {
448
2203a4bb620d removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
  1889
	RETURN ( __MKSTRING(servent->s_proto) );
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1890
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1891
#endif
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1892
    RETURN ( nil );
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1893
%}
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1894
    "
74
claus
parents: 71
diff changeset
  1895
     Socket protocolOfService:'finger' 
claus
parents: 71
diff changeset
  1896
     Socket protocolOfService:'nntp'  
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1897
     Socket protocolOfService:'xxx'
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1898
     Socket protocolOfService:79
74
claus
parents: 71
diff changeset
  1899
     Socket protocolOfService:'snmp' 
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1900
    "
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1901
!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1902
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1903
supportedProtocolFamilies
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1904
    "return a collection of supported protocol families.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1905
     This list specifies what the Socket class supports -
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1906
     socket creation may still fail, if your system was built
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1907
     without it."
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1908
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1909
    |list hasIt|
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1910
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1911
    list := OrderedCollection new.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1912
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1913
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1914
#ifdef AF_INET
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1915
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1916
    list add:#inet.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1917
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1918
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1919
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1920
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1921
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1922
#ifdef AF_UNIX
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1923
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1924
    list add:#unix.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1925
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1926
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1927
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1928
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1929
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1930
#ifdef AF_INET6
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1931
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1932
    list add:#inet6.   "/ internet v6
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1933
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1934
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1935
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1936
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1937
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1938
#ifdef AF_APPLETALK
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1939
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1940
    list add:#appletalk.  "/ appletalk
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1941
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1942
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1943
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1944
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1945
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1946
#ifdef AF_DECnet
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1947
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1948
    list add:#decnet.  "/ dec net
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1949
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1950
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1951
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1952
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1953
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1954
#ifdef AF_NS
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1955
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1956
    list add:#xns.     "/ Xerox XNS
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1957
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1958
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1959
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1960
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1961
%{
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1962
#ifdef AF_X25
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1963
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1964
    list add:#x25.     "/ X.25
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1965
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1966
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1967
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1968
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1969
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1970
#ifdef AF_SNA
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1971
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1972
    list add:#sna.     "/ IBM SNA
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1973
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1974
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1975
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1976
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1977
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1978
#ifdef AF_RAW
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1979
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1980
    list add:#raw.     "/ ?? RAW packets
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1981
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1982
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1983
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1984
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1985
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1986
#ifdef AF_ISO
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1987
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1988
    list add:#iso.     "/ ??
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1989
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1990
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1991
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1992
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1993
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1994
#ifdef AF_NETBIOS
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1995
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1996
    list add:#netbios. "/ ??
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1997
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1998
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1999
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2000
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2001
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2002
#ifdef AF_IPX
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2003
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2004
    list add:#ipx.     "/ Novell IPX
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2005
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2006
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2007
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2008
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2009
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2010
#ifdef AF_AX25
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2011
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2012
    list add:#ax25.    "/ Amateur Radio AX.25
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2013
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2014
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2015
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2016
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2017
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2018
#ifdef AF_NETROM
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2019
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2020
    list add:#netrom.  "/ Amateur Radio NET/ROM
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2021
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2022
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2023
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2024
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2025
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2026
#ifdef AF_BRIDGE
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2027
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2028
    list add:#bridge.  "/ multiprotocol bridge
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2029
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2030
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2031
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2032
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2033
%{
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2034
#ifdef AF_BSC
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2035
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2036
    list add:#bsc.     "/ BISYNC 2780/3780
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2037
%{
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2038
#endif
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2039
%}.
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2040
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2041
%{
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2042
#ifdef AF_ROSE
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2043
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2044
    list add:#rose.    "/ Amateur Radio X.25 PLP
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2045
%{
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2046
#endif
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2047
%}.
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2048
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2049
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2050
    ^ list
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2051
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2052
    "
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2053
     Socket supportedProtocolFamilies
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2054
    "
559
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2055
!
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2056
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2057
typeOfProtocol:aProtocol
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2058
    "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
  2059
     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
  2060
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2061
    (aProtocol = 'tcp') ifTrue:[^ #stream].
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2062
    (aProtocol = 'udp') ifTrue:[^ #datagram].
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2063
    (aProtocol = 'ip')  ifTrue:[^ #raw].
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2064
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2065
     unix domain
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2066
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2067
    (aProtocol = 'ud')  ifTrue:[^ #stream].
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2068
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2069
     add x25 stuff (if any) here ...
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2070
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2071
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2072
     add appletalk stuff (if any) here ...
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2073
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2074
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2075
     add other stuff (if any) here ...
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2076
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2077
    ^ nil
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2078
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2079
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2080
     Socket typeOfProtocol:'tcp'
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2081
     Socket typeOfProtocol:'ucp'
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2082
     Socket typeOfProtocol:(Socket protocolOfService:'nntp')
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2083
     Socket typeOfProtocol:(Socket protocolOfService:'echo')
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2084
    "
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2085
! !
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2086
867
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  2087
!Socket methodsFor:'Compatibility - ST80'!
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2088
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2089
errorReporter
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2090
    "ST-80 mimicry."
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2091
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2092
    ^ self
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2093
!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2094
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2095
notReadySignal
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2096
    "ST-80 mimicry.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2097
     for now - this is not yet raised"
71
claus
parents: 63
diff changeset
  2098
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2099
    ^ Signal new
486
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2100
!
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2101
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  2102
readAppendStream
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2103
    "ST-80 mimicry.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2104
     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
  2105
     ST-80 code therefore uses 'Socket readWriteStream' to access
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2106
     the actual stream. 
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2107
     In ST/X, sockets inherit from stream, so
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2108
     this method returns the receiver, for transparency"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2109
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  2110
    ^ self
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  2111
!
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  2112
486
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2113
readStream
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2114
    "ST-80 mimicry.
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2115
     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
  2116
     ST-80 code therefore uses 'Socket readStream' to access
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2117
     the actual stream. 
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2118
     In ST/X, sockets inherit from stream, so
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2119
     this method returns the receiver, for transparency"
486
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2120
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2121
    ^ self
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2122
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2123
    "Created: 24.1.1997 / 23:52:57 / cg"
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2124
!
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2125
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  2126
shutdown:how
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  2127
    "ST-80 compatibility"
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  2128
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  2129
    self shutDown
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  2130
!
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  2131
486
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2132
writeStream
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2133
    "ST-80 mimicry.
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2134
     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
  2135
     ST-80 code therefore uses 'Socket writeStream' to access
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2136
     the actual stream. 
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2137
     In ST/X, sockets inherit from stream, so
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2138
     this method returns the receiver, for transparency"
486
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2139
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2140
    ^ self
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2141
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2142
    "Created: 24.1.1997 / 10:34:35 / cg"
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2143
    "Modified: 24.1.1997 / 23:52:52 / cg"
71
claus
parents: 63
diff changeset
  2144
! !
claus
parents: 63
diff changeset
  2145
827
006dc4fe9dbd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 823
diff changeset
  2146
!Socket methodsFor:'Compatibility - Squeak'!
771
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  2147
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  2148
peerName
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  2149
    "return my peer (i.e. ipAddr + port);
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  2150
     May return nil if not yet setup completely."
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  2151
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  2152
    ^ self getPeer
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  2153
! !
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  2154
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2155
!Socket methodsFor:'datagram transmission'!
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2156
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2157
receiveFrom:anAddressBuffer buffer:aDataBuffer
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2158
    "receive datagramm data - put address of originating host into
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2159
     anAddressBuffer, data into aBuffer. 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2160
     Both must be ByteArray-like. The addressBuffer must
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2161
     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
  2162
     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
  2163
     On error, the unix error code is left in the lastErrorNumber
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2164
     instance variable."
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2165
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2166
    ^ 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
  2167
!
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
  2168
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2169
receiveFrom:anAddressBuffer buffer:aDataBuffer start:startIndex for:nBytes
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2170
    "receive datagramm data - put address of originating host into
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2171
     anAddressBuffer, data into aBuffer. For ST-80 compatibility,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2172
     the addressBuffer may be a non-ByteArray; then, it must understand
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2173
     the addressBytes-message (i.e. be a SocketAddress instance).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2174
     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
  2175
     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
  2176
     instance variable.
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2177
     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
  2178
     receiving, using #readWait or #readWaitWithTimeout:."
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2179
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2180
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2181
    |addrBytes addrLen nReceived|
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2182
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2183
    addrBytes := ByteArray new:100.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2184
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  2185
#ifndef NO_SOCKET
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2186
    OBJ oClass, myDomain;
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2187
    OBJ fp = __INST(filePointer);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2188
    int nInstVars, nInstBytes, objSize;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2189
    int sock;
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2190
    union sockaddr_u sa;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2191
    int alen;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2192
    int n;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2193
    char *cp;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2194
    int flags = 0;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2195
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2196
    if (fp != nil) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2197
	sock = fileno(__FILEVal(fp));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2198
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2199
	oClass = __Class(aDataBuffer);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2200
	switch (_intVal(_ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2201
	    case BYTEARRAY:
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2202
	    case WORDARRAY:
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2203
	    case SWORDARRAY:
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2204
	    case LONGARRAY:
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2205
	    case SLONGARRAY:
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2206
	    case FLOATARRAY:
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2207
	    case DOUBLEARRAY:
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2208
		break;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2209
	    default:
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2210
		goto bad;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2211
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2212
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2213
	nInstVars = _intVal(_ClassInstPtr(oClass)->c_ninstvars);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2214
	nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2215
	objSize = _Size(aDataBuffer) - nInstBytes;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2216
	cp = (char *)__InstPtr(aDataBuffer) + nInstBytes;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2217
	if (__isSmallInteger(startIndex)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2218
	    cp += __intVal(startIndex);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2219
	    objSize -= __intVal(startIndex);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2220
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2221
	if (__isSmallInteger(nBytes)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2222
	    if (__intVal(nBytes) < objSize) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2223
		objSize = __intVal(nBytes);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2224
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2225
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2226
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2227
	__BEGIN_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2228
	do {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2229
	    if (addrBytes == nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2230
		n = recvfrom(sock, cp, objSize, flags, (struct sockaddr *) 0, 0);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2231
	    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2232
		n = recvfrom(sock, cp, objSize, flags, (struct sockaddr *) &sa, &alen);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2233
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2234
	} while ((n < 0) && (errno == EINTR));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2235
	__END_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2236
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2237
	if (n >= 0) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2238
	    if (addrBytes != nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2239
		oClass = __Class(addrBytes);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2240
		if ((_intVal(_ClassInstPtr(oClass)->c_flags) & ARRAYMASK) != BYTEARRAY) 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2241
		    goto bad;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2242
		nInstVars = _intVal(_ClassInstPtr(oClass)->c_ninstvars);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2243
		nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2244
		objSize = _Size(addrBytes) - nInstBytes;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2245
		cp = (char *)__InstPtr(addrBytes) + nInstBytes;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2246
		if (objSize < alen) 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2247
		    goto bad;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2248
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2249
		myDomain = __INST(domain);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2250
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2251
		/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2252
		 * extract the datagrams address
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2253
		 */
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2254
# ifdef AF_INET
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2255
		if (myDomain == @symbol(inet)) {
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2256
		    if (objSize < 4) 
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2257
			goto bad;
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2258
		    cp[0] = (sa.in.sin_addr.s_addr >> 24) & 0xFF;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2259
		    cp[2] = (sa.in.sin_addr.s_addr >> 16) & 0xFF;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2260
		    cp[3] = (sa.in.sin_addr.s_addr >> 8) & 0xFF;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2261
		    cp[4] = (sa.in.sin_addr.s_addr >> 0) & 0xFF;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2262
		    alen = 4;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2263
		}
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2264
# endif /* AF_INET */
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2265
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2266
# ifdef AF_INET6
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2267
		if (myDomain == @symbol(inet6)) {
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2268
		    if (objSize < sizeof(sa.in6.sin6_addr.s6_addr)) 
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2269
			goto bad;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2270
		    bcopy(sa.in6.sin6_addr.s6_addr, cp, sizeof(sa.in6.sin6_addr.s6_addr));
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2271
		    alen = sizeof(sa.in6.sin6_addr.s6_addr);
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2272
		}
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2273
# endif /* AF_INET6 */
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2274
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2275
# ifdef AF_APPLETALK
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2276
		if (myDomain == @symbol(appletalk)) {
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2277
		    if (objSize < 3) 
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2278
			goto bad;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2279
		    cp[0] = (sa.at.sat_addr.s_net >> 8) & 0xFF;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2280
		    cp[2] = (sa.at.sat_addr.s_net) & 0xFF;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2281
		    cp[3] = (sa.at.sat_addr.s_node) & 0xFF;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2282
		    alen = 3;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2283
		}
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2284
# endif /* AF_APPLETALK */
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2285
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2286
		/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2287
		 * XXXX add addressing stuff for other domains here ...
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2288
		 */
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2289
# ifdef AF_X25
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2290
		if (myDomain == @symbol(x25)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2291
		}
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2292
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2293
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2294
# ifdef AF_AX25
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2295
		if (myDomain == @symbol(ax25)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2296
		}
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2297
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2298
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2299
# ifdef AF_NS
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2300
		if ((myDomain == @symbol(ns)) 
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2301
		 || (myDomain == @symbol(xns))) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2302
		}
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2303
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2304
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2305
# ifdef AF_SNA
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2306
		if (myDomain == @symbol(sna)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2307
		}
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2308
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2309
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2310
# ifdef AF_RAW
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2311
		if (myDomain == @symbol(raw)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2312
		}
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2313
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2314
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2315
# ifdef AF_ISO
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2316
		if (myDomain == @symbol(iso)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2317
		}
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2318
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2319
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2320
# ifdef AF_DECnet
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2321
		if (myDomain == @symbol(decnet)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2322
		}
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2323
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2324
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2325
# ifdef AF_NETBIOS
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2326
		if (myDomain == @symbol(netbios)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2327
		}
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2328
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2329
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2330
# ifdef AF_IPX
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2331
		if (myDomain == @symbol(ipx)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2332
		}
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2333
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2334
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2335
# ifdef AF_BRIDGE
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2336
		if (myDomain == @symbol(bridge)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2337
		}
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2338
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2339
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2340
# ifdef AF_BSC
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2341
		if (myDomain == @symbol(bsc)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2342
		}
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2343
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2344
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2345
# ifdef AF_ROSE
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2346
		if (myDomain == @symbol(rose)) {
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2347
		}
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2348
# endif
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2349
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2350
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2351
		if (myDomain == @symbol(ccitt)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2352
		}
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2353
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2354
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2355
		addrLen = __MKSMALLINT(alen);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2356
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2357
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2358
	if (n < 0) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2359
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2360
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2361
	nReceived = __MKSMALLINT(n);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2362
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  2363
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2364
bad: ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2365
%}.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2366
    nReceived notNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2367
	nReceived < 0 ifTrue:[
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2368
	    'Socket [warning]: ' infoPrint.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2369
	    (OperatingSystem errorTextForNumber:lastErrorNumber) infoPrintCR.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2370
	].
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2371
	addrLen notNil ifTrue:[
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2372
	    anAddressBuffer class isBytes ifTrue:[
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2373
		"/ can be a ByteArray for ST/X compatibility
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2374
		anAddressBuffer replaceFrom:1 to:addrLen with:addrBytes
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2375
	    ] ifFalse:[
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2376
		"/ can be a SocketAddress for ST-80 compatibility
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2377
		anAddressBuffer hostAddress:(addrBytes copyTo:addrLen)
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2378
	    ].
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2379
	].
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2380
	^ nReceived
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2381
    ].
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2382
    "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2383
     arrive here if you try to receive into an invalid buffer
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2384
     (i.e. not ByteArray-like), 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2385
     or if the addressBuffer is nonNil AND not a ByteArray/String 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2386
     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
  2387
    "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2388
    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
  2389
!
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2390
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2391
sendTo:anAddressBuffer buffer:buffer
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2392
    "send datagramm data - fetch address of destination host from
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2393
     anAddressBuffer, data from aDataBuffer. 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2394
     Both must be ByteArray-like. The bytes in the addressBuffer must
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2395
     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
  2396
     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
  2397
     On error, the unix error code is left in the lastErrorNumber
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2398
     instance variable.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2399
     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
  2400
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2401
    ^ 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
  2402
!
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2403
817
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2404
sendTo:anAddressBuffer buffer:buffer start:startIndex for:count
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2405
    "send datagramm data - fetch address of destination host from
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2406
     anAddressBuffer, data from aDataBuffer. 
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2407
     Both must be ByteArray-like. The bytes in the addressBuffer must
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2408
     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
  2409
     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
  2410
     On error, the unix error code is left in the lastErrorNumber
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2411
     instance variable.
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2412
     Flags is currently ignored; it is there for ST-80 compatibility."
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2413
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2414
    ^ self sendTo:anAddressBuffer buffer:buffer start:startIndex for:count flags:0 
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2415
!
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2416
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2417
sendTo:anAddressBuffer buffer:aDataBuffer start:startIndex for:count flags:flags
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2418
    "send datagramm data - fetch address of destination host from
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2419
     anAddressBuffer, data from aDataBuffer starting at startIndex,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2420
     sending count bytes. 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2421
     Both must be ByteArray-like. The bytes in the addressBuffer must
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2422
     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
  2423
     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
  2424
     On error, the unix error code is left in the lastErrorNumber
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2425
     instance variable."
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2426
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2427
    |addrBytes addrLen nReceived portNo|
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  2428
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2429
    "/ addressBuffer can be a byteArray (last 2 bytes are portNo, msb-first)
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2430
    "/ or (better) an instance of SocketAddress
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2431
    "/
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2432
    anAddressBuffer class isBytes ifTrue:[
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2433
	domain == #inet ifTrue:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2434
	    addrBytes := anAddressBuffer copyFrom:1 to:4.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2435
	    portNo := ((anAddressBuffer at:5) bitShift:8)
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2436
		      + (anAddressBuffer at:6).
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2437
	] ifFalse:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2438
	    domain == #appletalk ifTrue:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2439
		addrBytes := anAddressBuffer copyFrom:1 to:3.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2440
		portNo := ((anAddressBuffer at:5) bitShift:8)
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2441
			  + (anAddressBuffer at:6).
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2442
	    ].
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2443
	].
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2444
    ] ifFalse:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2445
	addrBytes := anAddressBuffer hostAddress.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2446
	portNo := anAddressBuffer port.
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2447
    ].
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2448
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  2449
#ifndef NO_SOCKET
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2450
    OBJ oClass;
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2451
    OBJ fp = __INST(filePointer);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2452
    int nInstVars, nInstBytes, objSize;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2453
    int sock;
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2454
    union sockaddr_u sa;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2455
    struct sockaddr *saPtr = (struct sockaddr *)&sa;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2456
    int alen = sizeof(sa);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2457
    int n;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2458
    char *cp;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2459
    int _flags = 0;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2460
    int offs, nBytes;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2461
    unsigned long norder;
21
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  2462
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2463
    _flags = __longIntVal(flags);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2464
 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2465
    if ((fp != nil) 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2466
     && __isSmallInteger(startIndex)
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2467
     && __isSmallInteger(count)) {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2468
	sock = fileno(__FILEVal(fp));
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2469
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2470
	if (addrBytes == nil) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2471
	    alen = 0;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2472
	    saPtr = (struct sockaddr *)0;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2473
	} else {
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2474
	    if (! __isByteArray(addrBytes)) goto bad;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2475
551
b2d6e4d86e77 avoid warnings (signed char vs. unsigned char)
Claus Gittinger <cg@exept.de>
parents: 537
diff changeset
  2476
	    cp = (char *)__ByteArrayInstPtr(addrBytes)->ba_element;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2477
	    n = __byteArraySize(addrBytes);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2478
	    if (alen < n) n = alen;
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2479
# ifdef DGRAM_DEBUG
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  2480
	    printf("address is %d bytes ... %d.%d.%d.%d", n, cp[0], cp[1], cp[2], cp[3]);
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2481
# endif
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  2482
	    bcopy(cp, &sa.in.sin_addr.s_addr, n);
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2483
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2484
# ifdef AF_INET
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  2485
	    if (__INST(domain) == @symbol(inet)) {
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
  2486
		sa.in.sin_family = AF_INET;
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
  2487
		sa.in.sin_port = htons((u_short) __intVal(portNo)); 
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  2488
	    }
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2489
# endif
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2490
# ifdef AF_INET6
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
  2491
	    if (__INST(domain) == @symbol(inet6)) {
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2492
		sa.in6.sin6_family = AF_INET6;
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
  2493
		sa.in6.sin6_port = htons((u_short) __intVal(portNo)); 
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
  2494
	    }
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2495
# endif
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2496
# ifdef AF_APPLETALK
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  2497
	    if (__INST(domain) == @symbol(appletalk)) {
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2498
		sa.at.sat_family = AF_APPLETALK;
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
  2499
		sa.at.sat_port = __intVal(portNo);
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
  2500
	    }
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2501
# endif
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  2502
	}
6
claus
parents: 4
diff changeset
  2503
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2504
	oClass = __Class(aDataBuffer);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2505
	switch (_intVal(_ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2506
	    case BYTEARRAY:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2507
		offs = __intVal(startIndex) - 1;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2508
		break;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2509
	    case WORDARRAY:
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2510
	    case SWORDARRAY:
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2511
		offs = (__intVal(startIndex) - 1) * 2;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2512
		break;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2513
	    case LONGARRAY:
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2514
	    case SLONGARRAY:
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2515
		offs = (__intVal(startIndex) - 1) * 4;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2516
		break;
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2517
	    case LONGLONGARRAY:
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2518
	    case SLONGLONGARRAY:
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2519
		offs = (__intVal(startIndex) - 1) * 8;
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2520
# ifdef __NEED_LONGLONG_ALIGN
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2521
		offs += 4;
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2522
# endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2523
	    case FLOATARRAY:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2524
		offs = (__intVal(startIndex) - 1) * sizeof(float);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2525
		break;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2526
	    case DOUBLEARRAY:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2527
		offs = (__intVal(startIndex) - 1) * sizeof(double);
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2528
# ifdef __NEED_DOUBLE_ALIGN
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2529
		offs += 4;
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2530
# endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2531
		break;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2532
	    default:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2533
		goto bad;
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  2534
	}
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2535
	nBytes = __intVal(count);
71
claus
parents: 63
diff changeset
  2536
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2537
	nInstVars = _intVal(_ClassInstPtr(oClass)->c_ninstvars);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2538
	nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2539
	objSize = __qSize(aDataBuffer) - nInstBytes;
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2540
	cp = (char *)__InstPtr(aDataBuffer) + nInstBytes;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2541
	cp += offs;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2542
	if ((offs + nBytes) > objSize) {
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2543
# ifdef DGRAM_DEBUG
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  2544
	    printf("cut off ...\n");
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2545
# endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2546
	    nBytes = objSize - offs;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2547
	}
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2548
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  2549
	norder = htonl(sa.in.sin_addr.s_addr);
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2550
# ifdef DGRAM_DEBUG
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  2551
	printf("sending %d bytes ... to ", nBytes);
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  2552
	printf("%d.%d.%d.%d\n",
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2553
		    (norder >> 24) & 0xFF,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2554
		    (norder >> 16) & 0xFF,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2555
		    (norder >> 8) & 0xFF,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2556
		    norder & 0xFF);
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2557
# endif
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2558
81
claus
parents: 79
diff changeset
  2559
	__BEGIN_INTERRUPTABLE__
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2560
	do {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2561
	    n = sendto(sock, cp, nBytes, _flags, saPtr, alen);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2562
	} while ((n < 0) && (errno == EINTR));
81
claus
parents: 79
diff changeset
  2563
	__END_INTERRUPTABLE__
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2564
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2565
	if (n < 0) {
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2566
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  2567
	}
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2568
	RETURN (__MKSMALLINT(n));
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2569
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  2570
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2571
bad: ;
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  2572
%}.
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  2573
    "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2574
     arrive here if you try to send from an invalid buffer
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2575
     (i.e. not ByteArray-like), 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2576
     or if the addressBuffer is nonNil AND not a ByteArray/String 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2577
     or if the addressBuffer is nonNil AND too small.
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  2578
    "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2579
    self primitiveFailed
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2580
! !
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2581
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2582
!Socket methodsFor:'low level'!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2583
507
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  2584
bindAnonymously
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  2585
    ^ self
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  2586
	bindTo:0
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  2587
	address:nil
509
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2588
	reuseAddress:false
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2589
!
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2590
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2591
bindAnonymouslyToAddress:addressString
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2592
    ^ self
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2593
	bindTo:0
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2594
	address:addressString
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2595
	reuseAddress:false
507
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  2596
!
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  2597
71
claus
parents: 63
diff changeset
  2598
bindTo:aSocketAddress 
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2599
    "ST80 compatible bind, expecting a socketAddress argument.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2600
     The socketAddress object (an instance of SocketAddress)
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2601
     is supposed to respond to #portOrName and #address requests."
71
claus
parents: 63
diff changeset
  2602
claus
parents: 63
diff changeset
  2603
    ^ self bindTo:(aSocketAddress portOrName)
claus
parents: 63
diff changeset
  2604
	   address:(aSocketAddress address)
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2605
	   reuseAddress:true
71
claus
parents: 63
diff changeset
  2606
!
claus
parents: 63
diff changeset
  2607
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2608
bindTo:portNrOrNameString address:addressString
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2609
    "low level bind - returns true if ok, false otherwise.
71
claus
parents: 63
diff changeset
  2610
     Currently only non-address binding is supported; 
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2611
     i.e. the address must always be nil.
71
claus
parents: 63
diff changeset
  2612
claus
parents: 63
diff changeset
  2613
     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
  2614
	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
  2615
	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
  2616
	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
  2617
     "
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2618
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2619
    ^ self 
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2620
	bindTo:portNrOrNameString 
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2621
	address:addressString 
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2622
	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
  2623
!
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2624
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2625
bindTo:portNrOrName address:address reuseAddress:reuse
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2626
    "low level bind - returns true if ok, false otherwise.
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2627
     Currently only non-address binding is supported; 
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2628
     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
  2629
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2630
     The interpretation of portNrOrName depends on the domain:
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2631
	inet domain uses (4byte) byteArray like internet numbers,
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2632
	unix domain uses pathname strings,
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2633
	others use whatever will come up in the future
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2634
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2635
     The reuse boolean argument controls if the SO_REUSEADDR socket option
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2636
     is to be set (to avoid the 'bind: address in use' error).
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2637
    "
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2638
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2639
    filePointer isNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2640
	^ self errorNotOpen
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2641
    ].
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2642
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  2643
#ifndef NO_SOCKET
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2644
    OBJ t = __INST(filePointer);
71
claus
parents: 63
diff changeset
  2645
    OBJ myDomain;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2646
    int sock;
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2647
    union sockaddr_u sa;
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2648
    int sockaddr_size;
6
claus
parents: 4
diff changeset
  2649
    int ret;
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  2650
    int on = 1;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2651
    int ok;
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2652
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2653
    if (!__isString(__INST(domain)) && !__isSymbol(__INST(domain))) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2654
	DBGPRINTF(("SOCKET: invalid domain arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2655
	RETURN (false);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2656
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2657
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2658
    ok = 0;
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2659
    myDomain = __INST(domain);
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2660
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2661
# ifdef AF_INET
71
claus
parents: 63
diff changeset
  2662
    if (myDomain == @symbol(inet)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2663
	/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2664
	 * INET addresses - port must be a smallinteger or nil
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2665
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2666
	sa.in.sin_family = AF_INET;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2667
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2668
	if (portNrOrName == nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2669
	    sa.in.sin_port = 0;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2670
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2671
	    if (! __isSmallInteger(portNrOrName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2672
		DBGPRINTF(("SOCKET: invalid port arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2673
		RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2674
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2675
	    sa.in.sin_port = htons((u_short) _intVal(portNrOrName));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2676
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2677
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2678
	/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2679
	 * INET addresses - addr must be nil, integer or byteArray
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2680
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2681
	if (address == nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2682
	    sa.in.sin_addr.s_addr = htonl(INADDR_ANY);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2683
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2684
	    if (__isInteger(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2685
		sa.in.sin_addr.s_addr = htonl(__longIntVal(address));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2686
	    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2687
		if (__isByteArray(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2688
		    unsigned char *cp;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2689
		    int n;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2690
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2691
		    cp = __ByteArrayInstPtr(address)->ba_element;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2692
		    n = __byteArraySize(address);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2693
		    if (n > 4) n = 4;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2694
		    bcopy(cp, &sa.in.sin_addr.s_addr, n);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2695
		} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2696
		    unsigned addr;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2697
		    struct hostent *hp ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2698
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2699
		    if (! __isString(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2700
			DBGPRINTF(("SOCKET: invalid address arg in bind\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2701
			RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2702
		    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2703
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2704
		    if ((addr = inet_addr(__stringVal(address))) != -1) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2705
			/* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2706
			 * is Internet addr in octet notation 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2707
			 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2708
			bcopy(&addr, (char *) &sa.in.sin_addr, sizeof(addr)) ; /* set address */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2709
		    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2710
			/* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2711
			 * do we know the host's address? 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2712
			 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2713
			GETHOSTBYNAME(hp, __stringVal(address))
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2714
			if (hp == NULL) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2715
			    DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(address)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2716
			    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2717
			}
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2718
			if (hp->h_addrtype != AF_INET) {
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2719
			    DBGPRINTF(("SOCKET: host:%s is not an inet host\n", __stringVal(address)));
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2720
			    RETURN (false);
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2721
			}
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2722
			bcopy(hp->h_addr, (char *) &sa.in.sin_addr, hp->h_length) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2723
			sa.in.sin_family = hp->h_addrtype;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2724
		    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2725
		}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2726
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2727
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2728
	DBGPRINTF(("SOCKET: bind addr: %x port: %x\n", sa.in.sin_addr.s_addr, sa.in.sin_port));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2729
	sockaddr_size = sizeof(struct sockaddr_in);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2730
	ok = 1;
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2731
    }
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2732
# endif /* AF_INET */
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2733
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2734
# ifdef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2735
    if (myDomain == @symbol(inet6)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2736
	/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2737
	 * INET6 addresses - port must be a smallinteger or nil
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2738
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2739
	sa.in6.sin6_family = AF_INET6;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2740
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2741
	if (portNrOrName == nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2742
	    sa.in6.sin6_port = 0;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2743
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2744
	    if (! __isSmallInteger(portNrOrName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2745
		DBGPRINTF(("SOCKET: invalid port arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2746
		RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2747
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2748
	    sa.in6.sin6_port = htons((u_short) _intVal(portNrOrName));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2749
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2750
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2751
	/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2752
	 * INET6 addresses - addr must be nil or byteArray or string
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2753
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2754
	if (address == nil) {
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2755
	    bzero(sa.in6.sin6_addr.s6_addr, sizeof(sa.in6.sin6_addr.s6_addr));
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2756
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2757
	    if (__isByteArray(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2758
		unsigned char *cp;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2759
		int n;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2760
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2761
		cp = __ByteArrayInstPtr(address)->ba_element;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2762
		n = __byteArraySize(address);
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2763
		if (n > sizeof(sa.in6.sin6_addr.s6_addr)) n = sizeof(sa.in6.sin6_addr.s6_addr);
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2764
		bcopy(cp, sa.in6.sin6_addr.s6_addr, n);
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2765
	    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2766
		unsigned addr;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2767
		struct hostent *hp ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2768
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2769
		if (! __isString(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2770
		    DBGPRINTF(("SOCKET: invalid address arg in bind\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2771
		    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2772
		}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2773
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2774
		/* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2775
		 * do we know the host's address? 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2776
		 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2777
		GETHOSTBYNAME(hp, __stringVal(address))
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2778
		if (hp == NULL) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2779
		    DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(address)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2780
		    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2781
		}
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2782
		if (hp->h_addrtype != AF_INET6) {
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2783
		    DBGPRINTF(("SOCKET: host:%s is not an ipv6 host\n", __stringVal(address)));
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2784
		    RETURN (false);
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2785
		}
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2786
		bcopy(hp->h_addr, (char *) &sa.in6.sin6_addr, hp->h_length) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2787
		sa.in.sin_family = hp->h_addrtype;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2788
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2789
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2790
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2791
	DBGPRINTF(("SOCKET: bind addr: %x.%x.%x.%x.%x.%x... port: %x\n", 
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2792
			sa.in6.sin6_addr.s6_addr[0], 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2793
			sa.in6.sin6_addr.s6_addr[1], 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2794
			sa.in6.sin6_addr.s6_addr[2], 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2795
			sa.in6.sin6_addr.s6_addr[3], 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2796
			sa.in6.sin6_addr.s6_addr[4], 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2797
			sa.in6.sin6_addr.s6_addr[5], 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2798
			sa.in6.sin6_port));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2799
	sockaddr_size = sizeof(struct sockaddr_in6);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2800
	ok = 1;
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2801
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2802
# endif /* AF_INET6 */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2803
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2804
# ifdef AF_UNIX
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2805
    /*
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2806
     * UNIX domain - port is ignored; address must be a string (path)
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2807
     */
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2808
    if (myDomain == @symbol(unix)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2809
	char *pathName;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2810
	int l;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2811
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2812
	if (! __isString(portNrOrName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2813
	    DBGPRINTF(("SOCKET: invalid port (pathname) arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2814
	    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2815
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2816
	pathName = (char *)__stringVal(portNrOrName);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2817
	l = strlen(pathName);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2818
	if ((l + sizeof ( sa.un.sun_family )) > sizeof(struct sockaddr_un)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2819
	    DBGPRINTF(("SOCKET: pathname too long\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2820
	    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2821
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2822
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2823
	strcpy(sa.un.sun_path, pathName);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2824
	sa.un.sun_family = AF_UNIX;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2825
	sockaddr_size = l + sizeof ( sa.un.sun_family );
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2826
	ok = 1;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2827
    }
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2828
# endif /* AF_UNIX */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2829
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2830
# ifdef AF_APPLETALK
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2831
    /*
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2832
     * this has never been tested ....
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2833
     */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2834
    if (myDomain == @symbol(appletalk)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2835
	/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2836
	 * APPLETALK addresses - port must be a smallinteger or nil
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2837
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2838
	sa.at.sat_family = AF_APPLETALK;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2839
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2840
	if (portNrOrName == nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2841
	    sa.at.sat_port = 0;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2842
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2843
	    if (! __isSmallInteger(portNrOrName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2844
		DBGPRINTF(("SOCKET: invalid port arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2845
		RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2846
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2847
	    sa.at.sat_port = __intVal(portNrOrName);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2848
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2849
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2850
	/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2851
	 * APPLETALK addresses - addr must be nil, integer or byteArray
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2852
	 * if integer, the first byte are the hi net bits, next byte are low net bits,
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2853
	 * last byte is node.
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2854
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2855
	if (address == nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2856
	    sa.at.sat_addr.s_net = ATADDR_ANYNET;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2857
	    sa.at.sat_addr.s_node = ATADDR_ANYNODE;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2858
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2859
	    if (__isInteger(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2860
		unsigned a = __longIntVal(address);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2861
		sa.at.sat_addr.s_net = htons((a >> 8) & 0xFFFF);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2862
		sa.at.sat_addr.s_node = htons(a & 0xFF);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2863
	    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2864
		if (__isByteArray(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2865
		    unsigned char *cp;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2866
		    int n;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2867
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2868
		    cp = __ByteArrayInstPtr(address)->ba_element;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2869
		    n = __byteArraySize(address);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2870
		    if (n > 3) n = 3;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2871
		    bcopy(cp, &sa.at.sat_addr, n);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2872
		} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2873
		    unsigned addr;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2874
		    struct hostent *hp ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2875
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2876
		    if (! __isString(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2877
			DBGPRINTF(("SOCKET: invalid address arg in bind\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2878
			RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2879
		    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2880
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2881
		    /* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2882
		     * do we know the host's address? 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2883
		     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2884
		    GETHOSTBYNAME(hp, __stringVal(address))
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2885
		    if (hp == NULL) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2886
			DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(address)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2887
			RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2888
		    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2889
		    if (hp->h_addrtype != AF_APPLETALK) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2890
			DBGPRINTF(("SOCKET: host:%s is not an appletalk host\n", __stringVal(address)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2891
			RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2892
		    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2893
		    bcopy(hp->h_addr, (char *) &sa.at.sat_addr, hp->h_length) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2894
		    sa.at.sat_family = hp->h_addrtype;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2895
		}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2896
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2897
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2898
	DBGPRINTF(("SOCKET: bind addr: %x port: %x\n", sa.in.sin_addr.s_addr, sa.in.sin_port));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2899
	sockaddr_size = sizeof(struct sockaddr_at);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2900
	ok = 1;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2901
    }
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2902
# endif /* AF_APPLETALK */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2903
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2904
    /*
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2905
     * XXXX add addressing stuff for other domains here ...
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2906
     */
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2907
# ifdef AF_X25
71
claus
parents: 63
diff changeset
  2908
    if (myDomain == @symbol(x25)) {
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2909
    }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2910
# endif
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2911
# ifdef AF_AX25
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2912
    if (myDomain == @symbol(ax25)) {
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2913
    }
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2914
# endif
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2915
# ifdef AF_NS
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2916
    if ((myDomain == @symbol(ns)) 
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2917
     || (myDomain == @symbol(xns))) {
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2918
    }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2919
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2920
# ifdef AF_DECnet
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2921
    if (myDomain == @symbol(decnet)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2922
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2923
# endif
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2924
# ifdef AF_SNA
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  2925
    if (myDomain == @symbol(sna)) {
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  2926
    }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2927
# endif
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2928
# ifdef AF_RAW
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  2929
    if (myDomain == @symbol(raw)) {
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  2930
    }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2931
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2932
# ifdef AF_ISO
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2933
    if (myDomain == @symbol(iso)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2934
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2935
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2936
# ifdef AF_NETBIOS
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2937
    if (myDomain == @symbol(netbios)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2938
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2939
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2940
# ifdef AF_IPX
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2941
    if (myDomain == @symbol(ipx)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2942
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2943
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2944
# ifdef AF_BRIDGE
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2945
    if (myDomain == @symbol(bridge)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2946
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2947
# endif
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2948
# ifdef AF_BSC
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2949
    if (myDomain == @symbol(bsc)) {
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2950
    }
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2951
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2952
# ifdef AF_ROSE
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2953
    if (myDomain == @symbol(rose)) {
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2954
    }
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2955
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2956
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2957
    if (myDomain == @symbol(ccitt)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2958
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2959
# endif
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2960
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2961
    if (! ok) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2962
	DBGPRINTF(("SOCKET: unsupported domain\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2963
	RETURN (false);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2964
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2965
110
7af19ae8693b use new FILE* wrapper macros (based on externalAddress)
Claus Gittinger <cg@exept.de>
parents: 106
diff changeset
  2966
    sock = fileno(__FILEVal(t));
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2967
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2968
# ifdef SO_REUSEADDR
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2969
    if (reuse == true) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2970
	if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2971
	    DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2972
	}
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2973
    }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2974
# endif /* SO_REUSEADDR */
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2975
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
  2976
    __BEGIN_INTERRUPTABLE__
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2977
    do {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2978
	ret = bind(sock, (struct sockaddr *)&sa, sockaddr_size);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2979
    } while ((ret < 0) && (errno == EINTR));
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
  2980
    __END_INTERRUPTABLE__
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2981
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2982
    if (ret < 0) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2983
	DBGPRINTF(("SOCKET: bind failed errno=%d\n", errno));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2984
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2985
	RETURN (false);
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2986
    }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2987
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2988
    __INST(port) = portNrOrName; __STORE(self, portNrOrName);
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2989
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2990
# ifdef AF_INET
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2991
    if (myDomain == @symbol(inet)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2992
	if (! __isSmallInteger(portNrOrName)
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2993
	 || (portNrOrName == __MKSMALLINT(0))) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2994
	    int p;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2995
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2996
	    /*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2997
	     * INET anonymous port - get the actual portNr
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2998
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2999
	    if (getsockname(sock, (struct sockaddr *)&sa, &sockaddr_size) < 0) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3000
		DBGPRINTF(("SOCKET: cannot get peername\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3001
	    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3002
		DBGPRINTF(("SOCKET: anon port=%x\n", sa.in.sin_port));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3003
		p = ntohs(sa.in.sin_port);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3004
		__INST(port) = __MKSMALLINT(p);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3005
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3006
	}
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3007
    }
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3008
# endif
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3009
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3010
# ifdef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3011
    if (myDomain == @symbol(inet6)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3012
	if (! __isSmallInteger(portNrOrName)
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3013
	 || (portNrOrName == __MKSMALLINT(0))) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3014
	    int p;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3015
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3016
	    /*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3017
	     * INET6 anonymous port - get the actual portNr
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3018
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3019
	    if (getsockname(sock, (struct sockaddr *)&sa, &sockaddr_size) < 0) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3020
		DBGPRINTF(("SOCKET: cannot get peername\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3021
	    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3022
		DBGPRINTF(("SOCKET: anon port=%x\n", sa.in.sin_port));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3023
		p = ntohs(sa.in6.sin6_port);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3024
		__INST(port) = __MKSMALLINT(p);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3025
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3026
	}
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3027
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3028
# endif
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3029
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3030
# ifdef AF_APPLETALK
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3031
    if (myDomain == @symbol(appletalk)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3032
	if (! __isSmallInteger(portNrOrName)
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3033
	 || (portNrOrName == __MKSMALLINT(0))) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3034
	    int p;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3035
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3036
	    /*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3037
	     * APPLETALK anonymous port - get the actual portNr
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3038
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3039
	    if (getsockname(sock, (struct sockaddr *)&sa, &sockaddr_size) < 0) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3040
		DBGPRINTF(("SOCKET: cannot get peername\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3041
	    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3042
		DBGPRINTF(("SOCKET: anon port=%x\n", sa.in.sin_port));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3043
		p = sa.at.sat_port;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3044
		__INST(port) = __MKSMALLINT(p);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3045
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3046
	}
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3047
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3048
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3049
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3050
#else /* NO_SOCKET */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3051
    RETURN (false);
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3052
#endif /* NO_SOCKET */
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  3053
%}.
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3054
    ^ true
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  3055
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3056
    "
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3057
     (Socket domain:#inet type:#stream)
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3058
	 bindTo:9999
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3059
	 address:nil
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3060
    "
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  3061
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  3062
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3063
closeFile
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3064
    "low level close"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3065
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3066
%{  /* NOCONTEXT */
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3067
#ifndef NO_SOCKET
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3068
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3069
    OBJ t;
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3070
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3071
    t = __INST(filePointer);
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3072
    if (t != nil) {
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3073
	FILE *fp;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3074
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3075
	fp = __FILEVal(t);
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
  3076
	DBGFPRINTF((stderr, "socket fclose %x (%d)\n", fp, fileno(fp)));
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3077
	fflush(fp);
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3078
	/* shutdown(fileno(fp), 2); */
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3079
	fclose(fp);
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3080
	__INST(filePointer) = nil;
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3081
    }
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3082
#endif
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3083
%}
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3084
!
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3085
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3086
listenFor:aNumber
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3087
    "same as listenWithBacklog: - for ST-80 compatibility"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3088
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3089
    ^ self listenWithBacklog:aNumber
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3090
!
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3091
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3092
listenWithBacklog:aNumber
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3093
    "start listening; return true if ok, false on error"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3094
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3095
    filePointer isNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3096
	^ self errorNotOpen
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3097
    ].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3098
%{
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3099
#ifndef NO_SOCKET
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3100
    OBJ fp = __INST(filePointer);
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3101
    int sock;
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3102
    int ret;
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3103
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3104
    if (! __isSmallInteger(aNumber)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3105
	DBGPRINTF(("SOCKET: invalid arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3106
	RETURN (false);
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3107
    }
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3108
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3109
    sock = fileno(__FILEVal(fp));
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3110
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3111
    __BEGIN_INTERRUPTABLE__
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3112
    do {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3113
	ret = listen(sock, _intVal(aNumber));
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3114
    } while ((ret < 0) && (errno == EINTR));
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3115
    __END_INTERRUPTABLE__
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3116
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3117
    if (ret < 0) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3118
	DBGPRINTF(("SOCKET: listen call failed errno=%d\n", errno));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3119
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3120
	RETURN (false);
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3121
    }
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3122
#else
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3123
    RETURN (false);
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3124
#endif
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3125
%}.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3126
    ^ true
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3127
!
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3128
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3129
shutDown 
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3130
    "shutDown without flushing "
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3131
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3132
    filePointer isNil ifTrue:[^ self].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3133
    Lobby unregister:self.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3134
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3135
%{
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3136
#ifndef NO_SOCKET
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3137
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3138
    OBJ fp;
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3139
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3140
    fp = __INST(filePointer);
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3141
    if (fp != nil) {
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3142
	FILE *f;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3143
	int fd;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3144
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3145
	__INST(filePointer) = nil;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3146
	f = __FILEVal(fp);
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3147
	fd = fileno(f);
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3148
	__BEGIN_INTERRUPTABLE__
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3149
	shutdown(fd, 2);
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
  3150
	DBGFPRINTF((stderr, "socket fclose %x (%d)\n", fp, fd));
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3151
	fclose(f);
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3152
	/* close(fd); */
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3153
	__END_INTERRUPTABLE__
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3154
    }
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3155
#endif
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3156
%}
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3157
! !
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3158
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3159
!Socket methodsFor:'low level-accepting'!
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3160
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3161
accept
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3162
    "create a new TCP socket from accepting on the receiver.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3163
     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
  3164
     For ST-80 compatibility"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3165
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3166
    |newSock|
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3167
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3168
    newSock := self class new.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3169
    (newSock acceptOn:self) ifFalse:[^ nil].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3170
    ^ newSock
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3171
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3172
    "
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3173
     |sock newSock|
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3174
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3175
     sock := Socket provide:8004.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3176
     sock listenFor:5.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3177
     newSock := sock accept.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3178
    "
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3179
!
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3180
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3181
acceptOn:aSocket
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3182
    "accept a connection on a server port (created with:'Socket>>onIPPort:')
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3183
     usage is: (Socket basicNew acceptOn:(Socket onIPPort:9999)).
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3184
     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
  3185
     Return the true if ok; false if not."
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3186
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3187
    aSocket readWriteWait.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3188
    ^ self blockingAcceptOn:aSocket
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3189
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3190
    "Modified: / 11.3.1996 / 14:21:31 / stefan"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3191
    "Modified: / 1.8.1998 / 23:39:10 / cg"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3192
!
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3193
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3194
blockingAcceptOn:aSocket
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3195
    "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
  3196
     usage is: (Socket basicNew acceptOn:(Socket onIPPort:9999)).
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3197
     Return the true if ok; false if not.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3198
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3199
     NOTICE: this method will block, if no connection is already pending.
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3200
	     use readWait or Socket>>accept."
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3201
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3202
    |serverSocketFd|
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3203
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3204
    filePointer notNil ifTrue:[
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3205
	^ self errorAlreadyOpen
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3206
    ].
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3207
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3208
    domain := aSocket domain.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3209
    socketType := aSocket type.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3210
    serverSocketFd := aSocket fileDescriptor.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3211
    serverSocketFd isNil ifTrue:[
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3212
	^ 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
  3213
    ].
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3214
    (serverSocketFd isMemberOf:SmallInteger) ifFalse:[
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3215
	^ 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
  3216
    ].
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3217
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3218
#ifndef NO_SOCKET
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3219
    FILE *fp;
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3220
    int flags;
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3221
    int sock, newSock;
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3222
    union sockaddr_u sa;
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  3223
    int alen, alen0;
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3224
    struct hostent *he ;
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3225
    char dotted[20] ;
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3226
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3227
    sock = _intVal(serverSocketFd);
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3228
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3229
#if defined(O_NDELAY) && defined(SET_NDELAY)
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3230
    flags = ioctl(sock, F_GETFL, 0);
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3231
    ioctl(sock, F_SETFL, flags | O_NDELAY);
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3232
#endif
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  3233
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  3234
#ifdef AF_INET
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  3235
    if (__INST(domain) == @symbol(inet)) {
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3236
	alen0 = sizeof(sa.in);
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  3237
    }
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  3238
#endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3239
#ifdef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3240
    if (__INST(domain) == @symbol(inet6)) {
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3241
	alen0 = sizeof(sa.in6);
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3242
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3243
#endif
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  3244
#ifdef AF_UNIX
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  3245
    if (__INST(domain) == @symbol(unix)) {
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3246
	alen0 = sizeof(sa.un);
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  3247
    }
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  3248
#endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3249
# ifdef AF_APPLETALK
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3250
    if (__INST(domain) == @symbol(appletalk)) {
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3251
	alen0 = sizeof(sa.at);
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3252
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3253
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3254
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3255
    /*
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3256
     * XXXX add addressing stuff for other domains here ...
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3257
     */
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3258
# ifdef AF_X25
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3259
    if (__INST(domain) == @symbol(x25)) {
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3260
	alen0 = sizeof(sa.x25);
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3261
    }
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3262
# endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3263
# ifdef AF_AX25
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3264
    if (__INST(domain) == @symbol(ax25)) {
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3265
	alen0 = sizeof(sa.ax25);
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3266
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3267
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3268
# ifdef AF_NS
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3269
    if ((__INST(domain) == @symbol(ns)) 
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3270
     || (__INST(domain) == @symbol(xns))) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3271
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3272
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3273
# ifdef AF_DECnet
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3274
    if (__INST(domain) == @symbol(decnet)) {
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3275
	alen0 = sizeof(sa.dn);
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3276
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3277
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3278
# ifdef AF_SNA
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3279
    if (__INST(domain) == @symbol(sna)) {
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3280
	alen0 = sizeof(sa.sna);
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3281
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3282
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3283
# ifdef AF_RAW
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3284
    if (__INST(domain) == @symbol(raw)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3285
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3286
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3287
# ifdef AF_ISO
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3288
    if (__INST(domain) == @symbol(iso)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3289
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3290
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3291
# ifdef AF_NETBIOS
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3292
    if (__INST(domain) == @symbol(netbios)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3293
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3294
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3295
# ifdef AF_IPX
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3296
    if (__INST(domain) == @symbol(ipx)) {
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3297
	alen0 = sizeof(sa.ipx);
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3298
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3299
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3300
# ifdef AF_BRIDGE
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3301
    if (__INST(domain) == @symbol(bridge)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3302
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3303
# endif
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3304
# ifdef AF_BSC
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3305
    if (__INST(domain) == @symbol(bsc)) {
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3306
    }
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3307
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3308
# ifdef AF_ROSE
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3309
    if (__INST(domain) == @symbol(rose)) {
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3310
    }
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3311
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3312
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3313
    if (__INST(domain) == @symbol(ccitt)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3314
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3315
# endif
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  3316
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3317
    __BEGIN_INTERRUPTABLE__
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3318
    do {
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3319
	alen = alen0;
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3320
	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
  3321
    } 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
  3322
    __END_INTERRUPTABLE__
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
  3323
    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
  3324
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3325
#if defined(O_NDELAY) && defined(SET_NDELAY)
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3326
    ioctl(sock, F_SETFL, flags);
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3327
#endif
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3328
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3329
    if (newSock < 0) {
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3330
	DBGPRINTF(("SOCKET: accept call failed errno=%d\n", errno));
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3331
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3332
	RETURN (false);
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3333
    }
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3334
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3335
    /*
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3336
     * extract the partners address
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3337
     */
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3338
#ifdef AF_INET
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  3339
    if (__INST(domain) == @symbol(inet)) {
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3340
	GETHOSTBYADDR(he, (char *) &sa.in.sin_addr, sizeof(sa.in.sin_addr), AF_INET);
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3341
	if (! he) {
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3342
	    unsigned long norder;
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3343
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3344
	    norder = htonl(sa.in.sin_addr.s_addr) ;
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3345
	    sprintf(dotted, "%d.%d.%d.%d",
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3346
		    (norder >> 24) & 0xFF,
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3347
		    (norder >> 16) & 0xFF,
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3348
		    (norder >> 8) & 0xFF,
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3349
		    norder & 0xFF);
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3350
	}
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3351
	DBGPRINTF(("SOCKET: accepted connection from host %s\n", (he ? he->h_name : dotted))) ;
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3352
	__INST(peerName) = __MKSTRING((he ? he->h_name : dotted));
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3353
	__STORESELF(peerName);
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3354
    }
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3355
#endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3356
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3357
#ifdef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3358
    if (__INST(domain) == @symbol(inet6)) {
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3359
	GETHOSTBYADDR(he, (char *) &sa.in6.sin6_addr, sizeof(sa.in6.sin6_addr), AF_INET6);
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3360
	if (! he) {
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3361
	    unsigned long norder;
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3362
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3363
	    /*
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3364
	     * XXX: what is inet6's naming convention ?
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3365
	     */
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3366
	    norder = htonl(sa.in.sin_addr.s_addr) ;
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3367
	    sprintf(dotted, "%d.%d.%d.%d.%d.%d...",
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3368
		    sa.in6.sin6_addr.s6_addr[0],
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3369
		    sa.in6.sin6_addr.s6_addr[1],
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3370
		    sa.in6.sin6_addr.s6_addr[2],
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3371
		    sa.in6.sin6_addr.s6_addr[3],
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3372
		    sa.in6.sin6_addr.s6_addr[4],
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3373
		    sa.in6.sin6_addr.s6_addr[5]);
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3374
	}
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3375
	DBGPRINTF(("SOCKET: accepted connection from host %s\n", (he ? he->h_name : dotted))) ;
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3376
	__INST(peerName) = __MKSTRING((he ? he->h_name : dotted));
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3377
	__STORESELF(peerName);
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3378
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3379
#endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3380
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3381
#ifdef AF_UNIX
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  3382
    if (__INST(domain) == @symbol(unix)) {
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3383
	DBGPRINTF(("SOCKET: accepted connection on unix socket\n")) ;
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3384
	/* nothing to be done here */
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3385
    }
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3386
#endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3387
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3388
#ifdef AF_APPLETALK
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3389
    if (__INST(domain) == @symbol(appletalk)) {
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3390
	GETHOSTBYADDR(he, (char *) &sa.at.sat_addr, sizeof(sa.at.sat_addr), AF_APPLETALK);
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3391
	if (! he) {
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3392
	    unsigned net;
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3393
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3394
	    /*
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3395
	     * XXX: what is apples naming convention ?
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3396
	     */
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3397
	    net = htons(sa.at.sat_addr.s_net) ;
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3398
	    sprintf(dotted, "%d.%d",
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3399
		    net,
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3400
		    sa.at.sat_addr.s_node);
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3401
	}
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3402
	DBGPRINTF(("SOCKET: accepted connection from host %s\n", (he ? he->h_name : dotted))) ;
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3403
	__INST(peerName) = __MKSTRING((he ? he->h_name : dotted));
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3404
	__STORESELF(peerName);
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3405
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3406
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3407
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3408
    /*
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3409
     * XXXX add addressing stuff for other domains here ...
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3410
     */
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3411
# ifdef AF_X25
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3412
    if (__INST(domain) == @symbol(x25)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3413
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3414
# endif
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3415
# ifdef AF_AX25
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3416
    if (__INST(domain) == @symbol(ax25)) {
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3417
    }
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3418
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3419
# ifdef AF_NS
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3420
    if ((__INST(domain) == @symbol(ns)) 
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3421
     || (__INST(domain) == @symbol(xns))) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3422
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3423
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3424
# ifdef AF_DECnet
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3425
    if (__INST(domain) == @symbol(decnet)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3426
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3427
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3428
# ifdef AF_SNA
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3429
    if (__INST(domain) == @symbol(sna)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3430
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3431
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3432
# ifdef AF_RAW
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3433
    if (__INST(domain) == @symbol(raw)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3434
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3435
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3436
# ifdef AF_ISO
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3437
    if (__INST(domain) == @symbol(iso)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3438
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3439
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3440
# ifdef AF_NETBIOS
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3441
    if (__INST(domain) == @symbol(netbios)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3442
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3443
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3444
# ifdef AF_IPX
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3445
    if (__INST(domain) == @symbol(ipx)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3446
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3447
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3448
# ifdef AF_BRIDGE
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3449
    if (__INST(domain) == @symbol(bridge)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3450
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3451
# endif
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3452
# ifdef AF_BSC
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3453
    if (__INST(domain) == @symbol(bsc)) {
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3454
    }
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3455
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3456
# ifdef AF_ROSE
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3457
    if (__INST(domain) == @symbol(rose)) {
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3458
    }
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3459
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3460
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3461
    if (__INST(domain) == @symbol(ccitt)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3462
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3463
# endif
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3464
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3465
    /* 
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3466
     * make it a FILE * 
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3467
     */
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3468
    fp = fdopen(newSock, "r+");
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3469
    if (! fp) {
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3470
	DBGPRINTF(("SOCKET: fdopen call failed\n"));
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3471
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3472
	close(newSock);
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
  3473
	DBGFPRINTF((stderr, "socket close (fdopen failed) (%d)\n", newSock));
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3474
	RETURN (false);
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3475
    } else {
444
9ba31a1fba38 always unbuffered on linux
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
  3476
#ifdef BUGGY_STDIO_LIB
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3477
	setbuf(fp, NULL);
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3478
	__INST(buffered) = false;
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3479
#endif
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3480
	__INST(filePointer) = __MKOBJ(fp);
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  3481
	__STORESELF(filePointer);
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3482
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3483
#endif
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3484
%}.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3485
    mode := #readwrite.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3486
    Lobby register:self.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3487
    binary := false.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3488
    port := aSocket port.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3489
    ^ true
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3490
!
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3491
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3492
waitForNewConnectionOrDataOnAny:otherConnections timeout:timeoutSeconds
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3493
    "suspend the current process, until either a new connection comes
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3494
     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
  3495
     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
  3496
     For an old connection, that socket is returned.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3497
     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
  3498
     or nil, if a timeout occured.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3499
     This method implements the inner wait-primitive of a multi-connection 
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3500
     server application."
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3501
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3502
    "/ first, a quick check if data is already available
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3503
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3504
    |connection wasBlocked sema|
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3505
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3506
    self canReadWithoutBlocking ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3507
	^ self accept.
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3508
    ].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3509
    otherConnections do:[:aConnection |
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3510
	aConnection canReadWithoutBlocking ifTrue:[
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3511
	    ^ aConnection
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3512
	]
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3513
    ].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3514
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3515
    [
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3516
	"/ check again - prevent incoming interrupts from disturbing our setup
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3517
	wasBlocked := OperatingSystem blockInterrupts.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3518
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3519
	self canReadWithoutBlocking ifTrue:[
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3520
	    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3521
	    ^ self accept.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3522
	].
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3523
	otherConnections do:[:aConnection |
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3524
	    aConnection canReadWithoutBlocking ifTrue:[
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3525
		wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3526
		^ aConnection
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3527
	    ]
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3528
	].
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3529
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3530
	"/ nope - must wait.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3531
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3532
	sema := Semaphore new name:'multiReadWait'.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3533
	otherConnections do:[:aConnection |
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3534
	    Processor signal:sema onInput:(aConnection fileDescriptor).
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3535
	].
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3536
	Processor signal:sema onInput:(self fileDescriptor).
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3537
	timeoutSeconds notNil ifTrue:[
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3538
	    Processor signal:sema afterSeconds:timeoutSeconds 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3539
	].
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3540
	Processor activeProcess state:#ioWait.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3541
	sema wait.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3542
	Processor disableSemaphore:sema.
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3543
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3544
    ] valueOnUnwindDo:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3545
	Processor disableSemaphore:sema.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3546
	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3547
    ].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3548
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3549
    "/ see who it was ...
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3550
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3551
    self canReadWithoutBlocking ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3552
	^ self accept.
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3553
    ].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3554
    otherConnections do:[:aConnection |
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3555
	aConnection canReadWithoutBlocking ifTrue:[
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3556
	    ^ aConnection
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3557
	]
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3558
    ].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3559
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3560
    "/ none - a timeout
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3561
    ^ nil
867
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3562
!
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3563
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3564
waitForNewConnectionWithTimeout:timeoutSeconds
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3565
    "suspend the current process, until a new connection comes
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3566
     in at the receiver or a timeout occurs.
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3567
     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
  3568
     Returns nil, if a timeout occured.
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3569
     This method implements the inner wait-primitive of a single-connection 
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3570
     server application."
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3571
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3572
    |newConnection|
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3573
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3574
    (self readWaitWithTimeout:timeoutSeconds) ifTrue:[
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3575
	"/ a timeout occurred - no connection within timeout
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3576
	^ nil
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3577
    ].
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3578
    ^ self accept.
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3579
! !
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3580
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3581
!Socket methodsFor:'low level-connecting'!
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
  3582
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  3583
connectTo:hostOrPathName port:portNrOrName
71
claus
parents: 63
diff changeset
  3584
    "low level connect; connect to port, portNrOrName on host, hostName.
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  3585
     For unix-domain sockets, the port argument is ignored and pathName is taken.
115
a9d85df931c4 added Unix domain support
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  3586
     Other sockets are not yet implemented.
71
claus
parents: 63
diff changeset
  3587
     Return true if ok, false otherwise.
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
  3588
     Hostname must be a string, portNrOrName an integer port number (in inet domain).
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
  3589
     The current process will block (but not the whole Smalltalk) until the connection
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  3590
     is established. 
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  3591
     See also: #connectTo:port:withTimeout: for a somewhat nicer interface."
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3592
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3593
    ^ self connectTo:hostOrPathName port:portNrOrName blocking:false
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3594
!
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3595
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3596
connectTo:hostOrPathName port:portNrOrName blocking:blocking
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3597
    "low level connect; connect to port, portNrOrName on host, hostName.
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3598
     For unix-domain sockets, the port argument is ignored and pathName is taken.
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3599
     Other sockets are not yet implemented.
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3600
     Return true if ok, false otherwise.
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3601
     Hostname must be a string, portNrOrName an integer port number (in inet domain).
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3602
     The current process will block (but not the whole Smalltalk) until the connection
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3603
     is established. 
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3604
     See also: #connectTo:port:withTimeout: for a somewhat nicer interface."
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3605
430
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  3606
    |isAsync|
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  3607
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3608
    filePointer isNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3609
	^ self errorNotOpen
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3610
    ].
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  3611
%{
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3612
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3613
#ifndef NO_SOCKET
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  3614
    OBJ t = __INST(filePointer);
71
claus
parents: 63
diff changeset
  3615
    OBJ myDomain;
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3616
    union sockaddr_u sa;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3617
    struct hostent *hp ;
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3618
    int a, sock ;
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3619
    long addr;
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3620
    FILE *fp;
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3621
    int ret, oldFlags;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3622
    int on = 1;
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3623
    int ok;
115
a9d85df931c4 added Unix domain support
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  3624
    int sockaddr_size;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3625
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  3626
    if (!__isString(__INST(domain)) && !__isSymbol(__INST(domain))) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3627
	DBGPRINTF(("SOCKET: invalid domain arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3628
	RETURN (false);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3629
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3630
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3631
    ok = 0;
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  3632
    myDomain = __INST(domain);
115
a9d85df931c4 added Unix domain support
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  3633
    bzero((char *) &sa, sizeof(sa)) ;
508
55d1e49c7157 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
  3634
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3635
#ifdef AF_INET
71
claus
parents: 63
diff changeset
  3636
    if (myDomain == @symbol(inet)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3637
	/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3638
	 * INET addressing: port must be a smallInteger;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3639
	 * hostOrPathName the name of the host (dot notation allowed)
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3640
	 * or a byteArray containing the 4 address bytes.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3641
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3642
	if (! __isSmallInteger(portNrOrName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3643
	    DBGPRINTF(("SOCKET: invalid port arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3644
	    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3645
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3646
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3647
	sa.in.sin_family = AF_INET;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3648
	sa.in.sin_port = htons((u_short) _intVal(portNrOrName)) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3649
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3650
	if (__isByteArray(hostOrPathName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3651
	    unsigned char *cp;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3652
	    int n;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3653
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3654
	    cp = __ByteArrayInstPtr(hostOrPathName)->ba_element;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3655
	    n = __byteArraySize(hostOrPathName);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3656
	    if (n > 4) n = 4;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3657
	    bcopy(cp, &sa.in.sin_addr.s_addr, n);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3658
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3659
	    if (! __isString(hostOrPathName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3660
		DBGPRINTF(("SOCKET: invalid hostname arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3661
		RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3662
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3663
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3664
	    if ((addr = inet_addr(__stringVal(hostOrPathName))) != -1) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3665
		/* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3666
		 * is Internet addr in octet notation 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3667
		 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3668
		bcopy(&addr, (char *) &sa.in.sin_addr, sizeof(addr)) ; /* set address */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3669
	    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3670
		/* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3671
		 * do we know the host's address? 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3672
		 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3673
		GETHOSTBYNAME(hp, __stringVal(hostOrPathName))
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3674
		if (hp == NULL) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3675
		    DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(hostOrPathName)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3676
		    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3677
		}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3678
		bcopy(hp->h_addr, (char *) &sa.in.sin_addr, hp->h_length) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3679
		sa.in.sin_family = hp->h_addrtype;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3680
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3681
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3682
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3683
	DBGPRINTF(("SOCKET: connect addr: %x port: %d\n", sa.in.sin_addr, sa.in.sin_port));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3684
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3685
	sockaddr_size = sizeof(struct sockaddr_in);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3686
	ok = 1;
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  3687
    }
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3688
#endif /* AF_INET */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3689
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3690
#ifdef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3691
    if (myDomain == @symbol(inet6)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3692
	/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3693
	 * INET6 addressing: port must be a smallInteger;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3694
	 * hostOrPathName the name of the host
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3695
	 * or a byteArray containing the address bytes.
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3696
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3697
	if (! __isSmallInteger(portNrOrName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3698
	    DBGPRINTF(("SOCKET: invalid port arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3699
	    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3700
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3701
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3702
	sa.in6.sin6_family = AF_INET6;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3703
	sa.in6.sin6_port = htons((u_short) _intVal(portNrOrName)) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3704
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3705
	if (__isByteArray(hostOrPathName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3706
	    unsigned char *cp;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3707
	    int n;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3708
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3709
	    cp = __ByteArrayInstPtr(hostOrPathName)->ba_element;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3710
	    n = __byteArraySize(hostOrPathName);
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3711
	    if (n > sizeof(sa.in6.sin6_addr.s6_addr)) n = sizeof(sa.in6.sin6_addr.s6_addr);
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3712
	    bcopy(cp, sa.in6.sin6_addr.s6_addr, n);
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3713
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3714
	    if (! __isString(hostOrPathName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3715
		DBGPRINTF(("SOCKET: invalid hostname arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3716
		RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3717
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3718
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3719
	    /* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3720
	     * do we know the host's address? 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3721
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3722
	    GETHOSTBYNAME(hp, __stringVal(hostOrPathName))
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3723
	    if (hp == NULL) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3724
		DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(hostOrPathName)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3725
		RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3726
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3727
	    bcopy(hp->h_addr, (char *) &sa.in.sin_addr, hp->h_length) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3728
	    sa.in.sin_family = hp->h_addrtype;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3729
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3730
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3731
	DBGPRINTF(("SOCKET: connect addr: %x.%x.%x.%x.%x.%x... port: %d\n", 
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3732
		sa.in6.sin6_addr.s6_addr[0],
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3733
		sa.in6.sin6_addr.s6_addr[1],
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3734
		sa.in6.sin6_addr.s6_addr[2],
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3735
		sa.in6.sin6_addr.s6_addr[3],
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3736
		sa.in6.sin6_addr.s6_addr[4],
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3737
		sa.in6.sin6_addr.s6_addr[5],
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3738
		sa.in6.sin6_port));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3739
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3740
	sockaddr_size = sizeof(struct sockaddr_in6);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3741
	ok = 1;
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3742
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3743
#endif /* AF_INET6 */
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3744
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  3745
#ifdef AF_UNIX
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  3746
    if (myDomain == @symbol(unix)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3747
	char *pathName;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3748
	int l;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3749
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3750
	/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3751
	 * UNIX domain: port is ignored;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3752
	 * hostOrPathName is a pathName
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3753
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3754
	if (! __isString(hostOrPathName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3755
	    DBGPRINTF(("SOCKET: invalid port (pathname) arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3756
	    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3757
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3758
	pathName = (char *) __stringVal(hostOrPathName);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3759
	l = strlen(pathName);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3760
	if ((l + sizeof ( sa.un.sun_family )) > sizeof(struct sockaddr_un)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3761
	    DBGPRINTF(("SOCKET: pathname too long\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3762
	    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3763
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3764
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3765
	strcpy(sa.un.sun_path, pathName);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3766
	sa.un.sun_family = AF_UNIX;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3767
	sockaddr_size = l + sizeof ( sa.un.sun_family );
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3768
	ok = 1;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3769
    }
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3770
#endif /* AF_UNIX */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3771
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3772
#ifdef AF_APPLETALK
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3773
    if (myDomain == @symbol(appletalk)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3774
	/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3775
	 * APPLETALK addressing: port must be a smallInteger;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3776
	 * hostOrPathName the name of the host
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3777
	 * or a byteArray containing the 3 address bytes.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3778
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3779
	if (! __isSmallInteger(portNrOrName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3780
	    DBGPRINTF(("SOCKET: invalid port arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3781
	    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3782
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3783
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3784
	sa.at.sat_family = AF_APPLETALK;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3785
	sa.at.sat_port = __intVal(portNrOrName);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3786
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3787
	if (__isByteArray(hostOrPathName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3788
	    unsigned char *cp;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3789
	    int n;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3790
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3791
	    cp = __ByteArrayInstPtr(hostOrPathName)->ba_element;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3792
	    n = __byteArraySize(hostOrPathName);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3793
	    if (n > 3) n = 3;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3794
	    bcopy(cp, &sa.at.sat_addr, n);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3795
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3796
	    if (! __isString(hostOrPathName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3797
		DBGPRINTF(("SOCKET: invalid hostname arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3798
		RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3799
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3800
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3801
	    /* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3802
	     * do we know the host's address? 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3803
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3804
	    GETHOSTBYNAME(hp, __stringVal(hostOrPathName))
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3805
	    if (hp == NULL) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3806
		DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(hostOrPathName)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3807
		RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3808
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3809
	    if (hp->h_addrtype != AF_APPLETALK) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3810
		DBGPRINTF(("SOCKET: host:%s is not an appletalk host\n", __stringVal(hostOrPathName)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3811
		RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3812
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3813
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3814
	    bcopy(hp->h_addr, (char *) &sa.at.sat_addr, hp->h_length) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3815
	    sa.at.sat_family = hp->h_addrtype;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3816
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3817
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3818
	DBGPRINTF(("SOCKET: connect addr: %x port: %d\n", sa.in.sin_addr, sa.in.sin_port));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3819
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3820
	sockaddr_size = sizeof(struct sockaddr_at);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3821
	ok = 1;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3822
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3823
#endif /* APPLETALK */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3824
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3825
    /*
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3826
     * XXXX add addressing stuff for other domains here ...
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3827
     */
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3828
#ifdef AF_X25
71
claus
parents: 63
diff changeset
  3829
    if (myDomain == @symbol(x25)) {
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3830
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3831
#endif
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3832
#ifdef AF_AX25
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3833
    if (myDomain == @symbol(ax25)) {
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3834
    }
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3835
#endif
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3836
#ifdef AF_NS
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3837
    if ((myDomain == @symbol(ns)) 
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3838
     || (myDomain == @symbol(xns))) {
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3839
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3840
#endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3841
# ifdef AF_DECnet
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3842
    if (myDomain == @symbol(decnet)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3843
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3844
# endif
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  3845
#ifdef AF_SNA
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  3846
    if (myDomain == @symbol(sna)) {
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  3847
    }
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  3848
#endif
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  3849
#ifdef AF_RAW 
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  3850
    if (myDomain == @symbol(raw)) {
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  3851
    }
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  3852
#endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3853
# ifdef AF_ISO
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3854
    if (myDomain == @symbol(iso)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3855
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3856
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3857
# ifdef AF_NETBIOS
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3858
    if (myDomain == @symbol(netbios)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3859
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3860
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3861
# ifdef AF_IPX
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3862
    if (myDomain == @symbol(ipx)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3863
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3864
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3865
# ifdef AF_BRIDGE
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3866
    if (myDomain == @symbol(bridge)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3867
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3868
# endif
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3869
# ifdef AF_BSC
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3870
    if (myDomain == @symbol(bsc)) {
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3871
    }
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3872
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3873
# ifdef AF_ROSE
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3874
    if (myDomain == @symbol(rose)) {
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3875
    }
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3876
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3877
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3878
    if (myDomain == @symbol(ccitt)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3879
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3880
# endif
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3881
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3882
    if (! ok) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3883
	DBGPRINTF(("SOCKET: unsupported domain\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3884
	RETURN (false);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3885
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3886
110
7af19ae8693b use new FILE* wrapper macros (based on externalAddress)
Claus Gittinger <cg@exept.de>
parents: 106
diff changeset
  3887
    sock = fileno(__FILEVal(t));
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3888
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3889
#if defined(O_NONBLOCK)
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3890
    if (blocking != true) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3891
	/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3892
	 * set to non-blocking and wait later
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3893
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3894
	oldFlags = fcntl(sock, F_GETFL, 0);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3895
	/* on SUNOS4.x, would use fcntl(osfd, F_SETFL, flags | FNDELAY); */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3896
	fcntl(sock, F_SETFL, oldFlags | O_NONBLOCK);
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3897
    }
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3898
#endif
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3899
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3900
    /* 
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3901
     * connect 
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3902
     */
81
claus
parents: 79
diff changeset
  3903
    __BEGIN_INTERRUPTABLE__
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3904
    do {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3905
	ret = connect(sock, (struct sockaddr *)&sa, sockaddr_size);
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  3906
    } while ((ret < 0) 
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3907
	     && ((errno == EINTR)
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  3908
#ifdef EAGAIN
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3909
		 || (errno == EAGAIN)
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  3910
#endif
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3911
		));
81
claus
parents: 79
diff changeset
  3912
    __END_INTERRUPTABLE__
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3913
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3914
    if (ret < 0) { 
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3915
#if defined(EINPROGRESS) || defined(EALREADY)
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3916
	if (0
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3917
# ifdef EINPROGRESS
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3918
	    || (errno == EINPROGRESS) 
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3919
# endif
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3920
# ifdef EALREADY
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3921
	    || (errno == EALREADY)
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3922
# endif
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3923
	) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3924
	    /*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3925
	     * We were interrupted. Do not call connect again
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3926
	     * (we will get an EALREADY.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3927
	     * Do a select on write instead.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3928
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3929
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3930
	    isAsync = true;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3931
	} else
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3932
#endif /* EINPROGRESS or EALREADY */
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3933
	{
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3934
	    DBGPRINTF(("SOCKET: connect failed errno=%d\n", errno));
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
  3935
#ifdef DUMP_ADDRESS
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3936
	    {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3937
		char *cp = (char *)(&sa);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3938
		int i;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3939
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3940
		printf("address data:\n");
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3941
		for (i=0; i<sockaddr_size; i++) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3942
		    printf(" %02x\n", *cp++);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3943
		}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3944
	    }
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
  3945
#endif
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3946
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3947
	    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3948
	}
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3949
    }
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3950
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3951
#if defined(O_NONBLOCK)
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3952
    if (blocking != true) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3953
	fcntl(sock, F_SETFL, oldFlags);
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3954
    }
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3955
#endif
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3956
430
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  3957
#else /* NO_SOCKET */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3958
    RETURN (false);
430
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  3959
#endif /* NO_SOCKET */
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  3960
%}.
430
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  3961
    isAsync == true ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3962
	self readWriteWait.
430
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  3963
    ].
71
claus
parents: 63
diff changeset
  3964
    port := portNrOrName.
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  3965
    peerName := hostOrPathName.
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3966
    ^ true
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3967
!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3968
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3969
connectTo:hostOrPathName port:portNrOrName blocking:blocking withTimeout:millis
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3970
    "connect to port, portNrOrName on host, hostName.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3971
     Or path (UNIX socket), where portNrOrName is ignored.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3972
     Return true if ok, false otherwise.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3973
     Hostname must be a string, portNrOrName an integer port number (in inet domain).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3974
     If a non-nil timeout is given, stop trying after that time and return false as well."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3975
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3976
    |stopSignal stopMe connection|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3977
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3978
    millis isNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3979
	^ self connectTo:hostOrPathName port:portNrOrName
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3980
    ].
559
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  3981
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3982
    stopSignal := Signal new.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3983
    stopMe := [stopSignal raise].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3984
    stopSignal handle:[:ex |
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3985
"/        'timeout on connect' infoPrintNL.
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3986
	^ false
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3987
    ] do:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3988
	Processor addTimedBlock:stopMe afterMilliseconds:millis.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3989
	[
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3990
	    connection := self connectTo:hostOrPathName port:portNrOrName blocking:blocking.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3991
	] valueNowOrOnUnwindDo:[
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3992
	    Processor removeTimedBlock:stopMe.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3993
	]
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3994
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3995
    ^ connection
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3996
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3997
    "Created: 31.10.1995 / 18:52:49 / cg"
559
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  3998
    "Modified: 16.8.1997 / 02:11:21 / cg"
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3999
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4000
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4001
connectTo:hostOrPathName port:portNrOrName withTimeout:millis
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4002
    "connect to port, portNrOrName on host, hostName.
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4003
     Or path (UNIX socket), where portNrOrName is ignored.
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4004
     Return true if ok, false otherwise.
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4005
     Hostname must be a string, portNrOrName an integer port number (in inet domain).
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4006
     If a non-nil timeout is given, stop trying after that time and return false as well."
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4007
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4008
    ^ self connectTo:hostOrPathName port:portNrOrName blocking:false withTimeout:millis
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  4009
! !
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  4010
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  4011
!Socket methodsFor:'queries'!
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  4012
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4013
domain
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4014
    "return the sockets addressing domain (i.e. #inet, #unix, #x25, #appletalk)"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4015
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4016
    ^ domain
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4017
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4018
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4019
getName
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4020
    "return the name; here, we return the ports name"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4021
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4022
    ^ port printString
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4023
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4024
102
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  4025
getPeer
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  4026
    "ST-80 compatibility: return an IPSocketAddress instance representing
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  4027
     my hostname/port combination.
155
fcf846c707b7 interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
  4028
     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
  4029
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  4030
    domain == #unix ifTrue:[
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  4031
	^ UDSocketAddress name:peerName
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  4032
    ].
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4033
    domain == #inet ifTrue:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4034
	^ IPSocketAddress hostAddress:(self class ipAddressOfHost:peerName) port:port
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4035
    ].
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4036
    domain == #inet6 ifTrue:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4037
	^ IPv6SocketAddress hostAddress:(self class ipV6AddressOfHost:peerName) port:port
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4038
    ].
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4039
    domain == #appletalk ifTrue:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4040
	^ AppletalkSocketAddress hostAddress:(self class appletalkAddressOfHost:peerName) port:port
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4041
    ].
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4042
    domain == #decnet ifTrue:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4043
	^ DecNetSocketAddress hostAddress:(self class decnetAddressOfHost:peerName) port:port
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4044
    ].
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4045
    self error:'unsupported domain'.
102
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  4046
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  4047
    "Created: 2.11.1995 / 11:22:39 / cg"
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  4048
!
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  4049
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  4050
getPeerName
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  4051
    "return the peer name; thats the hostname (or dotted name) of the
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  4052
     partners host after an accept."
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  4053
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  4054
    ^ peerName
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4055
!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4056
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4057
isActive
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4058
    "return true, if the receiver has a connection"
81
claus
parents: 79
diff changeset
  4059
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4060
    ^ filePointer notNil
81
claus
parents: 79
diff changeset
  4061
!
claus
parents: 79
diff changeset
  4062
71
claus
parents: 63
diff changeset
  4063
port
claus
parents: 63
diff changeset
  4064
    "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
  4065
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  4066
    |p|
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  4067
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  4068
    port == 0 ifTrue:[
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4069
	p := self getPort.
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  4070
	p notNil ifTrue:[
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  4071
	    port := p
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  4072
	]
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  4073
    ].
71
claus
parents: 63
diff changeset
  4074
    ^ port
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4075
!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4076
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4077
type
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4078
    "return the sockets connection type (i.e. #datagram, #stream etc)"
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4079
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4080
    ^ socketType
81
claus
parents: 79
diff changeset
  4081
! !
claus
parents: 79
diff changeset
  4082
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4083
!Socket methodsFor:'socket setup'!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4084
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4085
domain:domainArg type:typeArg
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4086
    "set up socket with domain and type.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4087
     This is a low level entry; no binding, listening or connect
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4088
     is done. Both arguments must be symbols from one of
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4089
     #inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4090
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4091
    ^ self domain:domainArg type:typeArg protocol:0 reuseAddress:true
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4092
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4093
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4094
domain:domainArg type:typeArg protocol:protocolNumber
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4095
    "set up socket with domain, type and protocol number.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4096
     This is a low level entry; no binding, listening or connect
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4097
     is done. Both arguments must be symbols from one of
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4098
     #inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4099
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4100
    ^ self domain:domainArg type:typeArg protocol:protocolNumber reuseAddress:true
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4101
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4102
    "
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4103
     Socket new domain:#inet type:#stream
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4104
     Socket new domain:#unix type:#stream
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4105
    "
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4106
!
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4107
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4108
domain:domainArg type:typeArg protocol:protocolNumber reuseAddress:reuse
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4109
    "set up socket with domain, type and protocol number.
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4110
     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
  4111
     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
  4112
     #inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp.
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4113
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4114
     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
  4115
     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
  4116
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4117
    |errorNr|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4118
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4119
    filePointer notNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4120
	^ self errorAlreadyOpen
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4121
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4122
%{
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4123
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  4124
#ifndef NO_SOCKET
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4125
    FILE *fp;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4126
    int dom, typ, pf, proto = 0, sock;
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4127
    int on = 1;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4128
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4129
    if (! __isSymbol(domainArg)) { 
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4130
	DBGPRINTF(("SOCKET: bad domain\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4131
	RETURN ( nil );
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4132
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4133
    if (! __isSymbol(typeArg)) { 
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4134
	DBGPRINTF(("SOCKET: bad type\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4135
	RETURN ( nil );
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4136
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4137
    if (protocolNumber != nil) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4138
	if (!__isSmallInteger(protocolNumber)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4139
	    DBGPRINTF(("SOCKET: bad protocol\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4140
	    RETURN ( nil );
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4141
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4142
	proto = __intVal(protocolNumber);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4143
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4144
        
81
claus
parents: 79
diff changeset
  4145
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4146
    /*
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4147
     * get address and protocol-family
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4148
     */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4149
#ifdef AF_UNIX
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4150
    if (domainArg == @symbol(unix)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4151
	dom = AF_UNIX;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4152
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4153
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4154
#ifdef AF_INET
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4155
    if (domainArg == @symbol(inet)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4156
	dom = AF_INET;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4157
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4158
#endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4159
#ifdef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4160
    if (domainArg == @symbol(inet6)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4161
	dom = AF_INET6;
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4162
    } else
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4163
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4164
#ifdef AF_DECnet
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4165
    if (domainArg == @symbol(decnet)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4166
	dom = AF_DECnet;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4167
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4168
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4169
#ifdef AF_APPLETALK
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4170
    if (domainArg == @symbol(appletalk)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4171
	dom = AF_APPLETALK;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4172
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4173
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4174
#ifdef AF_X25
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4175
    if (domainArg == @symbol(x25)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4176
	dom = AF_X25;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4177
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4178
#endif
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4179
#ifdef AF_AX25
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4180
    if (domainArg == @symbol(ax25)) {
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4181
	dom = AF_AX25;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4182
    } else
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4183
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4184
#ifdef AF_NS
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  4185
    if ((domainArg == @symbol(xns))
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  4186
     || (domainArg == @symbol(ns))) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4187
	dom = AF_NS;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4188
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4189
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4190
#ifdef AF_SNA
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4191
    if (domainArg == @symbol(sna)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4192
	dom = AF_SNA;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4193
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4194
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4195
#ifdef AF_RAW
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4196
    if (domainArg == @symbol(raw)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4197
	dom = AF_RAW;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4198
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4199
#endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4200
# ifdef AF_ISO
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4201
    if (domainArg == @symbol(iso)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4202
	dom = AF_ISO;
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4203
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4204
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4205
# ifdef AF_NETBIOS
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4206
    if (domainArg == @symbol(netbios)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4207
	dom = AF_NETBIOS;
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4208
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4209
# endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4210
# ifdef AF_IPX
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4211
    if (domainArg == @symbol(ipx)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4212
	dom = AF_IPX;
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4213
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4214
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4215
# ifdef AF_BRIDGE
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4216
    if (domainArg == @symbol(bridge)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4217
	dom = AF_BRIDGE;
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4218
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4219
# endif
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  4220
# ifdef AF_BSC
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  4221
    if (domainArg == @symbol(bsc)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4222
	dom = AF_BSC;
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  4223
    }
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  4224
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  4225
# ifdef AF_ROSE
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  4226
    if (domainArg == @symbol(rose)) {
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  4227
	dom = AF_ROSE;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  4228
    }
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  4229
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4230
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4231
    if (domainArg == @symbol(ccitt)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4232
	dom = AF_CCITT;
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4233
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4234
# endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4235
    {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4236
	DBGPRINTF(("SOCKET: unknown domain <%s>\n", __stringVal(domainArg)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4237
	RETURN ( nil );
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4238
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4239
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4240
#ifdef SOCK_STREAM
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4241
    if (typeArg == @symbol(stream)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4242
	typ = SOCK_STREAM;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4243
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4244
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4245
#ifdef SOCK_DGRAM
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4246
    if (typeArg == @symbol(datagram)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4247
	typ = SOCK_DGRAM;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4248
    } else 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4249
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4250
#ifdef SOCK_RAW
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4251
    if (typeArg == @symbol(raw))
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4252
	typ = SOCK_RAW;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4253
    else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4254
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4255
#ifdef SOCK_SEQPACKET
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4256
    if (typeArg == @symbol(seqPacket))
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4257
	typ = SOCK_SEQPACKET;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4258
    else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4259
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4260
    {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4261
	DBGPRINTF(("SOCKET: bad type <%s>\n", __stringVal(typeArg)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4262
	RETURN ( nil );
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4263
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4264
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4265
    __BEGIN_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4266
    do {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4267
	DBGPRINTF(("SOCKET: opening socket domain=%d type=%d proto=%d\n", dom, typ, proto));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4268
	sock = socket(dom, typ, proto);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4269
#if defined(EPROTONOSUPPORT) /* for SGI */
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4270
	if ((proto != 0) && (sock < 0) && (errno == EPROTONOSUPPORT)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4271
	    DBGPRINTF(("SOCKET: retry with UNSPEC protocol\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4272
	    proto = 0;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4273
	    sock = socket(dom, typ, 0);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4274
	}
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4275
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4276
    } while ((sock < 0) && (errno == EINTR));
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4277
    __END_INTERRUPTABLE__
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
  4278
    DBGFPRINTF((stderr, "socket create newSock=%d\n", sock));
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4279
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4280
    if (sock < 0) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4281
	DBGPRINTF(("SOCKET: socket(dom=%d typ=%d proto=%d) call failed errno=%d\n", dom, typ, proto, errno));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4282
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4283
    } else {
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4284
# ifdef SO_REUSEADDR
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4285
	if (reuse == true) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4286
	    DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4287
	    if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4288
		DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4289
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4290
	}
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4291
# endif /* SO_REUSEADDR */
711
487b2bff9d31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 693
diff changeset
  4292
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4293
	/* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4294
	 * make it a FILE * 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4295
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4296
	fp = fdopen(sock, "r+");
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4297
	if (! fp) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4298
	    DBGPRINTF(("SOCKET: fdopen call failed\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4299
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4300
	    __BEGIN_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4301
	    close(sock);
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
  4302
	    DBGFPRINTF((stderr, "socket close (fdopen failed) (%d)\n", sock));
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4303
	    __END_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4304
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4305
	    __INST(filePointer) = __MKOBJ(fp);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4306
	    __STORESELF(filePointer);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4307
	}
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4308
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  4309
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4310
%}.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4311
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4312
    "all ok?"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4313
    filePointer notNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4314
	domain := domainArg.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4315
	socketType := typeArg.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4316
	Lobby register:self.
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4317
    ] ifFalse:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4318
	^ nil
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4319
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4320
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4321
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4322
     Socket new domain:#inet type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4323
     Socket new domain:#unix type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4324
    "
81
claus
parents: 79
diff changeset
  4325
!
claus
parents: 79
diff changeset
  4326
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4327
for:hostName port:portNr
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4328
    "setup for a TCP socket (i.e. inet domain, stream type) 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4329
     If hostname is nil, a server port is opened,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4330
     otherwise a client port to the server on host.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4331
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4332
     HISTORIC LEFTOVER:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4333
     This method will vanish, as soon as the low level
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4334
     connect/bind works,"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4335
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4336
    self obsoleteMethodWarning.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4337
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4338
    filePointer notNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4339
	^ self errorAlreadyOpen
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4340
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4341
    (portNr isMemberOf:SmallInteger) ifFalse:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4342
	self error:'invalid portNr'
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4343
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4344
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  4345
#ifndef NO_SOCKET
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4346
    struct sockaddr_in sa ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4347
    struct hostent *hp ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4348
    int a, sock ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4349
    long addr;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4350
    FILE *fp;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4351
    int ret;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4352
    int on = 1;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4353
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4354
    bzero((char *) &sa, sizeof(sa)) ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4355
    sa.sin_family = AF_INET;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4356
    sa.sin_addr.s_addr = htonl(INADDR_ANY);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4357
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4358
    if ((hostName != nil) && __isString(hostName)){
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4359
	bzero(&sa, sizeof(sa)) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4360
	if ((addr = inet_addr((char *) __stringVal(hostName))) != -1) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4361
	    /* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4362
	     * is Internet addr in octet notation 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4363
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4364
	    bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)) ; /* set address */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4365
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4366
	    /* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4367
	     * do we know the host's address? 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4368
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4369
	    GETHOSTBYNAME(hp, __stringVal(hostName))
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4370
	    if (hp == NULL) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4371
		DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(hostName)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4372
		RETURN ( nil );
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4373
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4374
	    bcopy(hp->h_addr, (char *) &sa.sin_addr, hp->h_length) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4375
	    sa.sin_family = hp->h_addrtype;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4376
	}
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4377
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4378
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4379
    /*
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4380
     * create the socket
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4381
     */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4382
    __BEGIN_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4383
    do {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4384
	sock = socket(sa.sin_family, SOCK_STREAM, 0);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4385
    } while ((sock < 0) && (errno == EINTR));
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4386
    __END_INTERRUPTABLE__
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
  4387
    DBGFPRINTF((stderr, "socket create newSock=%d\n", sock));
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4388
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4389
    if (sock < 0) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4390
	DBGPRINTF(("SOCKET: socket(dom=%d typ=%d proto=0) call failed errno=%d\n", sa.sin_family, SOCK_STREAM, errno));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4391
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4392
    } else {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4393
	/* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4394
	 * connect/bind 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4395
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4396
	sa.sin_port = htons((u_short) _intVal(portNr)) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4397
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4398
	__BEGIN_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4399
	if (hostName != nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4400
	    do {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4401
		ret = connect(sock, (struct sockaddr *)&sa, sizeof(sa));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4402
	    } while ((ret < 0) && (errno == EINTR));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4403
	} else {
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4404
#ifdef SO_REUSEADDR
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4405
	    /*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4406
	     * should I also do this for DGRAM sockets ?
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4407
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4408
	    if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4409
		DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4410
	    }
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4411
#endif /* SO_REUSEADDR */
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4412
	    sa.sin_addr.s_addr = htonl(INADDR_ANY);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4413
	    do {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4414
		ret = bind(sock, (struct sockaddr *)&sa, sizeof(sa));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4415
	    } while ((ret < 0) && (errno == EINTR));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4416
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4417
	__END_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4418
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4419
	if (ret < 0) { 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4420
	    DBGPRINTF(("SOCKET: bind/connect call failed errno=%d\n", errno));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4421
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4422
	    __BEGIN_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4423
	    close(sock) ;
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
  4424
	    DBGFPRINTF((stderr, "socket close (fdopen failed) (%d)\n", sock));
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4425
	    __END_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4426
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4427
	    /* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4428
	     * make it a FILE * 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4429
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4430
	    fp = fdopen(sock, "r+");
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4431
	    if (! fp) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4432
		DBGPRINTF(("SOCKET: fdopen failed\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4433
		__INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4434
		__BEGIN_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4435
		close(sock);
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  4436
		DBGFPRINTF((stderr, "socket close (fdopen failed) (%d)\n", sock));
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4437
		__END_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4438
	    } else {
444
9ba31a1fba38 always unbuffered on linux
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
  4439
#ifdef BUGGY_STDIO_LIB
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4440
		setbuf(fp, NULL);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4441
		__INST(buffered) = false;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4442
#endif
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4443
		__INST(filePointer) = __MKOBJ(fp);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4444
		__STORESELF(filePointer);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4445
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4446
	}
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4447
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  4448
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4449
%}.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4450
    filePointer isNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4451
	^ nil
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4452
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4453
    mode := #readwrite.
169
ba5dac089c64 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 168
diff changeset
  4454
    Lobby register:self.
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4455
    binary := false.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4456
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4457
    domain := #inet.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4458
    socketType := #stream.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4459
    protocol := portNr.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4460
    peerName := hostName.
81
claus
parents: 79
diff changeset
  4461
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4462
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4463
     Socket new for:'clam' port:(Socket portOfService:'echo')
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4464
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4465
     Socket new for:nil port:9999
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4466
     Socket new for:(OperatingSystem getHostName) port:9999
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4467
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4468
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4469
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4470
for:hostName udpPort:portNr
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4471
    "setup for a UDP socket (i.e. inet domain, datagram type) 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4472
     if hostname is nil, a server port is opened;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4473
     otherwise a client port to the server on host.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4474
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4475
     HISTORIC LEFTOVER:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4476
     This method will vanish, as soon as the low level
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4477
     connect/bind works,"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4478
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4479
    self obsoleteMethodWarning.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4480
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4481
    filePointer notNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4482
	^ self errorAlreadyOpen
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4483
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4484
    (portNr isMemberOf:SmallInteger) ifFalse:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4485
	self error:'invalid portNr'
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4486
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4487
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  4488
#ifndef NO_SOCKET
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4489
    struct sockaddr_in sa ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4490
    struct hostent *hp ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4491
    int a, sock ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4492
    long addr;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4493
    FILE *fp;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4494
    int ret;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4495
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4496
    if (hostName != nil) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4497
	bzero(&sa, sizeof(sa)) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4498
	if ((addr = inet_addr((char *) __stringVal(hostName))) != -1) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4499
	    /* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4500
	     * is Internet addr in octet notation 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4501
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4502
	    bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)) ; /* set address */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4503
	    sa.sin_family = AF_INET ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4504
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4505
	    /* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4506
	     * is hostname - 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4507
	     * do we know the host's address? 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4508
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4509
	    GETHOSTBYNAME(hp, __stringVal(hostName))
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4510
	    if (hp == NULL) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4511
		DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(hostName)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4512
		RETURN ( nil );
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4513
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4514
	    bcopy(hp->h_addr, (char *) &sa.sin_addr, hp->h_length) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4515
	    sa.sin_family = hp->h_addrtype ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4516
	}
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  4517
    } else {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4518
	sa.sin_family = AF_INET;
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  4519
    }
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4520
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4521
    /*
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4522
     * create the socket
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4523
     */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4524
    __BEGIN_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4525
    do {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4526
	sock = socket(sa.sin_family, SOCK_DGRAM, 0);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4527
    } while ((sock < 0) && (errno == EINTR));
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4528
    __END_INTERRUPTABLE__
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
  4529
    DBGFPRINTF((stderr, "socket create newSock=%d\n", sock));
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4530
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4531
    if (sock < 0) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4532
	DBGPRINTF(("SOCKET: socket(dom=%d typ=%d proto=0) call failed errno=%d\n", sa.sin_family, SOCK_DGRAM, errno));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4533
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4534
    } else {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4535
	/* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4536
	 * ok,
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4537
	 * connect/bind 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4538
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4539
	__BEGIN_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4540
	if (hostName == nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4541
	    sa.sin_addr.s_addr = htonl(INADDR_ANY);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4542
	    do {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4543
		ret = bind(sock, (struct sockaddr *)&sa, sizeof(sa));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4544
	    } while ((ret < 0) && (errno == EINTR));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4545
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4546
	    sa.sin_port = htons((u_short) _intVal(portNr)) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4547
	    do {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4548
		ret = connect(sock, (struct sockaddr *)&sa, sizeof(sa));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4549
	    } while ((ret < 0) && (errno == EINTR));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4550
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4551
	__END_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4552
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4553
	if (ret < 0) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4554
	    DBGPRINTF(("SOCKET: bind/connect call failed\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4555
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4556
	    __BEGIN_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4557
	    close(sock) ;
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
  4558
	    DBGFPRINTF((stderr, "socket close (fdopen failed) (%d)\n", sock));
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4559
	    __END_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4560
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4561
	    /* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4562
	     * make it a FILE * 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4563
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4564
	    fp = fdopen(sock, "r+");
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4565
	    if (! fp) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4566
		DBGPRINTF(("SOCKET: fdopen call failed\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4567
		__INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4568
		__BEGIN_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4569
		close(sock);
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
  4570
		DBGFPRINTF((stderr, "socket close (fdopen failed) (%d)\n", sock));
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4571
		__END_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4572
	    } else {
444
9ba31a1fba38 always unbuffered on linux
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
  4573
#ifdef BUGGY_STDIO_LIB
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4574
		setbuf(fp, NULL);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4575
		__INST(buffered) = false;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4576
#endif
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4577
		__INST(filePointer) = __MKOBJ(fp);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4578
		__STORESELF(filePointer);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4579
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4580
	}
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4581
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  4582
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4583
%}.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4584
    filePointer isNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4585
	^ nil
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4586
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4587
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4588
    mode := #readwrite.
169
ba5dac089c64 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 168
diff changeset
  4589
    Lobby register:self.
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4590
    binary := false.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4591
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4592
    domain := #inet.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4593
    socketType := #datagram.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4594
    protocol := portNr.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4595
    peerName := hostName.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4596
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4597
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4598
     Socket new for:'clam' udpPort:(Socket portOfService:'echo')
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4599
    "
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4600
! !
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4601
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4602
!Socket methodsFor:'specials'!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4603
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4604
receiveTimeout:seconds
71
claus
parents: 63
diff changeset
  4605
    "set the receive timeout - for special applications only.
claus
parents: 63
diff changeset
  4606
     Not all operatingSystems offer this functionality
claus
parents: 63
diff changeset
  4607
     (returns false, if unsupported)"
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4608
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4609
    |millis|
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4610
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4611
    filePointer isNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4612
	^ self errorNotOpen
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4613
    ].
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4614
    millis := (seconds * 1000) rounded.
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4615
%{
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4616
#if defined(SO_RCVTIMEO) && defined(SOL_SOCKET) && defined(HZ)
58
bd6753bf0401 *** empty log message ***
claus
parents: 51
diff changeset
  4617
    if (__isSmallInteger(millis)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4618
	OBJ fp = __INST(filePointer);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4619
	int sock;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4620
	int opt;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4621
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4622
	sock = fileno(__FILEVal(fp));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4623
	opt = _intVal(millis) / (1000 / HZ);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4624
	setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&opt, sizeof(int));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4625
	RETURN(true);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4626
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4627
#endif
71
claus
parents: 63
diff changeset
  4628
%}.
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4629
    ^ false
81
claus
parents: 79
diff changeset
  4630
!
claus
parents: 79
diff changeset
  4631
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4632
sendTimeout:seconds
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4633
    "set the send timeout - for special applications only.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4634
     Not all operatingSystems offer this functionality
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4635
     (returns false, if unsupported)"
81
claus
parents: 79
diff changeset
  4636
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4637
    |millis|
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  4638
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4639
    filePointer isNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4640
	^ self errorNotOpen
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4641
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4642
    millis := (seconds * 1000) rounded.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4643
%{
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4644
#if defined(SO_SNDTIMEO) && defined(SOL_SOCKET) && defined(HZ)
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4645
    if (__isSmallInteger(millis)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4646
	OBJ fp = __INST(filePointer);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4647
	int sock;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4648
	int opt;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4649
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4650
	sock = fileno(__FILEVal(fp));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4651
	opt = _intVal(millis) / (1000 / HZ);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4652
	setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (char *)&opt, sizeof(int));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4653
	RETURN(true);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4654
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4655
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4656
%}.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4657
    ^ false
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4658
! !
82
claus
parents: 81
diff changeset
  4659
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  4660
!Socket class methodsFor:'documentation'!
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  4661
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  4662
version
867
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  4663
    ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.140 2000-01-17 11:20:18 cg Exp $'
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  4664
! !