Deferred instantiation of socket implmentations until registration.
[strongswan.git] / src / libcharon / network / socket.h
1 /*
2 * Copyright (C) 2006-2010 Tobias Brunner
3 * Copyright (C) 2005-2010 Martin Willi
4 * Copyright (C) 2006 Daniel Roethlisberger
5 * Copyright (C) 2005 Jan Hutter
6 * Hochschule fuer Technik Rapperswil
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * for more details.
17 */
18
19 /**
20 * @defgroup socket socket
21 * @{ @ingroup network
22 */
23
24 #ifndef SOCKET_H_
25 #define SOCKET_H_
26
27 typedef struct socket_t socket_t;
28
29 #include <library.h>
30 #include <network/packet.h>
31 #include <utils/enumerator.h>
32
33 /**
34 * Constructor prototype for sockets.
35 */
36 typedef socket_t *(*socket_constructor_t)();
37
38 /**
39 * Socket interface definition.
40 */
41 struct socket_t {
42
43 /**
44 * Receive a packet.
45 *
46 * Reads a packet from the socket and sets source/dest
47 * appropriately.
48 *
49 * @param packet pinter gets address from allocated packet_t
50 * @return
51 * - SUCCESS when packet successfully received
52 * - FAILED when unable to receive
53 */
54 status_t (*receive) (socket_t *this, packet_t **packet);
55
56 /**
57 * Send a packet.
58 *
59 * Sends a packet to the net using source and destination addresses of
60 * the packet.
61 *
62 * @param packet packet_t to send
63 * @return
64 * - SUCCESS when packet successfully sent
65 * - FAILED when unable to send
66 */
67 status_t (*send) (socket_t *this, packet_t *packet);
68
69 /**
70 * Destroy a socket implementation.
71 */
72 void (*destroy) (socket_t *this);
73 };
74
75 #endif /** SOCKET_H_ @}*/