/** Create an unbound Socket object. * * \param name name of the object, used for debugging * \param is_tcp true if TCP, false for UDP XXX: This should be more generic * \return a pointer to the SocketInt object, cast as a Socket, with a newly opened system socket * \see socket_free, socket_close */ Socket* socket_new(const char* name, int is_tcp) { SocketInt* self = socket_initialize(name); self->is_tcp = is_tcp; /* XXX: replace is_tcp with a more meaningful variable to contain that */ self->is_disconnected = 1; return (Socket*)self; }
int uart_init(int argc, char **argv) { lowmark=highmark=0; vte = vte_terminal_new(); gui_append_new_tab("UART",vte); //vte_terminal_set_pty(VTE_TERMINAL(vte), ptyslave); g_signal_connect(vte,"commit",(GCallback)&vte_uart_data,NULL); //poll_add(ptymaster, POLL_IN, &uart_incoming_data); socket_initialize(); return 0; }
/** Eventloop callback called when a new connection is received on a listening Socket. * * This function accept()s the connection, and creates a SocketInt to wrap * the underlying system socket. It then runs the user-supplied callback * (passed to socket_server_new() when creating the listening Socket) on this * new object, passing it the handle (passed to socket_server_new( too)) * * \param source source from which the event was received (e.g., an OComm Channel) * \param handle pointer to opaque data passed when creating the listening Socket */ static void on_client_connect(SockEvtSource* source, void* handle) { (void)source; // FIXME: Check why source parameter is unused char host[ADDRLEN], serv[SERVLEN]; size_t namesize; *host = 0; *serv = 0; socklen_t cli_len; SocketInt* self = (SocketInt*)handle; SocketInt* newSock = socket_initialize(NULL); cli_len = sizeof(newSock->servAddr.sa_stor); newSock->sockfd = accept(self->sockfd, &newSock->servAddr.sa, &cli_len); if (newSock->sockfd < 0) { o_log(O_LOG_ERROR, "socket(%s): Error on accept: %s\n", self->name, strerror(errno)); oml_free(newSock); return; } /* XXX: Duplicated somewhat with socket_in_new and s_connect */ if (!getnameinfo(&newSock->servAddr.sa, cli_len, host, ADDRLEN, serv, SERVLEN, NI_NUMERICHOST|NI_NUMERICSERV)) { namesize = strlen(host) + strlen(serv) + 3 + 1; newSock->name = oml_realloc(newSock->name, namesize); snprintf(newSock->name, namesize, "[%s]:%s", host, serv); } else { namesize = strlen(host) + 4 + 10 + 1; /* XXX: 10 is arbitrarily chosen for the number of characters in sockfd's decimal representation */ newSock->name = oml_realloc(newSock->name, namesize); snprintf(newSock->name, namesize, "%s-io:%d", self->name, newSock->sockfd); o_log(O_LOG_WARN, "socket(%s): Error resolving new client source, defaulting to %s: %s\n", self->name, newSock->name, strerror(errno)); } if (self->connect_callback) { self->connect_callback((Socket*)newSock, self->connect_handle); } }