Which socket protocol types support blocking read? stream? dgram? raw?

User avatar
i_am_mrp
Posts: 27
Joined: Thu Sep 28, 2017 9:14 am
Location: California

Which socket protocol types support blocking read? stream? dgram? raw?

Postby i_am_mrp » Wed Nov 15, 2017 8:28 pm

sockets.h defines 3 socket protocol types: SOCK_STREAM, SOCK_DGRAM and SOCK_RAW.

Do any of these support blocking reads?

I am using the lwip_socket(..) function to create the socket and lwip_read(..) or lwip_recv(..) to do the reads.
Underneath both read functions ultimately call: lwip_recvfrom(..).
I see that lwip_recv(..) allows for some flags to be passed in while the lwip_read(..) does not. Are there specific flags to enable blocking read?

Is there a way to specify you want blocking reads when configuring the socket/connection?
Is there some way to achieve the blocking read via the lwip_setsockopt(..) function?

I am specifically using SOCK_STREAM in specific tests and can't get the read() to block. I am interested all 3 socket protocol types as mentioned previously.

I have looked at the sockets.h/sockets.c code but it's not obvious what the default behaviors are and how to achieve the blocking read semantic.

User avatar
i_am_mrp
Posts: 27
Joined: Thu Sep 28, 2017 9:14 am
Location: California

Re: Which socket protocol types support blocking read? stream? dgram? raw?

Postby i_am_mrp » Thu Nov 16, 2017 12:50 am

setsockopt(..) can be used to control the send and receive timeouts. It appears the connect timeout is not currently supported

Code: Select all

#include "sockets.h"

struct timeval tv;
    tv.tv_sec = 10 ; // seconds
    tv.tv_usec = 0 ;
int rc = setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
I have tried/verified both send and receive timeouts do indeed work as expected for at least socket protocol type: SOCK_STREAM

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 186 guests