VLC 4.0.0-dev
vlc_dtls.h
Go to the documentation of this file.
1/*****************************************************************************
2 * datagram.h:
3 *****************************************************************************
4 * Copyright (C) 2020 RĂ©mi Denis-Courmont
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
20
21#ifndef VLC_DATAGRAM_SOCKET_H
22# define VLC_DATAGRAM_SOCKET_H
23
24struct iovec;
25
26/**
27 * Datagram socket
28 */
29struct vlc_dtls {
30 const struct vlc_dtls_operations *ops;
31};
32
34 void (*close)(struct vlc_dtls *);
35
36 int (*get_fd)(struct vlc_dtls *, short *events);
37 ssize_t (*readv)(struct vlc_dtls *, struct iovec *iov, unsigned len,
38 bool *restrict truncated);
39 ssize_t (*writev)(struct vlc_dtls *, const struct iovec *iov, unsigned len);
40};
41
42static inline void vlc_dtls_Close(struct vlc_dtls *dgs)
43{
44 dgs->ops->close(dgs);
45}
46
47static inline int vlc_dtls_GetPollFD(struct vlc_dtls *dgs, short *restrict ev)
48{
49 return dgs->ops->get_fd(dgs, ev);
50}
51
52static inline ssize_t vlc_dtls_Recv(struct vlc_dtls *dgs, void *buf, size_t len,
53 bool *restrict truncated)
54{
55 struct iovec iov = { .iov_base = buf, .iov_len = len };
56
57 return dgs->ops->readv(dgs, &iov, 1, truncated);
58}
59
60static inline ssize_t vlc_dtls_Send(struct vlc_dtls *dgs, const void *buf,
61 size_t len)
62{
63 struct iovec iov = { .iov_base = (void *)buf, .iov_len = len };
64
65 return dgs->ops->writev(dgs, &iov, 1);
66}
67
68struct vlc_dtls *vlc_datagram_CreateFD(int fd);
69struct vlc_dtls *vlc_dccp_CreateFD(int fd);
70
71#endif
Definition: vlc_dtls.h:33
void(* close)(struct vlc_dtls *)
Definition: vlc_dtls.h:34
int(* get_fd)(struct vlc_dtls *, short *events)
Definition: vlc_dtls.h:36
ssize_t(* writev)(struct vlc_dtls *, const struct iovec *iov, unsigned len)
Definition: vlc_dtls.h:39
ssize_t(* readv)(struct vlc_dtls *, struct iovec *iov, unsigned len, bool *restrict truncated)
Definition: vlc_dtls.h:37
Datagram socket.
Definition: vlc_dtls.h:29
const struct vlc_dtls_operations * ops
Definition: vlc_dtls.h:30
struct vlc_dtls * vlc_datagram_CreateFD(int fd)
Definition: datagram.c:99
static int vlc_dtls_GetPollFD(struct vlc_dtls *dgs, short *restrict ev)
Definition: vlc_dtls.h:47
static ssize_t vlc_dtls_Send(struct vlc_dtls *dgs, const void *buf, size_t len)
Definition: vlc_dtls.h:60
static void vlc_dtls_Close(struct vlc_dtls *dgs)
Definition: vlc_dtls.h:42
struct vlc_dtls * vlc_dccp_CreateFD(int fd)
Definition: datagram.c:150
static ssize_t vlc_dtls_Recv(struct vlc_dtls *dgs, void *buf, size_t len, bool *restrict truncated)
Definition: vlc_dtls.h:52