Sponsored Content
Top Forums Programming Looping connect call for a non blocking socket Post 302705101 by satish@123 on Monday 24th of September 2012 08:41:01 AM
Old 09-24-2012
So connect, select and again connect based on the return codes and errno indications achieve smooth non blocking connection but I am still thinking of looping connect call and I verified the truss to see the return code of connect when I loop -

First remote connect said - EINPROGRESS as expected.
Next try indicated - EISCONN. Indicating already connected.
Even if not then would have indicated EALREADY. Having 100 milli secods each time before trying to connect, there should not be any issue except that the last retry may indicate connect = 0 and will not update errno (The only chance of failure in the loop after 400 milli seconds, mostly in bad network cases). Other case If connect returned 0 will not update errno but the next try to same connected socket would indicate error - EISCONN, correct?

connect(4, 0x080453E0, 16, SOV_DEFAULT) Err#150 EINPROGRESS
pollsys(0x00000000, 0, 0x08045330, 0x00000000) = 0
connect(4, 0x080453E0, 16, SOV_DEFAULT) Err#133 EISCONN
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
CONNECT(2)						      BSD System Calls Manual							CONNECT(2)

NAME
connect -- initiate a connection on a socket SYNOPSIS
#include <sys/types.h> #include <sys/socket.h> int connect(int socket, const struct sockaddr *address, socklen_t address_len); DESCRIPTION
The parameter socket is a socket. If it is of type SOCK_DGRAM, this call specifies the peer with which the socket is to be associated; this address is that to which datagrams are to be sent, and the only address from which datagrams are to be received. If the socket is of type SOCK_STREAM, this call attempts to make a connection to another socket. The other socket is specified by address, which is an address in the communications space of the socket. Each communications space interprets the address parameter in its own way. Generally, stream sockets may successfully connect() only once; datagram sockets may use connect() multiple times to change their association. Datagram sockets may dissolve the association by connecting to an invalid address, such as a null address or an address with the address family set to AF_UNSPEC (the error EAFNOSUPPORT will be harm- lessly returned). RETURN VALUES
Upon successful completion, a value of 0 is returned. Otherwise, a value of -1 is returned and the global integer variable errno is set to indicate the error. ERRORS
The connect() system call will fail if: [EACCES] The destination address is a broadcast address and the socket option SO_BROADCAST is not set. [EADDRINUSE] The address is already in use. [EADDRNOTAVAIL] The specified address is not available on this 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] socket is not a valid descriptor. [ECONNREFUSED] The attempt to connect was ignored (because the target is not listening for connections) or explicitly rejected. [EFAULT] The address parameter specifies an area outside the process address space. [EHOSTUNREACH] The target host cannot be reached (e.g., down, disconnected). [EINPROGRESS] The socket is non-blocking and the connection cannot be completed immediately. It is possible to select(2) for completion by selecting the socket for writing. [EINTR] Its execution was interrupted by a signal. [EINVAL] An invalid argument was detected (e.g., address_len is not valid for the address family, the specified address family is invalid). [EISCONN] The socket is already connected. [ENETDOWN] The local network interface is not functioning. [ENETUNREACH] The network isn't reachable from this host. [ENOBUFS] The system call was unable to allocate a needed memory buffer. [ENOTSOCK] socket is not a file descriptor for a socket. [EOPNOTSUPP] Because socket is listening, no connection is allowed. [EPROTOTYPE] address has a different type than the socket that is bound to the specified peer address. [ETIMEDOUT] Connection establishment timed out without establishing a connection. [ECONNRESET] Remote host reset the connection request. The following errors are specific to connecting names in the UNIX domain. These errors may not apply in future versions of the UNIX IPC domain. [EACCES] Search permission is denied for a component of the path prefix. [EACCES] Write access to the named socket is denied. [EIO] An I/O error occurred while reading from or writing to the file system. [ELOOP] Too many symbolic links were encountered in translating the pathname. This is taken to be indicative of a looping sym- bolic link. [ENAMETOOLONG] A component of a pathname exceeded {NAME_MAX} characters, or an entire path name exceeded {PATH_MAX} characters. [ENOENT] The named socket does not exist. [ENOTDIR] A component of the path prefix is not a directory. LEGACY SYNOPSIS
#include <sys/types.h> #include <sys/socket.h> The include file <sys/types.h> is necessary. SEE ALSO
accept(2), getsockname(2), select(2), socket(2), compat(5) HISTORY
The connect() function call appeared in 4.2BSD. 4.2 Berkeley Distribution June 4, 1993 4.2 Berkeley Distribution
All times are GMT -4. The time now is 10:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy