LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 03-01-2002, 07:43 PM   #1
bzImage
LQ Newbie
 
Registered: Mar 2002
Location: Cuautitlan Izcalli, Mexico
Posts: 1

Rep: Reputation: 0
help!!! how can i timeout a socket connect call... ?


in the sample code:

cut here ---
signal(SIGALRM, sig_alrm);

alarm(TIMEOUT);
printf("tying...");
rc=connect(sock,(struct sockaddr *)&server,sizeof(struct sockaddr));
alarm(0);

if (rc == -1 && errno == EINTR)
{
perror("unable to connect");
return(1);
}

cut here --

the sig_alrm function its:

cut here ---
sig_alrm() {
exit(0);
}
cut here--

how can i timeout this connect function ?
when i run the program i get:

Resource temporarily unavailable

HELP please..
 
Old 03-06-2002, 03:54 PM   #2
kervin
Member
 
Registered: Jan 2002
Location: Melbourne, FL.
Distribution: redhat
Posts: 168

Rep: Reputation: 30
I don't know why your code doesn't work but why don't you open the socket as non-blocking?

That way connect() returns immediately and you can then use select() to poll the socket file descriptor to see if it's ready.

As a non-blocking socket, all your function will return immediately.

See also, the UNIX Socket FAQ at http://www.developerweb.net/sock-faq/

also Steven's UNIX Network programming is a must read
http://shop.barnesandnoble.com/textb...sbn=013490012x
 
  


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
Fedora 3 - PHP - Socket timeout b_whelan Linux - Software 2 09-29-2005 03:41 AM
Socket timeout (c question) alaios Programming 13 09-11-2005 12:43 PM
Unable to connect to UNIX socket /tmp/.esd/socket error while using grip dr_zayus69 Linux - Software 4 08-23-2005 08:28 PM
C++: can you set a timeout for a system call? BrianK Programming 1 06-03-2005 09:43 PM
connect: socket operation on non-socket bit7 Linux - Networking 0 02-18-2003 06:08 PM


All times are GMT -5. The time now is 09:10 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration