Looping connect call for a non blocking socket


 
Thread Tools Search this Thread
Top Forums Programming Looping connect call for a non blocking socket
# 8  
Old 09-24-2012
Because you are always sleeping for a fixed time on every case, on a good network you will always have a time loss of the initial sleep even if the socket is ready for use already. It will work, but I think thats bad design. You should always do select and check connect return value before doing a possibly wasteful sleep.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Cannot connect to socket

solaris client report "cannot to socket(code 25)" while trying to backup on veritas netbackup 6.5.5 server (1 Reply)
Discussion started by: EUGINIAM
1 Replies

2. Programming

Looping problems socket programming in C

Sorry if I posted 2 separate questions. I'm currently doing socket programming on my current task. As you can see below in the client side. I've tried to do a loop so I will be able to get prompt for input over and over again. This is the code. do{ printf("Please your name > ");... (10 Replies)
Discussion started by: aLHaNz
10 Replies

3. Programming

socket accept() keeps looping

I'm using C/ C++ with gcc on Linux. I've a server socket where accept() is called on the socket inside a while() loop. The problem I am facing is that the first call to accept is blocking (i.e., the program waits for the first connection) but as soon as I fork afterwards (so that the child process... (2 Replies)
Discussion started by: jaywalker
2 Replies

4. Programming

write on Non Blocking Socket

How to know whether socket is ready for write. select(maxfds, (fd_set *)NULL, &writefds, NULL, &timeout); By default socket is set for write without checking whether it would block or not? If so how do I know my FD is ready for writing. (3 Replies)
Discussion started by: satish@123
3 Replies

5. Programming

non blocking connect

OS : solaris 10 X86 I created stream socket, tries to connect to port 7 on the remote machine. After doing the non blocking connect call I did select with time out value is 3 secs. I am always getting timed out though I am writing prior to select. code: x=fcntl(S,F_GETFL,0);... (1 Reply)
Discussion started by: satish@123
1 Replies

6. Solaris

Non-blocking connect readability & writeability

Hello, When using a non-blocking connect, is it _guaranteed_ that connection completion can be detected by selecting for writeability? I have encountered situations where the socket has returned both readable and writeable at the same time - having trawled the net, I have seen some old posts... (1 Reply)
Discussion started by: tristan12
1 Replies

7. Programming

connect() socket API

Is there any relation between the connect() socket API and the TCP's Transmission Control Block. Also how does connect detect that a socket is in use i.e., EADDRINUSE (1 Reply)
Discussion started by: sunaina
1 Replies

8. UNIX for Advanced & Expert Users

connect problem for sctp socket (ipv6 socket) - Runtime fail Invalid Arguments

Hi, I was porting ipv4 application to ipv6; i was done with TCP transports. Now i am facing problem with SCTp transport at runtime. To test SCTP transport I am using following server and client socket programs. Server program runs fine, but client program fails giving Invalid Arguments for... (0 Replies)
Discussion started by: chandrutiptur
0 Replies

9. Shell Programming and Scripting

Looping connect to different server

Hi there. I am attempting to write a script that will read through a flat file, get the server and directory that I want the size for, connect to the server, get the directory size, and send it to an output file. Here is what I have: while read LINE do NAME=`echo $LINE | awk -F'~' '{print... (5 Replies)
Discussion started by: la_womn
5 Replies

10. UNIX for Dummies Questions & Answers

Blocking ftp users to connect using telnet

Hi everybody ! We have all flavors of Unix / Linux and we want to restrict ftp users to telnet our servers. We can't disable telnet because we have other users using it. :confused: Are there any thing that could be done to solve this thing ??? Best regards, Julio Moreira (11 Replies)
Discussion started by: juliocdrm
11 Replies
Login or Register to Ask a Question
connect(3SOCKET)														  connect(3SOCKET)

NAME
connect - initiate a connection on a socket SYNOPSIS
cc [ flag ... ] file ... -lsocket -lnsl [ library ... ] #include <sys/types.h> #include <sys/socket.h> int connect(int s, const struct sockaddr *name, int namelen); The parameter s is a socket. If it is of type SOCK_DGRAM, connect() specifies the peer with which the socket is to be associated. This address is the address to which datagrams are to be sent if a receiver is not explicitly designated. This address is the only address from which datagrams are to be received. If the socket s is of type SOCK_STREAM, connect() attempts to make a connection to another socket. The other socket is specified by name. name is an address in the communication space of the socket. Each communication space interprets the name parameter in its own way. If s is not bound, then s will be bound to an address selected by the underlying transport provider. Gener- ally, stream sockets can successfully connect() only once. Datagram sockets can use connect() multiple times to change their association. Datagram sockets can dissolve the association by connecting to a null address. If the connection or binding succeeds, 0 is returned. Otherwise, -1 is returned and sets errno to indicate the error. The call fails if: EACCES Search permission is denied for a component of the path prefix of the pathname in name. EADDRINUSE The address is already in use. EADDRNOTAVAIL The specified address is not available on the remote machine. EAFNOSUPPORT Addresses in the specified address family cannot be used with this socket. EALREADY The socket is non-blocking, and a previous connection attempt has not yet been completed. EBADF s is not a valid descriptor. ECONNREFUSED The attempt to connect was forcefully rejected. The calling program should close(2) the socket descriptor, and issue another socket(3SOCKET) call to obtain a new descriptor before attempting another connect() call. EINPROGRESS The socket is non-blocking, and the connection cannot be completed immediately. You can use select(3C) to com- plete the connection by selecting the socket for writing. EINTR The connection attempt was interrupted before any data arrived by the delivery of a signal. The connection, how- ever, will be established asynchronously. EINVAL namelen is not the size of a valid address for the specified address family. EIO An I/O error occurred while reading from or writing to the file system. EISCONN The socket is already connected. ELOOP Too many symbolic links were encountered in translating the pathname in name. ENETUNREACH The network is not reachable from this host. EHOSTUNREACH The remote host is not reachable from this host. ENOENT A component of the path prefix of the pathname in name does not exist. ENOENT The socket referred to by the pathname in name does not exist. ENOSR There were insufficient STREAMS resources available to complete the operation. ENXIO The server exited before the connection was complete. ETIMEDOUT Connection establishment timed out without establishing a connection. EWOULDBLOCK The socket is marked as non-blocking, and the requested operation would block. The following errors are specific to connecting names in the UNIX domain. These errors might not apply in future versions of the UNIX IPC domain. ENOTDIR A component of the path prefix of the pathname in name is not a directory. ENOTSOCK s is not a socket. ENOTSOCK name is not a socket. EPROTOTYPE The file that is referred to by name is a socket of a type other than type s. For example, s is a SOCK_DGRAM socket, while name refers to a SOCK_STREAM socket. See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |Safe | +-----------------------------+-----------------------------+ close(2), accept(3SOCKET), getsockname(3SOCKET), select(3C), socket(3SOCKET), socket.h(3HEAD), attributes(5) 08 Mar 2005 connect(3SOCKET)