示例#1
0
static void
fpv_create(const char *type, struct fake_pvconn *fpv)
{
#ifdef HAVE_OPENSSL
    if (!strcmp(type, "ssl")) {
        stream_ssl_set_private_key_file("testpki-privkey.pem");
        stream_ssl_set_certificate_file("testpki-cert.pem");
        stream_ssl_set_ca_cert_file("testpki-cacert.pem", false);
    }
#endif

    fpv->type = type;
    if (!strcmp(type, "unix")) {
        static int unix_count = 0;
        char *bind_path;

        bind_path = xasprintf("fake-pvconn.%d", unix_count++);
        fpv->pvconn_name = xasprintf("punix:%s", bind_path);
        fpv->vconn_name = xasprintf("unix:%s", bind_path);
        CHECK_ERRNO(pstream_open(fpv->pvconn_name, &fpv->pstream,
                                 DSCP_DEFAULT), 0);
        free(bind_path);
    } else if (!strcmp(type, "tcp") || !strcmp(type, "ssl")) {
        char *s, *port, *save_ptr = NULL;
        char *open_name;

        open_name = xasprintf("p%s:0:127.0.0.1", type);
        CHECK_ERRNO(pstream_open(open_name, &fpv->pstream, DSCP_DEFAULT), 0);

        /* Extract bound port number from pstream name. */
        s = xstrdup(pstream_get_name(fpv->pstream));
        strtok_r(s, ":", &save_ptr);
        port = strtok_r(NULL, ":", &save_ptr);

        /* Save info. */
        fpv->pvconn_name = xstrdup(pstream_get_name(fpv->pstream));
        fpv->vconn_name = xasprintf("%s:127.0.0.1:%s", type, port);

        free(open_name);
        free(s);
    } else {
        abort();
    }
}
示例#2
0
文件: server.c 项目: KIRAlzn/stream
int main()
{

    struct pstream* p_pstream; 
    struct stream* p_stream;
    const char* pstream_name = "ptcp:1234";
    char buffer[50];
    uint8_t dscp = 1;
    int actualrecv = 0;


    if(pstream_open(pstream_name,&p_pstream,dscp))
        printf("pstream open failure!\n");
    else
    {
        while(1)
        {  
    
	    while(pstream_accept(p_pstream, &p_stream))
                ;
            printf("\nget one steam connect success!\n");

            printf("p_pstream name:%s\n", pstream_get_name(p_pstream));
            printf("p_pstream bound_port:%d\n", pstream_get_bound_port(p_pstream));
	    printf("p_stream name:%s\n", stream_get_name(p_stream));


            printf("<remote_ip,remote_port> : <%d,%d>\n", stream_get_remote_ip(p_stream),stream_get_remote_port(p_stream));
            printf("<local_ip,local_port> : <%d,%d>\n", stream_get_local_ip(p_stream),stream_get_local_port(p_stream));

            actualrecv = stream_recv(p_stream,buffer,sizeof(buffer));
 
           if(actualrecv < 0)
              printf("pstream receive failure!\n");
           else if(actualrecv == 0)
               printf("pstream receive 0 bytes!\n");
           else
               printf("pstream actual receive %d bytes,buffer:%s\n\n",actualrecv,buffer);

         }


        stream_close(p_stream);
        pstream_close(p_pstream);

    }   
 
    return 0;
}