[asterisk-commits] file: branch file/netsock2 r97536 - in /team/file/netsock2: include/asterisk/...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jan 9 12:29:39 CST 2008


Author: file
Date: Wed Jan  9 12:29:38 2008
New Revision: 97536

URL: http://svn.digium.com/view/asterisk?view=rev&rev=97536
Log:
Add in a periodic callback.

Modified:
    team/file/netsock2/include/asterisk/netsock2.h
    team/file/netsock2/main/netsock2.c

Modified: team/file/netsock2/include/asterisk/netsock2.h
URL: http://svn.digium.com/view/asterisk/team/file/netsock2/include/asterisk/netsock2.h?view=diff&rev=97536&r1=97535&r2=97536
==============================================================================
--- team/file/netsock2/include/asterisk/netsock2.h (original)
+++ team/file/netsock2/include/asterisk/netsock2.h Wed Jan  9 12:29:38 2008
@@ -73,7 +73,7 @@
  * \param read Function to be called when there is data to be read
  * \return Returns 0 on success, -1 on failure
  */
-#define ast_netsock2_bind_sctp(binder, socket_list, address, port, tos, cos, read) ast_netsock2_bind(binder, socket_list, AST_NETSOCK2_TRANSPORT_SCTP, address, port, tos, cos, NULL, read, NULL, NULL, NULL)
+#define ast_netsock2_bind_sctp(binder, socket_list, address, port, tos, cos, read) ast_netsock2_bind(binder, socket_list, AST_NETSOCK2_TRANSPORT_SCTP, address, port, tos, cos, NULL, read, NULL, NULL, NULL, NULL)
 
 /*! \brief Bind to an address and port using UDP
  * \param binder What is binding to this address/port
@@ -85,7 +85,7 @@
  * \param read Function to be called when there is data to be read
  * \return Returns 0 on success, -1 on failure
  */
-#define ast_netsock2_bind_udp(binder, socket_list, address, port, tos, cos, read) ast_netsock2_bind(binder, socket_list, AST_NETSOCK2_TRANSPORT_UDP, address, port, tos, cos, NULL, read, NULL, NULL, NULL)
+#define ast_netsock2_bind_udp(binder, socket_list, address, port, tos, cos, read) ast_netsock2_bind(binder, socket_list, AST_NETSOCK2_TRANSPORT_UDP, address, port, tos, cos, NULL, read, NULL, NULL, NULL, NULL)
 
 /*! \brief Bind to an address and port using TCP
  * \param binder What is binding to this address/port
@@ -97,9 +97,10 @@
  * \param connect Function to be called upon acception of a connection
  * \param read Function to be called when there is data to be read
  * \param disconnect Function to be called upon disconnection
- * \return Returns 0 on success, -1 on failure
- */
-#define ast_netsock2_bind_tcp(binder, socket_list, address, port, tos, cos, connect, read, disconnect) ast_netsock2_bind(binder, socket_list, AST_NETSOCK2_TRANSPORT_TCP, address, port, tos, cos, connect, read, disconnect, NULL, NULL)
+ * \param periodic Function to be called periodically
+ * \return Returns 0 on success, -1 on failure
+ */
+#define ast_netsock2_bind_tcp(binder, socket_list, address, port, tos, cos, connect, read, disconnect, periodic) ast_netsock2_bind(binder, socket_list, AST_NETSOCK2_TRANSPORT_TCP, address, port, tos, cos, connect, read, disconnect, periodic, NULL, NULL)
 
 /*! \brief Bind to an address and port using TCP with TLS support
  * \param binder What is binding to this address/port
@@ -111,11 +112,12 @@
  * \param connect Function to be called upon acception of a connection
  * \param read Function to be called when there is data to be read
  * \param disconnect Function to be called upon disconnection
+ * \param periodic Function to be called periodically
  * \param certificate SSL Certificate to use
  * \param cipher SSL Cipher to use
  * \return Returns 0 on success, -1 on failure
  */
-#define ast_netsock2_bind_tls(binder, socket_list, address, port, tos, cos, connect, read, disconnect, certificate, cipher) ast_netsock2_bind(binder, socket_list, AST_NETSOCK2_TRANSPORT_TLS, address, port, tos, cos, connect, read, disconnect, certificate, cipher)
+#define ast_netsock2_bind_tls(binder, socket_list, address, port, tos, cos, connect, read, disconnect, periodic, certificate, cipher) ast_netsock2_bind(binder, socket_list, AST_NETSOCK2_TRANSPORT_TLS, address, port, tos, cos, connect, read, disconnect, periodic, certificate, cipher)
 
 /*! \brief Bind to an address and port using the given transport
  * \param binder What is binding to this address/port
@@ -128,11 +130,12 @@
  * \param connect Function to be called upon acception of a connection
  * \param read Function to be called when there is data to be read
  * \param disconnect Function to be called upon disconnection
+ * \param periodic Function to be called periodically
  * \param certificate SSL Certificate to use
  * \param cipher SSL Cipher to use
  * \return Returns 0 on success, -1 on failure
  */
