Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » FD_ISSET Segmentation Fault?!!

This thread is locked; no one can reply to it. rss feed Print
FD_ISSET Segmentation Fault?!!
Daniel McKinnon
Member #1,463
August 2001
avatar

Okay, this makes absolutely no sense to me:

The line:

a = FD_ISSET( net->sockfd, &net->fd );

where a is an integer, and net is of type networktype
#define MAXDATASIZE 0x1000
typedef struct networktype{
int sockfd;
int numbytes;
int bufsize;
struct timeval t;
fd_set fd;
unsigned char line[MAXDATASIZE];
unsigned char buf[MAXDATASIZE];
struct hostent *he;
struct sockaddr_in their_addr;
} networktype;

Why, Oh why would it ever segmentation fault THERE?!

Steve Terry
Member #1,989
March 2002
avatar

Why do you need to pass in the address of fd... it's not like anything is changed in ISSET.

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

Billybob
Member #3,136
January 2003

ST: Because that's the way it's delcared.
[url http://www.zevils.com/cgi-bin/man/man2html?FD_ISSET+2]

As for the segmentation fault, maybe you need to ZERO the set before doing anything else to it?

Steve Terry
Member #1,989
March 2002
avatar

Sorry I couldn't remember off the top of my head.. I should of researched.

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

Daniel McKinnon
Member #1,463
August 2001
avatar

The set is FD_ZERO'ed, this is mind boggling...

Edit: Actually, I should mention that I'm trying to use select() as a method of non-blocking sockets. Now, one of the funny things I encountered, is that it never seems to time out, and that the call to FD_SET is passing a 1 a whole bunch of times, but then suddenly (but consistantly) gives me a segmentation fault, I beleive (but I'm not sure) when select() finally times out. It's still mind boggling.

Steve Terry
Member #1,989
March 2002
avatar

Did you set timeval t to { 0, 0 }?

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

Daniel McKinnon
Member #1,463
August 2001
avatar

notta, it's actually {2,50000}, but I don't think that would work anyways.

I'm lead to beleive that I have some kind of strange memory leak or what-have-you, but I just can't seem to figure out where it is. It's okay, this code was second prototype anyhow.

I'm on my second draft of engineering, and I was hoping to get at least something usefull out of it. I guess I did.

Thanks for the help anyways.

By the way, tip to all you NEWBIES out there, a good plan is to brainstorm, write two engineering drafts, a final engineering document, and make prototypes along the way. Once your done, write the documents and you should have a solid peice of code. (unlike this silly spaghetti masterpeice)

aquasync
Member #3,964
October 2003

Yeah, a bit confusing, I had to figure this same stuff out to write a daemon recently. Anyway, your timeout problem is possibly the same mistake I made, which is that you need to re-set the timeout every time. Also check the fd values aren't greater than MAX_FD (or whatever the define is).

ReyBrujo
Moderator
January 2001
avatar

Are you sure you have cleared the set and set the descriptor correctly?

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

Thomas Fjellstrom
Member #476
June 2000
avatar

isnt fd supposed to be one more than the max fd you put in a set?

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Daniel McKinnon
Member #1,463
August 2001
avatar

Never had a problem with the timeout, I was indeed always setting it. The descriptors were being set properly, I've done it a million times before.

sockfd+1 was always under FD_MAX, but good observation. I scrapped that prototype anyhow, I'm onto my final draft here, and It's looking pretty darn solid so far. Thanks for the help anyways though.

Go to: