Beispiel #1
0
redisContext *redisConnectBindNonBlock(const char *ip, int port, int ssl, char* certfile, char* certdir,
                                       const char *source_addr) {
    redisContext *c = redisContextInit();
    c->flags &= ~REDIS_BLOCK;
        
    if( ssl ) {
    	setupSSL();
    	// TODO: Create a bind version of this...
        redisContextConnectSSL(c,ip,port,certfile,certdir,NULL);
    } else {
       	redisContextConnectBindTcp(c,ip,port,NULL,source_addr);
    }
    
    return c;
}
Beispiel #2
0
redisContext *redisConnectNonBlock(const char *ip, int port, int ssl, char* certfile, char* certdir) {
    redisContext *c;

    c = redisContextInit();
    if (c == NULL)
        return NULL;

    c->flags &= ~REDIS_BLOCK;

    if( ssl ) {
      setupSSL();
      redisContextConnectSSL(c,ip,port,certfile,certdir,NULL);
    } else {
      redisContextConnectTcp(c,ip,port,NULL);
    }

    return c;
}
Beispiel #3
0
redisContext *redisConnectWithTimeout(const char *ip, int port, const struct timeval tv, int ssl, char* certfile, char* certdir) {
    redisContext *c;

    c = redisContextInit();
    if (c == NULL)
        return NULL;

    c->flags |= REDIS_BLOCK;

    if( ssl ) {
      setupSSL();
      redisContextConnectSSL(c,ip,port,certfile,certdir,&tv);
    } else {
      redisContextConnectTcp(c,ip,port,&tv);
    }

    return c;
}
Beispiel #4
0
int main(int argc, char **argv) {
	if (argc != 2) {
		perror("Illegal argument count\n");
		exit(0);
	}

	/* server port */
	int port = (int) strtol(argv[1], (char **)NULL, 10);

	/* ssl setup */
	SSL_CTX *ssl_ctx;
	ssl_ctx = setupSSL();

	/* socket setup */
	int sockfd = setupSocket(port);


    fd_set rfds;//, temp_set;
    struct timeval tv;
    int retval;//, maxfd = sockfd;

	for (;;){
        FD_ZERO(&rfds);
        FD_SET(sockfd, &rfds);

	    tv.tv_sec = 5;
        tv.tv_usec = 0;
        retval = select(sockfd + 1, &rfds, NULL, NULL, &tv);

        if (retval == -1) {
            perror("accept()");
        } else if (retval > 0) {
            if (FD_ISSET(sockfd, &rfds)) {
                printf("Someone is trying to connect!\n");

                struct sockaddr_in addr;
                socklen_t len = sizeof(addr);

                printf("Accepting connection!\n");
                int fd_client = accept(sockfd, (struct sockaddr*)&addr, &len);
                if (fd_client < 0) {
                    perror("accept()");
                    exit(0);
                }
                
                SSL *ssl = SSL_new(ssl_ctx);
                SSL_set_fd(ssl, fd_client);

                printf("Accepting SSL connection!\n");
                if (SSL_accept(ssl) < 0){
                    perror("SSL_accept()");
                    exit(0);
                }

                printf("Saying Hello!\n");
                SSL_write(ssl, "Hello", sizeof("Hello"));

                printf("Stopping connection!\n");
                SSL_free(ssl);
                close(fd_client);
            }

        } else {
            printf("No message in five seconds.\n");
        }
    }

	close(sockfd);
	SSL_CTX_free(ssl_ctx);
}