3 % (c) The GRASP/AQUA Project, Glasgow University, 1995
5 \subsection[connectSocket.lc]{Assign name to client socket}
10 #define NON_POSIX_SOURCE
12 #include "ghcSockets.h"
16 connectSocket(I_ sockfd, A_ servaddr, I_ addrlen, I_ isUnixDomain)
20 while ((rc = connect((int)sockfd, (struct sockaddr *)servaddr, (int)addrlen)) < 0) {
21 if (errno == EINPROGRESS) {
23 return FILEOBJ_BLOCKED_WRITE;
25 } else if (errno != EINTR) {
32 ghc_errtype = ERR_PERMISSIONDENIED;
33 if (isUnixDomain != 0)
34 ghc_errstr = "For a component of path prefix of path name";
36 ghc_errstr = "Requested address protected, cannot bind socket";
40 ghc_errtype = ERR_RESOURCEBUSY;
41 ghc_errstr = "Address already in use";
43 case GHC_EADDRNOTAVAIL:
44 ghc_errtype = ERR_PERMISSIONDENIED;
45 ghc_errstr = "Address not available from local machine";
47 case GHC_EAFNOSUPPORT:
48 ghc_errtype = ERR_INVALIDARGUMENT;
49 ghc_errstr = "Address cannot be used with socket";
52 ghc_errtype = ERR_RESOURCEBUSY;
53 ghc_errstr = "Non-blocking socket, previous connection attempt not completed";
56 ghc_errtype = ERR_INVALIDARGUMENT;
57 ghc_errstr = "Not a valid socket file descriptor";
59 case GHC_ECONNREFUSED:
60 ghc_errtype = ERR_PERMISSIONDENIED;
61 ghc_errstr = "Connection rejected";
64 ghc_errtype = ERR_INVALIDARGUMENT;
65 ghc_errstr = "Address not in valid part of process address space";
68 ghc_errtype = ERR_SYSTEMERROR;
69 ghc_errstr = "Specified size of structure not equal valid address for family";
72 ghc_errtype = ERR_PERMISSIONDENIED;
73 ghc_errstr = "Network not reachable from host";
76 ghc_errtype = ERR_INAPPROPRIATETYPE;
77 ghc_errstr = "Descriptor for file, not a socket";
80 ghc_errtype = ERR_TIMEEXPIRED;
81 ghc_errstr = "Connection attempt timed out";
84 ghc_errtype = ERR_SYSTEMERROR;
85 ghc_errstr = "Could not make directory entry or alloc inode";
88 ghc_errtype = ERR_INVALIDARGUMENT;
89 ghc_errstr = "A null path name was given";
92 ghc_errtype = ERR_SYSTEMERROR;
93 ghc_errstr = "Too many symbolic links encountered";
95 case GHC_ENAMETOOLONG:
96 ghc_errtype = ERR_INVALIDARGUMENT;
97 ghc_errstr = "Max length of path name exceeded";
100 ghc_errtype = ERR_INVALIDARGUMENT;
101 ghc_errstr = "Component in path prefix does not exist";
104 ghc_errtype = ERR_INVALIDARGUMENT;
105 ghc_errstr = "Component in path prefix is not a directory";
108 ghc_errtype = ERR_INVALIDARGUMENT;
109 ghc_errstr = "File referred to is a socket of differing type";