syslog-ng source
socket-options.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2014 Balabit
3  * Copyright (c) 1998-2013 Balázs Scheidler
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 as published
7  * by the Free Software Foundation, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * As an additional exemption you are allowed to compile & link against the
19  * OpenSSL libraries as published by the OpenSSL project. See the file
20  * COPYING for details.
21  *
22  */
23 #ifndef SOCKET_OPTIONS_H_INCLUDED
24 #define SOCKET_OPTIONS_H_INCLUDED
25 
26 #include "gsockaddr.h"
27 
28 typedef enum
29 {
33 
34 typedef struct _SocketOptions SocketOptions;
35 
37 {
38  /* socket options */
39  gint so_sndbuf;
40  gint so_rcvbuf;
43  gboolean so_reuseport;
44  gboolean (*setup_socket)(SocketOptions *s, gint sock, GSockAddr *bind_addr, AFSocketDirection dir);
45  gboolean (*setup_peer_socket)(SocketOptions *s, gint sock, GSockAddr *peer_addr);
46  void (*free)(gpointer s);
47 };
48 
49 gboolean socket_options_setup_socket_method(SocketOptions *self, gint fd, GSockAddr *bind_addr, AFSocketDirection dir);
50 gboolean socket_options_setup_peer_socket_method(SocketOptions *self, gint fd, GSockAddr *bind_addr);
51 void socket_options_init_instance(SocketOptions *self);
52 SocketOptions *socket_options_new(void);
53 
54 static inline gboolean
55 socket_options_setup_socket(SocketOptions *s, gint sock, GSockAddr *bind_addr, AFSocketDirection dir)
56 {
57  return s->setup_socket(s, sock, bind_addr, dir);
58 }
59 
60 static inline gboolean
61 socket_options_setup_peer_socket(SocketOptions *s, gint sock, GSockAddr *peer_addr)
62 {
63  return s->setup_peer_socket(s, sock, peer_addr);
64 }
65 
66 static inline void
67 socket_options_free(SocketOptions *s)
68 {
69  s->free(s);
70 }
71 
72 #endif
AFSocketDirection
Definition: socket-options.h:29
@ AFSOCKET_DIR_SEND
Definition: socket-options.h:31
@ AFSOCKET_DIR_RECV
Definition: socket-options.h:30
gboolean socket_options_setup_peer_socket_method(SocketOptions *self, gint fd, GSockAddr *bind_addr)
Definition: socket-options.c:138
SocketOptions * socket_options_new(void)
Definition: socket-options.c:154
void socket_options_init_instance(SocketOptions *self)
Definition: socket-options.c:146
gboolean socket_options_setup_socket_method(SocketOptions *self, gint fd, GSockAddr *bind_addr, AFSocketDirection dir)
Definition: socket-options.c:114
Definition: gsockaddr.h:46
Definition: socket-options.h:37
void(* free)(gpointer s)
Definition: socket-options.h:46
gboolean so_reuseport
Definition: socket-options.h:43
gboolean(* setup_socket)(SocketOptions *s, gint sock, GSockAddr *bind_addr, AFSocketDirection dir)
Definition: socket-options.h:44
gint so_rcvbuf
Definition: socket-options.h:40
gint so_broadcast
Definition: socket-options.h:41
gint so_sndbuf
Definition: socket-options.h:39
gint so_keepalive
Definition: socket-options.h:42
gboolean(* setup_peer_socket)(SocketOptions *s, gint sock, GSockAddr *peer_addr)
Definition: socket-options.h:45
int sock
Definition: test_thread_wakeup.c:93