blob: 374e97bf68257d02966e73b9bd2e4fe2959ad41e [file] [log] [blame]
Frédéric Lécaille70da8892020-11-06 15:49:49 +01001/*
2 * QUIC socket management.
3 *
4 * Copyright 2020 HAProxy Technologies, Frédéric Lécaille <flecaille@haproxy.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 */
12
13#include <errno.h>
14
15#include <sys/socket.h>
16#include <sys/types.h>
17
18#include <haproxy/connection.h>
19#include <haproxy/listener.h>
20
21/* Tests if the receiver supports accepting connections. Returns positive on
22 * success, 0 if not possible
23 */
24int quic_sock_accepting_conn(const struct receiver *rx)
25{
26 return 1;
27}
28
29/* Accept an incoming connection from listener <l>, and return it, as well as
30 * a CO_AC_* status code into <status> if not null. Null is returned on error.
31 * <l> must be a valid listener with a valid frontend.
32 */
33struct connection *quic_sock_accept_conn(struct listener *l, int *status)
34{
35 /* TO DO */
36 return NULL;
37}
38
39/* Function called on a read event from a listening socket. It tries
40 * to handle as many connections as possible.
41 */
42void quic_sock_fd_iocb(int fd)
43{
44 ssize_t ret;
45 struct buffer *buf;
46 struct listener *l = objt_listener(fdtab[fd].owner);
47 /* Source address */
48 struct sockaddr_storage saddr = {0};
49 socklen_t saddrlen;
50
51 if (!l)
52 ABORT_NOW();
53
54 if (!(fdtab[fd].ev & FD_POLL_IN) || !fd_recv_ready(fd))
55 return;
56
57 buf = get_trash_chunk();
58 saddrlen = sizeof saddr;
59 do {
60 ret = recvfrom(fd, buf->area, buf->size, 0,
61 (struct sockaddr *)&saddr, &saddrlen);
62 if (ret < 0) {
63 if (errno == EINTR)
64 continue;
65 if (errno == EAGAIN)
66 fd_cant_recv(fd);
67 return;
68 }
69 } while (0);
70
71 buf->data = ret;
72}