Kurt Van Dijck wrote:
> On Mon, Sep 21, 2009 at 10:30:07AM +0200, [email protected] wrote:
>> Hello Wolfgang,
>>
>> I have tested SW again and cannot reproduce error situation I had
>> yesterday.
>> Everything turns out to be OK. Was it Sunday effect? I have no idea...
>> The write function issue you have mentioned is fixed (see attached).
> I looked at the code.
> 
>                         while( (nbytes=write(s, &tx_frames[send_pos], 
> sizeof(*tx_frames))) !=
>                                    sizeof(*tx_frames) )
>                         {
>                                 if(nbytes!=EAGAIN)
>                                 {
>                                         perror("write");
>                                         return 1;
>                                 }
>                         }
> 
> I don't know the exact purpose of the test.
> This loops asks for sunday effects, isn't it?
> 
> nbytes would return -1, not EAGAIN!
>    if ((nbytes < 0)&&(EAGAIN == errno))

With proper error handling it should look like:

        if (nbytes < 0) {
                if (errno == ENOBUFS)
                        continue;
                perror("write failed");
        } else {
                fprintf(stderr, "write returned bogus %d\n", nbytes);
        }
        return 1;

> is what I think you meant

Ah, oh, sure, missed that :-(. Thanks for pointing that out.

> my preference:
> 
>    int ret;
>    struct pollfd pollfd;
> 
>    pollfd.fd = s;
>    pollfd.events = POLLOUT;
>    while ((ret = poll(&pollfd, 1, -1)) < 0) {
>       if (EAGAIN == errno) {
>          perror("write");
>          return 1;
>       }
>    }
>    nbytes = write(s, ....)
>    // nbytes with anything other than sizeof(*tx_frames) is a serious
>    // poll issue
>> Regards,
>> Vladislav

As Marc pointed out, poll/select will block in case of ENOBUFS.

Wolfgang.
_______________________________________________
Socketcan-core mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/socketcan-core

Reply via email to