| 131 | */ |
| 132 | |
| 133 | http_t * /* O - HTTP connection or @code NULL@ */ |
| 134 | httpAcceptConnection(int fd, /* I - Listen socket file descriptor */ |
| 135 | int blocking) /* I - 1 if the connection should be |
| 136 | blocking, 0 otherwise */ |
| 137 | { |
| 138 | http_t *http; /* HTTP connection */ |
| 139 | http_addrlist_t addrlist; /* Dummy address list */ |
| 140 | socklen_t addrlen; /* Length of address */ |
| 141 | int val; /* Socket option value */ |
| 142 | |
| 143 | |
| 144 | /* |
| 145 | * Range check input... |
| 146 | */ |
| 147 | |
| 148 | if (fd < 0) |
| 149 | return (NULL); |
| 150 | |
| 151 | /* |
| 152 | * Create the client connection... |
| 153 | */ |
| 154 | |
| 155 | memset(&addrlist, 0, sizeof(addrlist)); |
| 156 | |
| 157 | if ((http = http_create(NULL, 0, &addrlist, AF_UNSPEC, |
| 158 | HTTP_ENCRYPTION_IF_REQUESTED, blocking, |
| 159 | _HTTP_MODE_SERVER)) == NULL) |
| 160 | return (NULL); |
| 161 | |
| 162 | /* |
| 163 | * Accept the client and get the remote address... |
| 164 | */ |
| 165 | |
| 166 | addrlen = sizeof(http_addr_t); |
| 167 | |
| 168 | if ((http->fd = accept(fd, (struct sockaddr *)&(http->addrlist->addr), |
| 169 | &addrlen)) < 0) |
| 170 | { |
| 171 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(errno), 0); |
| 172 | httpClose(http); |
| 173 | |
| 174 | return (NULL); |
| 175 | } |
| 176 | |
| 177 | http->hostaddr = &(http->addrlist->addr); |
| 178 | |
| 179 | if (httpAddrLocalhost(http->hostaddr)) |
| 180 | strlcpy(http->hostname, "localhost", sizeof(http->hostname)); |
| 181 | else |
| 182 | httpAddrString(http->hostaddr, http->hostname, sizeof(http->hostname)); |
| 183 | |
| 184 | #ifdef SO_NOSIGPIPE |
| 185 | /* |
| 186 | * Disable SIGPIPE for this socket. |
| 187 | */ |
| 188 | |
| 189 | val = 1; |
| 190 | setsockopt(http->fd, SOL_SOCKET, SO_NOSIGPIPE, CUPS_SOCAST &val, sizeof(val)); |
no test coverage detected