epoll problem with tcp connect()


 
Thread Tools Search this Thread
Top Forums Programming epoll problem with tcp connect()
# 1  
Old 12-15-2009
Question epoll problem with tcp connect()

I am using epoll to manage my network connections. At the client side, the idea is to send the message upon detecting the completion of connect(). I've set up the socket to be nonblocking, then after calling of connect(), I add the socket into the epoll and wait on the event to be detected from epoll_wait. But I found there's no event returned at all. I was wondering if connect() will report event or not? Or my code has some problem? Thanks.

here is the part of my code:
Code:
    
if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
        perror("socket");
        exit(1);
    }

    printf(">>>client socket = %d   master ip=%s\n", sockfd, master_ip);
    setnonblocking(sockfd);

    bzero(&serv_addr, sizeof(serv_addr));
    serv_addr.sin_family = PF_INET;
    serv_addr.sin_port = htons(PORT);
    inet_aton(master_ip, &serv_addr.sin_addr);

    ret=connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(struct sockaddr));
    if(ret <0 ) {
        if(errno!=EINPROGRESS) {
            ret = lustre_event_add(sockfd, EPOLLIN | EPOLLET,
                    lustre_sendmsg_event_handler, (void *)NULL);
            if (ret) {
                fprintf(stderr, "lustre_event_add failed.\n");
                return;
            }
        }
        else
            sockfd=ret;
        perror("connect");
    }

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Problem and question with TCP

Hi guys , i write this message for a doubt, a time ago i wrote a client/server program with TCP/IP in Linux. When i tested the program flooding the server with messages of 1024 bytes (Or 1025 bytes i dont remember exactly the number but was more that 1000 bytes) in certain point a message was... (5 Replies)
Discussion started by: Kovalevski
5 Replies

2. Programming

Problem with tcp server

Hello @ all, I hope you can give me some advice :b: I will be following code for a tcp server and doStuff () function, the clients treated. From some point, I have several identical clients (zombies, I think), the same records in the database write. Has anyone an explanation? What can I... (1 Reply)
Discussion started by: yumos
1 Replies

3. UNIX for Advanced & Expert Users

epoll, sockets and threads

Hello Forum, There is a transient bug in my code which I just can't catch. Could you help please? The basic idea is this. I have a multithreaded server and two thread pools, the IO pool and Worker pool. The main server thread listens to incoming connections. When it gets one, it dispatches... (0 Replies)
Discussion started by: rij
0 Replies

4. Shell Programming and Scripting

tcp/ip and memory problem

how the data from disk is loaded into memory and then it supplied to tcp/ip packet. how i can trace the no of pages loaded in memory by that process and rate of context switch for that process. (1 Reply)
Discussion started by: amar20
1 Replies

5. Red Hat

tcp/ip problem

how the data from disk is loaded into memory and then it transfered to tcp/ip packet. how i can find how many pages are loaded into memory by that process what is the rate of context switch for that process. (5 Replies)
Discussion started by: amar20
5 Replies

6. Solaris

TCP Problem

I am running a Java Client on Solaris 9 which communicates with the Server using TCP/IP. The client transmits a FIN packet to server. The server sends a ACK, FIN enters LAST_ACK state and then waits for ACK from client. The client did not respond back leaving the server in LAST_ACK itself. Also... (0 Replies)
Discussion started by: diarun
0 Replies

7. Programming

epoll detecting client connections

I've got a program running using epoll to poll activity on a listening socket. I want to be able to output a message to the terminal when the socket is connected to from the client app. It appears that epoll doesn't throw any events on the connect but only on the socket activity. Is there any... (1 Reply)
Discussion started by: mstaylor
1 Replies

8. Programming

epoll problem

I programmed simple tcp server using nonblocking sockets and epoll. But I am facing some problems. 1. I can recv from events.data.fd but I can't send any data over events.data.fd 2. When I make multiple connections at once (say 100) I get segmentation fault... What am I doing wrong? ... (1 Reply)
Discussion started by: Parahat Melayev
1 Replies

9. IP Networking

WinXP and TCP/IP Problem

Hi Eveyone, I have A small problems maybe some one can help me. I'm running a small network at home with internet access. Two PC's have Win XP and one has Win98se. I have them all hook up on a SMC router. ALL windows firewall are off and and harddrive sharing is on. I am using DCHP network... (3 Replies)
Discussion started by: Peterh
3 Replies

10. IP Networking

tcp problem with port

I am trying to connect via DBACCESS and Informix server to a server on a different computer. When I execute the connect command from dbaccess I get the following message, Exec format error cannot bind a name to the port. As far as I know the port is not being used by another client. How... (1 Reply)
Discussion started by: lopez
1 Replies
Login or Register to Ask a Question