- To: Michael Still <mikal@xxxxxxxxxxx>
- Subject: Re: [SLUG] EINVAL on socket read
- From: Crossfire <xfire@xxxxxxxx>
- Date: Thu May 24 09:57:02 2001
- Cc: slug@xxxxxxxxxxx
- User-agent: Mutt/1.2.5i
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
xfire@xxxxxxxx | on 100% Recycled Electrons
--==============================================--