LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-19-2015, 12:52 PM   #1
esolve
LQ Newbie
 
Registered: Oct 2012
Posts: 17

Rep: Reputation: Disabled
linux read(): after reading 20 bytes, reading again get "Resource temporarily unavail


I use funfd to read packets from a tun socket, which is registered as an even callback function with libevent.

at first I read the first 20 bytes to check the IP header, and then read the following bytes:

Code:
		
                nr_bytes = read(tunfd, buf, 20);
		assert(nr_bytes == 20);
		validate_ip(buf);	

		/* get the IP packet length and read the whole packet */
		iphdr = (struct ip *)buf;
		ip_len = ntohs(iphdr->ip_len);
		iphdr_len = iphdr->ip_hl*4;

		nr_bytes = read(tunfd, buf+20, ip_len-20);
		if(-1 == nr_bytes) perror("readtun() failed:\n");
but for the second read, `read(tunfd, buf+20, ip_len-20)`, I get "Resource temporarily unavailable", what are potential problems? and how to deal with it?
 
Old 10-20-2015, 05:52 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,812

Rep: Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290
Are you sure such partial read is possible?
 
Old 10-20-2015, 08:02 AM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: MA, USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 7,937
Blog Entries: 13

Rep: Reputation: 3423Reputation: 3423Reputation: 3423Reputation: 3423Reputation: 3423Reputation: 3423Reputation: 3423Reputation: 3423Reputation: 3423Reputation: 3423Reputation: 3423
More information is needed:
  1. What exact attributes are you using with your open()?
  2. Are you changing any attributes after you open the descriptor? If so what?
  3. What exact ERRNO number are you receiving? Check the manual page for read(2) because that error string only makes sense if you aren't root but needed to be root to use this resource. Since you've read from it once already, and managed to open it, I'm assuming permissions are not the issue here.
  4. It is perfectly fine to get EAGAIN if there's no data and the socket is non-blocking, this just means you have no data. I regularly code reads in a loop where I screen for that errno and upon seeing it just continue my loop silently because I know it just means there's no data at the present time.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
USB serial interface - initial read(2) ops fail, "Resource temporarily unavailable" MCinAZ Linux - Hardware 2 10-19-2015 02:19 AM
[SOLVED] reading 4 bytes at a time fread/fseek question. PoleStar Programming 2 04-23-2012 01:14 AM
"read" is reading info from while loop mikedotexe Linux - Newbie 1 02-10-2011 11:07 PM
..."short read while reading block 516" mohapi Fedora 7 10-22-2004 01:37 PM
Observing odd behavior while reading bytes jpbarto Programming 4 12-02-2003 01:47 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration