1 /* 2 * This file is part of the Nice GLib ICE library. 3 * 4 * (C) 2008-2009 Collabora Ltd. 5 * Contact: Youness Alaoui 6 * (C) 2008-2009 Nokia Corporation. All rights reserved. 7 * 8 * The contents of this file are subject to the Mozilla Public License Version 9 * 1.1 (the "License"); you may not use this file except in compliance with 10 * the License. You may obtain a copy of the License at 11 * http://www.mozilla.org/MPL/ 12 * 13 * Software distributed under the License is distributed on an "AS IS" basis, 14 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 15 * for the specific language governing rights and limitations under the 16 * License. 17 * 18 * The Original Code is the Nice GLib ICE library. 19 * 20 * The Initial Developers of the Original Code are Collabora Ltd and Nokia 21 * Corporation. All Rights Reserved. 22 * 23 * Contributors: 24 * Youness Alaoui, Collabora Ltd. 25 * 26 * Alternatively, the contents of this file may be used under the terms of the 27 * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which 28 * case the provisions of LGPL are applicable instead of those above. If you 29 * wish to allow use of your version of this file only under the terms of the 30 * LGPL and not to allow others to use your version of this file under the 31 * MPL, indicate your decision by deleting the provisions above and replace 32 * them with the notice and other provisions required by the LGPL. If you do 33 * not delete the provisions above, a recipient may use your version of this 34 * file under either the MPL or the LGPL. 35 */ 36 37 #ifndef _SOCKET_H 38 #define _SOCKET_H 39 40 #include "agent.h" 41 #include "address.h" 42 #include <gio/gio.h> 43 44 #ifdef G_OS_WIN32 45 #include <winsock2.h> 46 #include <ws2tcpip.h> 47 #else 48 #include <sys/types.h> 49 #include <sys/socket.h> 50 #include <netinet/in.h> 51 #include <arpa/inet.h> 52 #endif 53 54 G_BEGIN_DECLS 55 56 typedef struct _NiceSocket NiceSocket; 57 58 typedef enum { 59 NICE_SOCKET_TYPE_UDP_BSD, 60 NICE_SOCKET_TYPE_TCP_BSD, 61 NICE_SOCKET_TYPE_PSEUDOSSL, 62 NICE_SOCKET_TYPE_HTTP, 63 NICE_SOCKET_TYPE_SOCKS5, 64 NICE_SOCKET_TYPE_UDP_TURN, 65 NICE_SOCKET_TYPE_UDP_TURN_OVER_TCP, 66 NICE_SOCKET_TYPE_TCP_ACTIVE, 67 NICE_SOCKET_TYPE_TCP_PASSIVE, 68 NICE_SOCKET_TYPE_TCP_SO 69 } NiceSocketType; 70 71 typedef void (*NiceSocketWritableCb) (NiceSocket *sock, gpointer user_data); 72 73 struct _NiceSocket 74 { 75 NiceAddress addr; 76 NiceSocketType type; 77 GSocket *fileno; 78 /* Implementations must handle any value of n_recv_messages, including 0. Iff 79 * n_recv_messages is 0, recv_messages may be NULL. */ 80 gint (*recv_messages) (NiceSocket *sock, 81 NiceInputMessage *recv_messages, guint n_recv_messages); 82 /* As above, @n_messages may be zero. Iff so, @messages may be %NULL. */ 83 gint (*send_messages) (NiceSocket *sock, const NiceAddress *to, 84 const NiceOutputMessage *messages, guint n_messages); 85 gint (*send_messages_reliable) (NiceSocket *sock, const NiceAddress *to, 86 const NiceOutputMessage *messages, guint n_messages); 87 gboolean (*is_reliable) (NiceSocket *sock); 88 gboolean (*can_send) (NiceSocket *sock, NiceAddress *addr); 89 void (*set_writable_callback) (NiceSocket *sock, 90 NiceSocketWritableCb callback, gpointer user_data); 91 gboolean (*is_based_on) (NiceSocket *sock, NiceSocket *other); 92 void (*close) (NiceSocket *sock); 93 void *priv; 94 }; 95 96 97 G_GNUC_WARN_UNUSED_RESULT 98 gint 99 nice_socket_recv_messages (NiceSocket *sock, 100 NiceInputMessage *recv_messages, guint n_recv_messages); 101 102 gint 103 nice_socket_send_messages (NiceSocket *sock, const NiceAddress *addr, 104 const NiceOutputMessage *messages, guint n_messages); 105 gint 106 nice_socket_send_messages_reliable (NiceSocket *sock, const NiceAddress *addr, 107 const NiceOutputMessage *messages, guint n_messages); 108 gssize 109 nice_socket_recv (NiceSocket *sock, NiceAddress *from, gsize len, 110 gchar *buf); 111 gssize 112 nice_socket_send (NiceSocket *sock, const NiceAddress *to, gsize len, 113 const gchar *buf); 114 gssize 115 nice_socket_send_reliable (NiceSocket *sock, const NiceAddress *addr, gsize len, 116 const gchar *buf); 117 118 gboolean 119 nice_socket_is_reliable (NiceSocket *sock); 120 121 gboolean 122 nice_socket_can_send (NiceSocket *sock, NiceAddress *addr); 123 124 void 125 nice_socket_set_writable_callback (NiceSocket *sock, 126 NiceSocketWritableCb callback, gpointer user_data); 127 128 /** 129 * nice_socket_is_based_on: 130 * @sock: a #NiceSocket 131 * @other: another #NiceSocket 132 * 133 * Checks whether @sock wraps @other as a source and destination of its read and 134 * write operations. The function traverses the whole chain of @sock's base 135 * sockets until @other is found or the end is reached. 136 * 137 * Returns: %TRUE if @sock is based on @other or if @sock and @other are 138 * the same socket, %FALSE otherwise. 139 * 140 * Since: 0.1.14 141 */ 142 gboolean 143 nice_socket_is_based_on (NiceSocket *sock, NiceSocket *other); 144 145 void 146 nice_socket_free (NiceSocket *sock); 147 148 #include "udp-bsd.h" 149 #include "tcp-bsd.h" 150 #include "tcp-active.h" 151 #include "tcp-passive.h" 152 #include "pseudossl.h" 153 #include "socks5.h" 154 #include "http.h" 155 #include "udp-turn.h" 156 #include "udp-turn-over-tcp.h" 157 158 G_END_DECLS 159 160 #endif /* _SOCKET_H */ 161 162