예제 #1
0
void iguana_acceptloop(void *args)
{
    socklen_t clilen; struct sockaddr_in cli_addr; struct iguana_peer *addr; struct iguana_info *coin = args;
    addr = &coin->bindaddr;
    memset(addr,0,sizeof(*addr));
    iguana_initpeer(coin,addr,(uint32_t)calc_ipbits("127.0.0.1"));
    addr->usock = pp_bind("127.0.0.1",coin->chain->portp2p);
    printf("iguana_bindloop 127.0.0.1 bind sock.%d\n",addr->usock);
    memset(coin->fds,0,sizeof(coin->fds));
    while ( 1 )
    {
        printf("LISTEN on sock.%d\n",addr->usock);
        listen(addr->usock,64);
        clilen = sizeof(cli_addr);
        printf("ACCEPT on sock.%d\n",addr->usock);
        coin->fds[coin->numsocks].fd = accept(addr->usock,(struct sockaddr *)&cli_addr,&clilen);
        printf("NEWSOCK.%d\n",coin->fds[coin->numsocks].fd);
        if ( coin->fds[coin->numsocks].fd < 0 )
        {
            printf("ERROR on accept\n");
            continue;
        }
        coin->numsocks++;
    }
}
예제 #2
0
void *bindloop(void *args)
{
    int32_t pp_bind(char *hostname,uint16_t port);
    int32_t sock,newsock; socklen_t clilen; struct sockaddr_in cli_addr; char buffer[512];
    sock = pp_bind("127.0.0.1",8000);
    printf("bind sock.%d\n",sock);
    while ( 1 )
    {
        listen(sock,5);
        clilen = sizeof(cli_addr);
        newsock = accept(sock, (struct sockaddr *)&cli_addr, &clilen);
        if ( newsock < 0 )
        {
            printf("ERROR on accept\n");
            continue;
        }
        int result = (int32_t)recv(newsock, buffer, sizeof(buffer), 0);
        printf("bind recv.%d (%s)\n",result,buffer);
        close(newsock);
    }
    return(0);
}