utils: Add convenience function for setting fd flags
[asterisk/asterisk.git] / res / res_pktccops.c
index e1d9d40..156c49d 100644 (file)
@@ -37,8 +37,6 @@
 
 #include "asterisk.h"
 
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <fcntl.h>
@@ -650,7 +648,7 @@ static struct cops_gate *cops_gate_cmd(int cmd, struct cops_cmts *cmts,
 
 static int cops_connect(char *host, char *port)
 {
-       int s, sfd = -1, flags;
+       int s, sfd = -1;
        struct addrinfo hints;
        struct addrinfo *rp;
        struct addrinfo *result;
@@ -676,8 +674,7 @@ static int cops_connect(char *host, char *port)
                if (sfd == -1) {
                        ast_log(LOG_WARNING, "Failed socket\n");
                }
-               flags = fcntl(sfd, F_GETFL);
-               fcntl(sfd, F_SETFL, flags | O_NONBLOCK);
+               ast_fd_set_flags(sfd, O_NONBLOCK);
 #ifdef HAVE_SO_NOSIGPIPE
                setsockopt(sfd, SOL_SOCKET, SO_NOSIGPIPE, &trueval, sizeof(trueval));
 #endif
@@ -799,9 +796,9 @@ static void *do_pktccops(void *data)
                                if ((idx = ast_poll_fd_index(pfds, nfds, cmts->sfd)) > -1 && (pfds[idx].revents & POLLIN)) {
                                        len = cops_getmsg(cmts->sfd, recmsg);
                                        if (len > 0) {
-                                               ast_debug(3, "COPS: got from %s:\n Header: versflag=0x%.2x opcode=%i clienttype=0x%.4x msglength=%u\n",
-                                                       cmts->name, (unsigned)recmsg->verflag,
-                                                       recmsg->opcode, (unsigned)recmsg->clienttype, recmsg->length);
+                                               ast_debug(3, "COPS: got from %s:\n Header: versflag=0x%02hhx opcode=%i clienttype=0x%04hx msglength=%u\n",
+                                                       cmts->name, recmsg->verflag,
+                                                       recmsg->opcode, recmsg->clienttype, recmsg->length);
                                                if (recmsg->object != NULL) {
                                                        pobject = recmsg->object;
                                                        while (pobject != NULL) {
@@ -1474,6 +1471,10 @@ static int load_module(void)
        }
        ast_cli_register_multiple(cli_pktccops, sizeof(cli_pktccops) / sizeof(struct ast_cli_entry));
        restart_pktc_thread();
+
+       /* For Optional API. */
+       ast_module_shutdown_ref(AST_MODULE_SELF);
+
        return 0;
 }
 
@@ -1511,9 +1512,9 @@ static int reload_module(void)
 }
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "PktcCOPS manager for MGCP",
-               .support_level = AST_MODULE_SUPPORT_EXTENDED,
-               .load = load_module,
-               .unload = unload_module,
-               .reload = reload_module,
-              );
+       .support_level = AST_MODULE_SUPPORT_EXTENDED,
+       .load = load_module,
+       .unload = unload_module,
+       .reload = reload_module,
+);