static void process_accept(kn_socket *s){ int fd; kn_sockaddr remote; for(;;) { fd = _accept(s,&remote); if(fd < 0) break; else{ handle_t h = new_stream_socket(fd,s->domain); ((kn_socket*)h)->addr_local = s->addr_local; ((kn_socket*)h)->addr_remote = remote; if(((kn_stream_socket*)s)->ctx){ ((kn_stream_socket*)h)->ssl = SSL_new(((kn_stream_socket*)s)->ctx); SSL_set_fd(((kn_stream_socket*)h)->ssl, fd); if (SSL_accept(((kn_stream_socket*)h)->ssl) == -1) { printf("SSL_accept error\n"); stream_socket_close(h); continue; } } h->status = SOCKET_ESTABLISH; ((kn_socket*)s)->callback(h,s,0,0); } } }
static void on_connected(int32_t fd,int32_t err,void *ud) { if(fd >= 0 && err == 0) { engine *e = (engine*)ud; stream_socket_ *h = new_stream_socket(fd); engine_associate(e,h,transfer_finish); struct session *s = session_new(h); session_send(s,65535); } else if(err == ETIMEDOUT) { printf("connect timeout\n"); } }
handle_t kn_new_sock(int domain,int type,int protocal){ int fd = socket(domain,type|SOCK_CLOEXEC,protocal); if(fd < 0) return NULL; handle_t h = NULL; if(type == SOCK_STREAM) h = new_stream_socket(fd,domain); else if(type == SOCK_DGRAM){ h = new_datagram_socket(fd,domain); } if(!h) close(fd); return h; }