Michael Still was once rumoured to have said:
> 
> Hey all.
> 
> I have some socket code, which binds to a port and then accepts
> connections. Every time I try to read() from the socket, I get a EINVAL. I
> am sure that I am doing something grossly stupid, and was wondering if
> anyone could tell me what I had missed.
> 
> Sorry about the big code dump, I have tried to trim it down a bit.

[Snip]
> 
>   while(1){
>     if(accept(socketfd, (struct sockaddr *) &connaddr, &connaddrlen) ==
> -1)

This is where your error lies.

this should read:

        while(1) {
                int     newfd = 0;

                if ((newfd = accept(socketfd, (struct sockaddr*) &connaddr, 
&connaddrlen) == -1) {
                        // error handling here...
                        ...
                }

And use newfd as the socket to read from/write to.

C.
-- 
--==============================================--
  Crossfire      | This email was brought to you
  [EMAIL PROTECTED] | on 100% Recycled Electrons
--==============================================--

-- 
SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug

Reply via email to