Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 03-01-2002, 06:43 PM   #1
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);

rc=connect(sock,(struct sockaddr *)&server,sizeof(struct sockaddr));

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

cut here --

the sig_alrm function its:

cut here ---
sig_alrm() {
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, 02:54 PM   #2
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

also Steven's UNIX Network programming is a must read


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

All times are GMT -5. The time now is 06:57 AM.

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