示例#1
0
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);
    	}      
    }
}
示例#2
0
int      kn_close_sock(handle_t h){
	if(h->type != KN_SOCKET) 
		return -1;
	if(((kn_socket*)h)->type == SOCK_STREAM)
		return stream_socket_close(h);
	else
		return -1;
}