Sponsored Content
Top Forums Programming epoll problem with tcp connect() Post 302380513 by tuesday420 on Tuesday 15th of December 2009 11:22:28 AM
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");
    }

 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
EPOLL_CREATE(2) 					     Linux Programmer's Manual						   EPOLL_CREATE(2)

NAME
epoll_create, epoll_create1 - open an epoll file descriptor SYNOPSIS
#include <sys/epoll.h> int epoll_create(int size); int epoll_create1(int flags); DESCRIPTION
epoll_create() creates an epoll(7) instance. Since Linux 2.6.8, the size argument is ignored, but must be greater than zero; see NOTES below. epoll_create() returns a file descriptor referring to the new epoll instance. This file descriptor is used for all the subsequent calls to the epoll interface. When no longer required, the file descriptor returned by epoll_create() should be closed by using close(2). When all file descriptors referring to an epoll instance have been closed, the kernel destroys the instance and releases the associated resources for reuse. epoll_create1() If flags is 0, then, other than the fact that the obsolete size argument is dropped, epoll_create1() is the same as epoll_create(). The following value can be included in flags to obtain different behavior: EPOLL_CLOEXEC Set the close-on-exec (FD_CLOEXEC) flag on the new file descriptor. See the description of the O_CLOEXEC flag in open(2) for rea- sons why this may be useful. RETURN VALUE
On success, these system calls return a nonnegative file descriptor. On error, -1 is returned, and errno is set to indicate the error. ERRORS
EINVAL size is not positive. EINVAL (epoll_create1()) Invalid value specified in flags. EMFILE The per-user limit on the number of epoll instances imposed by /proc/sys/fs/epoll/max_user_instances was encountered. See epoll(7) for further details. ENFILE The system limit on the total number of open files has been reached. ENOMEM There was insufficient memory to create the kernel object. VERSIONS
epoll_create() was added to the kernel in version 2.6. Library support is provided in glibc starting with version 2.3.2. epoll_create1() was added to the kernel in version 2.6.27. Library support is provided in glibc starting with version 2.9. CONFORMING TO
epoll_create() is Linux-specific. NOTES
In the initial epoll_create() implementation, the size argument informed the kernel of the number of file descriptors that the caller expected to add to the epoll instance. The kernel used this information as a hint for the amount of space to initially allocate in inter- nal data structures describing events. (If necessary, the kernel would allocate more space if the caller's usage exceeded the hint given in size.) Nowadays, this hint is no longer required (the kernel dynamically sizes the required data structures without needing the hint), but size must still be greater than zero, in order to ensure backward compatibility when new epoll applications are run on older kernels. SEE ALSO
close(2), epoll_ctl(2), epoll_wait(2), epoll(7) COLOPHON
This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. Linux 2012-04-15 EPOLL_CREATE(2)
All times are GMT -4. The time now is 08:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy