| [f4a2d624] | 1 | /*
|
|---|
| [4a4cc150] | 2 | * Copyright (c) 2011 Jiri Svoboda
|
|---|
| [f4a2d624] | 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | /** @addtogroup websrv
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /**
|
|---|
| [4a4cc150] | 33 | * @file Skeletal web server.
|
|---|
| [f4a2d624] | 34 | */
|
|---|
| 35 |
|
|---|
| [4a4cc150] | 36 | #include <bool.h>
|
|---|
| 37 | #include <errno.h>
|
|---|
| [d4d74dc] | 38 | #include <assert.h>
|
|---|
| [f4a2d624] | 39 | #include <stdio.h>
|
|---|
| [4a4cc150] | 40 | #include <sys/types.h>
|
|---|
| 41 | #include <sys/stat.h>
|
|---|
| [9c3bba0] | 42 | #include <stdlib.h>
|
|---|
| [4a4cc150] | 43 | #include <fcntl.h>
|
|---|
| [f4a2d624] | 44 |
|
|---|
| 45 | #include <net/in.h>
|
|---|
| 46 | #include <net/inet.h>
|
|---|
| 47 | #include <net/socket.h>
|
|---|
| 48 |
|
|---|
| [0a549cc] | 49 | #include <arg_parse.h>
|
|---|
| 50 | #include <macros.h>
|
|---|
| [f4a2d624] | 51 | #include <str.h>
|
|---|
| [0a549cc] | 52 | #include <str_error.h>
|
|---|
| [f4a2d624] | 53 |
|
|---|
| [0a549cc] | 54 | #define NAME "websrv"
|
|---|
| [f4a2d624] | 55 |
|
|---|
| [0a549cc] | 56 | #define DEFAULT_PORT 8080
|
|---|
| 57 | #define BACKLOG_SIZE 3
|
|---|
| 58 |
|
|---|
| 59 | #define WEB_ROOT "/data/web"
|
|---|
| [4a4cc150] | 60 |
|
|---|
| [f4a2d624] | 61 | /** Buffer for receiving the request. */
|
|---|
| [0a549cc] | 62 | #define BUFFER_SIZE 1024
|
|---|
| 63 |
|
|---|
| 64 | static uint16_t port = DEFAULT_PORT;
|
|---|
| 65 |
|
|---|
| [4a4cc150] | 66 | static char rbuf[BUFFER_SIZE];
|
|---|
| [0a549cc] | 67 | static size_t rbuf_out;
|
|---|
| 68 | static size_t rbuf_in;
|
|---|
| [4a4cc150] | 69 |
|
|---|
| 70 | static char lbuf[BUFFER_SIZE + 1];
|
|---|
| 71 | static size_t lbuf_used;
|
|---|
| 72 |
|
|---|
| 73 | static char fbuf[BUFFER_SIZE];
|
|---|
| [f4a2d624] | 74 |
|
|---|
| [0a549cc] | 75 | /** Responses to send to client. */
|
|---|
| 76 |
|
|---|
| 77 | static const char *msg_ok =
|
|---|
| [f4a2d624] | 78 | "HTTP/1.0 200 OK\r\n"
|
|---|
| [4a4cc150] | 79 | "\r\n";
|
|---|
| 80 |
|
|---|
| [0a549cc] | 81 | static const char *msg_bad_request =
|
|---|
| 82 | "HTTP/1.0 400 Bad Request\r\n"
|
|---|
| 83 | "\r\n"
|
|---|
| 84 | "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n"
|
|---|
| 85 | "<html><head>\r\n"
|
|---|
| 86 | "<title>400 Bad Request</title>\r\n"
|
|---|
| 87 | "</head>\r\n"
|
|---|
| 88 | "<body>\r\n"
|
|---|
| 89 | "<h1>Bad Request</h1>\r\n"
|
|---|
| 90 | "<p>The requested URL has bad syntax.</p>\r\n"
|
|---|
| 91 | "</body>\r\n"
|
|---|
| 92 | "</html>\r\n";
|
|---|
| 93 |
|
|---|
| 94 | static const char *msg_not_found =
|
|---|
| 95 | "HTTP/1.0 404 Not Found\r\n"
|
|---|
| 96 | "\r\n"
|
|---|
| 97 | "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n"
|
|---|
| 98 | "<html><head>\r\n"
|
|---|
| 99 | "<title>404 Not Found</title>\r\n"
|
|---|
| 100 | "</head>\r\n"
|
|---|
| 101 | "<body>\r\n"
|
|---|
| 102 | "<h1>Not Found</h1>\r\n"
|
|---|
| 103 | "<p>The requested URL was not found on this server.</p>\r\n"
|
|---|
| 104 | "</body>\r\n"
|
|---|
| 105 | "</html>\r\n";
|
|---|
| 106 |
|
|---|
| 107 | static const char *msg_not_implemented =
|
|---|
| 108 | "HTTP/1.0 501 Not Implemented\r\n"
|
|---|
| 109 | "\r\n"
|
|---|
| 110 | "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n"
|
|---|
| 111 | "<html><head>\r\n"
|
|---|
| 112 | "<title>501 Not Implemented</title>\r\n"
|
|---|
| 113 | "</head>\r\n"
|
|---|
| 114 | "<body>\r\n"
|
|---|
| 115 | "<h1>Not Implemented</h1>\r\n"
|
|---|
| 116 | "<p>The requested method is not implemented on this server.</p>\r\n"
|
|---|
| 117 | "</body>\r\n"
|
|---|
| 118 | "</html>\r\n";
|
|---|
| 119 |
|
|---|
| [4a4cc150] | 120 | /** Receive one character (with buffering) */
|
|---|
| 121 | static int recv_char(int fd, char *c)
|
|---|
| 122 | {
|
|---|
| 123 | if (rbuf_out == rbuf_in) {
|
|---|
| 124 | rbuf_out = 0;
|
|---|
| 125 | rbuf_in = 0;
|
|---|
| [0a549cc] | 126 |
|
|---|
| 127 | ssize_t rc = recv(fd, rbuf, BUFFER_SIZE, 0);
|
|---|
| [4a4cc150] | 128 | if (rc <= 0) {
|
|---|
| [0a549cc] | 129 | fprintf(stderr, "recv() failed (%zd)\n", rc);
|
|---|
| [4a4cc150] | 130 | return rc;
|
|---|
| 131 | }
|
|---|
| [0a549cc] | 132 |
|
|---|
| [4a4cc150] | 133 | rbuf_in = rc;
|
|---|
| 134 | }
|
|---|
| [0a549cc] | 135 |
|
|---|
| [4a4cc150] | 136 | *c = rbuf[rbuf_out++];
|
|---|
| 137 | return EOK;
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| [0a549cc] | 140 | /** Receive one line with length limit */
|
|---|
| [4a4cc150] | 141 | static int recv_line(int fd)
|
|---|
| 142 | {
|
|---|
| [0a549cc] | 143 | char *bp = lbuf;
|
|---|
| 144 | char c = '\0';
|
|---|
| 145 |
|
|---|
| [4a4cc150] | 146 | while (bp < lbuf + BUFFER_SIZE) {
|
|---|
| [0a549cc] | 147 | char prev = c;
|
|---|
| 148 | int rc = recv_char(fd, &c);
|
|---|
| 149 |
|
|---|
| [4a4cc150] | 150 | if (rc != EOK)
|
|---|
| 151 | return rc;
|
|---|
| [0a549cc] | 152 |
|
|---|
| [4a4cc150] | 153 | *bp++ = c;
|
|---|
| [0a549cc] | 154 | if ((prev == '\r') && (c == '\n'))
|
|---|
| [4a4cc150] | 155 | break;
|
|---|
| 156 | }
|
|---|
| [0a549cc] | 157 |
|
|---|
| [4a4cc150] | 158 | lbuf_used = bp - lbuf;
|
|---|
| 159 | *bp = '\0';
|
|---|
| [0a549cc] | 160 |
|
|---|
| [4a4cc150] | 161 | if (bp == lbuf + BUFFER_SIZE)
|
|---|
| 162 | return ELIMIT;
|
|---|
| [0a549cc] | 163 |
|
|---|
| [4a4cc150] | 164 | return EOK;
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | static bool uri_is_valid(char *uri)
|
|---|
| 168 | {
|
|---|
| 169 | if (uri[0] != '/')
|
|---|
| 170 | return false;
|
|---|
| [0a549cc] | 171 |
|
|---|
| [4a4cc150] | 172 | if (uri[1] == '.')
|
|---|
| 173 | return false;
|
|---|
| [0a549cc] | 174 |
|
|---|
| 175 | char *cp = uri + 1;
|
|---|
| 176 |
|
|---|
| [4a4cc150] | 177 | while (*cp != '\0') {
|
|---|
| [0a549cc] | 178 | char c = *cp++;
|
|---|
| [4a4cc150] | 179 | if (c == '/')
|
|---|
| 180 | return false;
|
|---|
| 181 | }
|
|---|
| [0a549cc] | 182 |
|
|---|
| [4a4cc150] | 183 | return true;
|
|---|
| 184 | }
|
|---|
| 185 |
|
|---|
| 186 | static int send_response(int conn_sd, const char *msg)
|
|---|
| 187 | {
|
|---|
| [0a549cc] | 188 | size_t response_size = str_size(msg);
|
|---|
| 189 |
|
|---|
| 190 | fprintf(stderr, "Sending response\n");
|
|---|
| 191 | ssize_t rc = send(conn_sd, (void *) msg, response_size, 0);
|
|---|
| [4a4cc150] | 192 | if (rc < 0) {
|
|---|
| [0a549cc] | 193 | fprintf(stderr, "send() failed\n");
|
|---|
| [4a4cc150] | 194 | return rc;
|
|---|
| 195 | }
|
|---|
| [0a549cc] | 196 |
|
|---|
| [4a4cc150] | 197 | return EOK;
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | static int uri_get(const char *uri, int conn_sd)
|
|---|
| 201 | {
|
|---|
| 202 | if (str_cmp(uri, "/") == 0)
|
|---|
| [6bb169b5] | 203 | uri = "/index.html";
|
|---|
| [0a549cc] | 204 |
|
|---|
| 205 | char *fname;
|
|---|
| 206 | int rc = asprintf(&fname, "%s%s", WEB_ROOT, uri);
|
|---|
| [4a4cc150] | 207 | if (rc < 0)
|
|---|
| 208 | return ENOMEM;
|
|---|
| [0a549cc] | 209 |
|
|---|
| 210 | int fd = open(fname, O_RDONLY);
|
|---|
| [4a4cc150] | 211 | if (fd < 0) {
|
|---|
| [0a549cc] | 212 | rc = send_response(conn_sd, msg_not_found);
|
|---|
| [9c3bba0] | 213 | free(fname);
|
|---|
| [0a549cc] | 214 | return rc;
|
|---|
| [4a4cc150] | 215 | }
|
|---|
| [0a549cc] | 216 |
|
|---|
| [9c3bba0] | 217 | free(fname);
|
|---|
| [0a549cc] | 218 |
|
|---|
| 219 | rc = send_response(conn_sd, msg_ok);
|
|---|
| [4a4cc150] | 220 | if (rc != EOK)
|
|---|
| 221 | return rc;
|
|---|
| [0a549cc] | 222 |
|
|---|
| [4a4cc150] | 223 | while (true) {
|
|---|
| [0a549cc] | 224 | ssize_t nr = read(fd, fbuf, BUFFER_SIZE);
|
|---|
| [4a4cc150] | 225 | if (nr == 0)
|
|---|
| 226 | break;
|
|---|
| [0a549cc] | 227 |
|
|---|
| [4a4cc150] | 228 | if (nr < 0) {
|
|---|
| 229 | close(fd);
|
|---|
| 230 | return EIO;
|
|---|
| 231 | }
|
|---|
| [0a549cc] | 232 |
|
|---|
| [4a4cc150] | 233 | rc = send(conn_sd, fbuf, nr, 0);
|
|---|
| 234 | if (rc < 0) {
|
|---|
| [0a549cc] | 235 | fprintf(stderr, "send() failed\n");
|
|---|
| [4a4cc150] | 236 | close(fd);
|
|---|
| 237 | return rc;
|
|---|
| 238 | }
|
|---|
| 239 | }
|
|---|
| [0a549cc] | 240 |
|
|---|
| [4a4cc150] | 241 | close(fd);
|
|---|
| [0a549cc] | 242 |
|
|---|
| [4a4cc150] | 243 | return EOK;
|
|---|
| 244 | }
|
|---|
| 245 |
|
|---|
| 246 | static int req_process(int conn_sd)
|
|---|
| 247 | {
|
|---|
| [0a549cc] | 248 | int rc = recv_line(conn_sd);
|
|---|
| [4a4cc150] | 249 | if (rc != EOK) {
|
|---|
| [0a549cc] | 250 | fprintf(stderr, "recv_line() failed\n");
|
|---|
| [4a4cc150] | 251 | return rc;
|
|---|
| 252 | }
|
|---|
| [0a549cc] | 253 |
|
|---|
| 254 | fprintf(stderr, "Request: %s", lbuf);
|
|---|
| 255 |
|
|---|
| [4a4cc150] | 256 | if (str_lcmp(lbuf, "GET ", 4) != 0) {
|
|---|
| [0a549cc] | 257 | rc = send_response(conn_sd, msg_not_implemented);
|
|---|
| 258 | return rc;
|
|---|
| [4a4cc150] | 259 | }
|
|---|
| [0a549cc] | 260 |
|
|---|
| 261 | char *uri = lbuf + 4;
|
|---|
| 262 | char *end_uri = str_chr(uri, ' ');
|
|---|
| [4a4cc150] | 263 | if (end_uri == NULL) {
|
|---|
| 264 | end_uri = lbuf + lbuf_used - 2;
|
|---|
| 265 | assert(*end_uri == '\r');
|
|---|
| 266 | }
|
|---|
| [0a549cc] | 267 |
|
|---|
| [4a4cc150] | 268 | *end_uri = '\0';
|
|---|
| [0a549cc] | 269 | fprintf(stderr, "Requested URI: %s\n", uri);
|
|---|
| 270 |
|
|---|
| [4a4cc150] | 271 | if (!uri_is_valid(uri)) {
|
|---|
| [0a549cc] | 272 | rc = send_response(conn_sd, msg_bad_request);
|
|---|
| 273 | return rc;
|
|---|
| [4a4cc150] | 274 | }
|
|---|
| [0a549cc] | 275 |
|
|---|
| [4a4cc150] | 276 | return uri_get(uri, conn_sd);
|
|---|
| 277 | }
|
|---|
| [f4a2d624] | 278 |
|
|---|
| [0a549cc] | 279 | static void usage(void)
|
|---|
| [f4a2d624] | 280 | {
|
|---|
| [0a549cc] | 281 | printf("Skeletal server\n"
|
|---|
| 282 | "\n"
|
|---|
| 283 | "Usage: " NAME " [options]\n"
|
|---|
| 284 | "\n"
|
|---|
| 285 | "Where options are:\n"
|
|---|
| 286 | "-p port_number | --port=port_number\n"
|
|---|
| 287 | "\tListening port (default " STRING(DEFAULT_PORT) ").\n"
|
|---|
| 288 | "\n"
|
|---|
| 289 | "-h | --help\n"
|
|---|
| 290 | "\tShow this application help.\n");
|
|---|
| 291 | }
|
|---|
| [f4a2d624] | 292 |
|
|---|
| [0a549cc] | 293 | static int parse_option(int argc, char *argv[], int *index)
|
|---|
| 294 | {
|
|---|
| 295 | int value;
|
|---|
| [f4a2d624] | 296 | int rc;
|
|---|
| [0a549cc] | 297 |
|
|---|
| 298 | switch (argv[*index][1]) {
|
|---|
| 299 | case 'h':
|
|---|
| 300 | usage();
|
|---|
| 301 | exit(0);
|
|---|
| 302 | break;
|
|---|
| 303 | case 'p':
|
|---|
| 304 | rc = arg_parse_int(argc, argv, index, &value, 0);
|
|---|
| 305 | if (rc != EOK)
|
|---|
| 306 | return rc;
|
|---|
| 307 |
|
|---|
| 308 | port = (uint16_t) value;
|
|---|
| 309 | break;
|
|---|
| 310 | /* Long options with double dash */
|
|---|
| 311 | case '-':
|
|---|
| 312 | if (str_lcmp(argv[*index] + 2, "help", 5) == 0) {
|
|---|
| 313 | usage();
|
|---|
| 314 | exit(0);
|
|---|
| 315 | } else if (str_lcmp(argv[*index] + 2, "port=", 5) == 0) {
|
|---|
| 316 | rc = arg_parse_int(argc, argv, index, &value, 7);
|
|---|
| 317 | if (rc != EOK)
|
|---|
| 318 | return rc;
|
|---|
| 319 |
|
|---|
| 320 | port = (uint16_t) value;
|
|---|
| 321 | } else {
|
|---|
| 322 | usage();
|
|---|
| 323 | return EINVAL;
|
|---|
| 324 | }
|
|---|
| 325 | break;
|
|---|
| 326 | default:
|
|---|
| 327 | usage();
|
|---|
| 328 | return EINVAL;
|
|---|
| 329 | }
|
|---|
| 330 |
|
|---|
| 331 | return EOK;
|
|---|
| 332 | }
|
|---|
| [f4a2d624] | 333 |
|
|---|
| [0a549cc] | 334 | int main(int argc, char *argv[])
|
|---|
| 335 | {
|
|---|
| 336 | /* Parse command line arguments */
|
|---|
| 337 | for (int i = 1; i < argc; i++) {
|
|---|
| 338 | if (argv[i][0] == '-') {
|
|---|
| 339 | int rc = parse_option(argc, argv, &i);
|
|---|
| 340 | if (rc != EOK)
|
|---|
| 341 | return rc;
|
|---|
| 342 | } else {
|
|---|
| 343 | usage();
|
|---|
| 344 | return EINVAL;
|
|---|
| 345 | }
|
|---|
| 346 | }
|
|---|
| 347 |
|
|---|
| 348 | struct sockaddr_in addr;
|
|---|
| 349 |
|
|---|
| [f4a2d624] | 350 | addr.sin_family = AF_INET;
|
|---|
| [0a549cc] | 351 | addr.sin_port = htons(port);
|
|---|
| 352 |
|
|---|
| 353 | int rc = inet_pton(AF_INET, "127.0.0.1", (void *)
|
|---|
| 354 | &addr.sin_addr.s_addr);
|
|---|
| [f4a2d624] | 355 | if (rc != EOK) {
|
|---|
| [0a549cc] | 356 | fprintf(stderr, "Error parsing network address (%s)\n",
|
|---|
| 357 | str_error(rc));
|
|---|
| [f4a2d624] | 358 | return 1;
|
|---|
| 359 | }
|
|---|
| [0a549cc] | 360 |
|
|---|
| 361 | fprintf(stderr, "Creating socket\n");
|
|---|
| 362 |
|
|---|
| 363 | int listen_sd = socket(PF_INET, SOCK_STREAM, 0);
|
|---|
| [f4a2d624] | 364 | if (listen_sd < 0) {
|
|---|
| [0a549cc] | 365 | fprintf(stderr, "Error creating listening socket (%s)\n",
|
|---|
| 366 | str_error(listen_sd));
|
|---|
| 367 | return 2;
|
|---|
| [f4a2d624] | 368 | }
|
|---|
| [0a549cc] | 369 |
|
|---|
| [f4a2d624] | 370 | rc = bind(listen_sd, (struct sockaddr *) &addr, sizeof(addr));
|
|---|
| 371 | if (rc != EOK) {
|
|---|
| [0a549cc] | 372 | fprintf(stderr, "Error binding socket (%s)\n",
|
|---|
| 373 | str_error(rc));
|
|---|
| 374 | return 3;
|
|---|
| [f4a2d624] | 375 | }
|
|---|
| [0a549cc] | 376 |
|
|---|
| [ae481e0] | 377 | rc = listen(listen_sd, BACKLOG_SIZE);
|
|---|
| [f4a2d624] | 378 | if (rc != EOK) {
|
|---|
| [0a549cc] | 379 | fprintf(stderr, "listen() failed (%s)\n", str_error(rc));
|
|---|
| 380 | return 4;
|
|---|
| [f4a2d624] | 381 | }
|
|---|
| [0a549cc] | 382 |
|
|---|
| 383 | fprintf(stderr, "Listening for connections at port %" PRIu16 "\n",
|
|---|
| 384 | port);
|
|---|
| [f4a2d624] | 385 | while (true) {
|
|---|
| [0a549cc] | 386 | struct sockaddr_in raddr;
|
|---|
| 387 | socklen_t raddr_len = sizeof(raddr);
|
|---|
| 388 | int conn_sd = accept(listen_sd, (struct sockaddr *) &raddr,
|
|---|
| [f4a2d624] | 389 | &raddr_len);
|
|---|
| [0a549cc] | 390 |
|
|---|
| [f4a2d624] | 391 | if (conn_sd < 0) {
|
|---|
| [0a549cc] | 392 | fprintf(stderr, "accept() failed (%s)\n", str_error(rc));
|
|---|
| [4a4cc150] | 393 | continue;
|
|---|
| [f4a2d624] | 394 | }
|
|---|
| [0a549cc] | 395 |
|
|---|
| 396 | fprintf(stderr, "Connection accepted (sd=%d), "
|
|---|
| 397 | "waiting for request\n", conn_sd);
|
|---|
| 398 |
|
|---|
| 399 | rbuf_out = 0;
|
|---|
| 400 | rbuf_in = 0;
|
|---|
| 401 |
|
|---|
| [4a4cc150] | 402 | rc = req_process(conn_sd);
|
|---|
| [0a549cc] | 403 | if (rc != EOK)
|
|---|
| 404 | fprintf(stderr, "Error processing request (%s)\n",
|
|---|
| 405 | str_error(rc));
|
|---|
| 406 |
|
|---|
| [f4a2d624] | 407 | rc = closesocket(conn_sd);
|
|---|
| 408 | if (rc != EOK) {
|
|---|
| [0a549cc] | 409 | fprintf(stderr, "Error closing connection socket (%s)\n",
|
|---|
| 410 | str_error(rc));
|
|---|
| [415578ef] | 411 | closesocket(listen_sd);
|
|---|
| [0a549cc] | 412 | return 5;
|
|---|
| [f4a2d624] | 413 | }
|
|---|
| [0a549cc] | 414 |
|
|---|
| 415 | fprintf(stderr, "Connection closed\n");
|
|---|
| [f4a2d624] | 416 | }
|
|---|
| [0a549cc] | 417 |
|
|---|
| 418 | /* Not reached */
|
|---|
| [f4a2d624] | 419 | return 0;
|
|---|
| 420 | }
|
|---|
| 421 |
|
|---|
| 422 | /** @}
|
|---|
| 423 | */
|
|---|