p.ferife
p.ferife

Reputation: 11

The return value for bind is not an int?

I am trying to learn c/c++ socket programming but the bind function working properly or is not returning what it should return, instead of "int" its returning "__bind " i don't know whats wrong and i have searched for what to do and no out come

please help

Server::Server()
: sock_fd(0)
{
    // number used as index in to the vector of client fd
    num = 0;
    clino.reserve(10);
    clientfd.reserve(10);
   if( (sock_fd = socket(AF_INET,SOCK_STREAM,0) ) < 0)
   {
       perror("Server constructor : cannot open socekt");
   }
    bzero(&servaddr, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_port = htons(TCP_PORT);
    servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
   //error returning __bind<int&, sockaddr*, unsigned long> 
   int b =  bind(sock_fd,(sockaddr *)&servaddr, sizeof(servaddr));



    //this bind function is acting up, dosent want to let me check for errors lol



    printf("printing..\n");
}




int Server::waitforconnections()
{

    printf("listening....\n");

    if(listen(sock_fd, 5) < 0)
    {
        perror("Server constructor : listen error");
    }

    for(;;)
    {
        clino[num] = num + 1;
        printf("accepting.. \n");
        clientfd[clino[num]] =  accept(sock_fd, (sockaddr *)&cliaddr, clilen);
        clisocktoaddr[clientfd[num]] = cliaddr;
        if(clientfd[num] < 0)
        {
            perror("waitforconnections: accept error");
        }
        //no client number 0
            if(do_service() < 0)
            {
                perror("waitforconnections: cannot do service, !!FATAL ERROR!!");
                _exit(-1);
            }
        //if i am going to use kids then they must be some inter processing communication don't forget !!


        num++;
    }




    return (0);
}

Upvotes: 0

Views: 1870

Answers (1)

dbush
dbush

Reputation: 223699

You're not calling the function you think you're calling.

Instead of calling bind, you're calling std::bind. This is one of the pitfalls that can happen when you have using namespace std; in your code.

You have two options here. You can call the socket bind function by using ::bind as the function name. Alternately, you can remove using namespace std; and prefix any object from this namespace with std::. The latter may mean more changes in your code but it will increase readability by being more clear about what is being used.

Upvotes: 8

Related Questions