-int ast_netsock2_bind(const char *binder, struct ast_netsock2_socket_list *socket_list, enum ast_netsock2_transport transport, const char *address, int port, int tos, int cos, ast_netsock2_callback connect, ast_netsock2_callback read, ast_netsock2_callback disconnect, const char *certificate, const char *cipher);
+int ast_netsock2_bind(const char *binder, struct ast_netsock2_socket_list *socket_list, enum ast_netsock2_transport transport, const char *address, int port, int tos, int cos, ast_netsock2_callback connect, ast_netsock2_callback read, ast_netsock2_callback disconnect, ast_netsock2_callback periodic, const char *certificate, const char *cipher);
 
 /*! \brief Get amount of data waiting to be read on a socket
  * \param socket Socket that data is waiting on

Modified: team/file/netsock2/main/netsock2.c
URL: http://svn.digium.com/view/asterisk/team/file/netsock2/main/netsock2.c?view=diff&rev=97536&r1=97535&r2=97536
==============================================================================
--- team/file/netsock2/main/netsock2.c (original)
+++ team/file/netsock2/main/netsock2.c Wed Jan  9 12:29:38 2008
@@ -67,6 +67,7 @@
 	ast_netsock2_callback on_connect;
 	ast_netsock2_callback on_read;
 	ast_netsock2_callback on_disconnect;
+	ast_netsock2_callback on_periodic;
 	pthread_t thread;
 	struct ast_netsock2_socket *parent;
 #ifdef HAVE_OPENSSL
@@ -124,7 +125,7 @@
 
 	/* Now we essentially go into a loop until either they disconnect, the callback terminates them, or we are told to stop */
 	while (child_socket->thread != AST_PTHREADT_STOP) {
-		int res = ast_wait_for_input(child_socket->fd, -1);
+		int res = ast_wait_for_input(child_socket->fd, (parent->on_periodic ? parent->on_periodic(child_socket) : -1));
 
 		if (res > 0) {
 			parent->on_read(child_socket);
@@ -322,7 +323,7 @@
 }
 
 /*! Internal function that finds all IP addresses of a given transport and binds each individually */
-static int wildcard_individual_bind(const char *binder, struct ast_netsock2_socket_list *socket_list, enum ast_netsock2_transport transport, enum ast_netsock2_network_layer network_layer, int port, int tos, int cos, ast_netsock2_callback connect, ast_netsock2_callback read, ast_netsock2_callback disconnect, const char *certificate, const char *cipher)
+static int wildcard_individual_bind(const char *binder, struct ast_netsock2_socket_list *socket_list, enum ast_netsock2_transport transport, enum ast_netsock2_network_layer network_layer, int port, int tos, int cos, ast_netsock2_callback connect, ast_netsock2_callback read, ast_netsock2_callback disconnect, ast_netsock2_callback periodic, const char *certificate, const char *cipher)
 {
 	struct ifaddrs *ifstart = NULL, *ifcurrent = NULL;
 	int family = (network_layer == AST_NETSOCK2_NETWORK_LAYER_IPV6 ? AF_INET6 : AF_INET), res = 0;
@@ -344,7 +345,7 @@
 		if (getnameinfo(ifcurrent->ifa_addr, salen, address, sizeof(address), NULL, 0, NI_NUMERICHOST) < 0)
 			continue;
 
-		res = ast_netsock2_bind(binder, socket_list, transport, address, port, tos, cos, connect, read, disconnect, certificate, cipher);
+		res = ast_netsock2_bind(binder, socket_list, transport, address, port, tos, cos, connect, read, disconnect, periodic, certificate, cipher);
 	}
 
 	/* Now that we are all done we have to free the list, otherwise it would leak memory and that is bad, mmmk? */
@@ -364,11 +365,12 @@
  * \param connect Function to be called upon acception of a connection
  * \param read Function to be called when there is data to be read
  * \param disconnect Function to be called upon disconnection
+ * \param periodic Function to be called periodically
  * \param certificate SSL Certificate to use
  * \param cipher SSL Cipher to use
  * \return Returns 0 on success, -1 on failure
  */
-int ast_netsock2_bind(const char *binder, struct ast_netsock2_socket_list *socket_list, enum ast_netsock2_transport transport, const char *address, int port, int tos, int cos, ast_netsock2_callback connect, ast_netsock2_callback read, ast_netsock2_callback disconnect, const char *certificate, const char *cipher)
+int ast_netsock2_bind(const char *binder, struct ast_netsock2_socket_list *socket_list, enum ast_netsock2_transport transport, const char *address, int port, int tos, int cos, ast_netsock2_callback connect, ast_netsock2_callback read, ast_netsock2_callback disconnect, ast_netsock2_callback periodic, const char *certificate, const char *cipher)
 {
 	struct ast_netsock2_socket *netsock2_socket = NULL;
 	enum ast_netsock2_network_layer network_layer = AST_NETSOCK2_NETWORK_LAYER_IPV4;
@@ -405,7 +407,7 @@
 
 	/* Since we now have the address information from above let's see if this is a wildcard */
 	if ((network_layer == AST_NETSOCK2_NETWORK_LAYER_IPV6 ? IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6*)&addr.addr)->sin6_addr) : ((struct sockaddr_in*)&addr.addr)->sin_addr.s_addr == INADDR_ANY)) {
-		return wildcard_individual_bind(binder, socket_list, transport, network_layer, port, tos, cos, connect, read, disconnect, certificate, cipher);
+		return wildcard_individual_bind(binder, socket_list, transport, network_layer, port, tos, cos, connect, read, disconnect, periodic, certificate, cipher);
 	}
 
 	/* Next create an actual socket that we will eventually bind to */
@@ -454,6 +456,7 @@
 	netsock2_socket->on_connect = connect;
 	netsock2_socket->on_read = read;
 	netsock2_socket->on_disconnect = disconnect;
+	netsock2_socket->on_periodic = periodic;
 	memcpy(&netsock2_socket->addr.addr, &addr.addr, addr.len);
 	netsock2_socket->addr.len = addr.len;
 




More information about the asterisk-commits mailing list