Sponsored Content
Full Discussion: write on Non Blocking Socket
Top Forums Programming write on Non Blocking Socket Post 302451179 by satish@123 on Monday 6th of September 2010 02:45:38 AM
Old 09-06-2010
write on Non Blocking Socket

How to know whether socket is ready for write.
Code:
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.
 

10 More Discussions You Might Find Interesting

1. Programming

read/write socket error

I have client and server connected. client write and read from csock. server write and read from ssock suppose the server does : .... close(ssock); //send FIN to client othertask(); .... READ ERROR if after the server close() the client does: ... read(csock,...); ...... (2 Replies)
Discussion started by: gio
2 Replies

2. Programming

How to Write Linux Friendly Async Socket I/O

I am presently refactoring a windows deamon with an eye towards porting it to linux someday. Presently the application uses a single background thread and asynchronous socket I/O to implement FTP and HTTP clients in a single switch statement (2000 lines and 100 cases just for the switch... (3 Replies)
Discussion started by: siegfried
3 Replies

3. IP Networking

Can we write a multiple thread to receive from a single socket file descriptor

Hi Friends, I have written a program which will listener for more than 1000 requests per second from a single socket descriptor and then it will process those requestes. Its taking X amount of time. Now i want to reduce that time. Will I can write multiple threads to receive the... (2 Replies)
Discussion started by: pa.chidhambaram
2 Replies

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

5. Programming

socket function to read a webpage (socket.h)

Why does this socket function only read the first 1440 chars of the stream. Why not the whole stream ? I checked it with gdm and valgrind and everything seems correct... #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <string.h> #include... (3 Replies)
Discussion started by: cyler
3 Replies

6. Programming

Write-Write on a socket

Can anyone tell what happens if each end writes at the same time on the same socket ? - if one of them issues a read() after write() has completed, will it record into the buffer what the other sent ? ex. e1 writes to e2 - - - while - - - e2 writes to e1 (at the same time) e1 read () - what... (1 Reply)
Discussion started by: gendaox
1 Replies

7. IP Networking

Clarification - Setting socket options at the same time when socket is listening

I need clarification on whether it is okay to set socket options on a listening socket simultaneously when it is being used in an accept() call? Following is the scenario:- -- Task 1 - is executing in a loop - polling a listen socket, lets call it 'fd', (whose file descriptor is global)... (2 Replies)
Discussion started by: jake24
2 Replies

8. Shell Programming and Scripting

Read and write to tcp socket

Hello all, I have a requirement to read and write to a tcp socket from an HP-UX shell script. I see a /dev/tcp character device on my servers: crw-rw-rw- 1 root root 72 0x00004f Mar 28 18:37 /dev/tcp So I believe this is what I should use. The problem is that all the... (2 Replies)
Discussion started by: lupin..the..3rd
2 Replies

9. Programming

Looping connect call for a non blocking socket

will there be any unexpected results on looping connect call for a non blocking socket to determine the connection based on error code. I am getting connection unsuccessful intermittently and so wondering whether is the timeout 500 millisec not sufficient or looping connect cause any unexpected. ... (7 Replies)
Discussion started by: satish@123
7 Replies

10. Programming

Which are blocking and non-blocking api's in sockets in C ?

among the below socket programming api's, please let me know which are blocking and non-blocking. socket accept bind listen write read close (2 Replies)
Discussion started by: VSSajjan
2 Replies
select(2)							System Calls Manual							 select(2)

NAME
select - Synchronous I/O multiplexing SYNOPSIS
#include <sys/time.h> int select( int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) ; void FD_CLR( int fd, fd_set *fdset); int FD_ISSET( int fd, fd_set *fdset); void FD_SET( int fd, fd_set *fdset); void FD_ZERO( fd_set *fdset); STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: select(): XSH5.0, XNS5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Specifies the number of open objects that may be ready for reading or writing or that have exceptions pending. The nfds parameter cannot be greater than FD_SETSIZE. Points to an I/O descriptor set consisting of file descriptors of objects opened for reading. When the readfds parameter is a null pointer, the read I/O descriptor set is ignored by the select() function. Points to an I/O descriptor set consisting of file descriptors for objects opened for writing. When the writefds parameter is a null pointer, the write I/O descriptor set is ignored. Points to an I/O descriptor set consisting of file descriptors for objects opened for reading or writing that have an exception pending. When the exceptfds parameter is a null pointer, the exception I/O descriptor set is ignored. Points to a type timeval structure that specifies the maximum time to wait for a response to a select() function. When the timeout parameter has a nonzero value, the maximum time interval to wait for the select() function to complete is specified by values stored in space reserved by the type timeval structure pointed to by the timeout parameter. When the timeout parameter is a null pointer, the select() function blocks indefinitely. To poll, the timeout parameter should be specified as a nonzero value and point to a zero-valued timeval structure. The use of a timeout does not affect any pending timers set up by alarm(, ualarm(, or settimer(. Specifies a file descriptor. Points to an I/O descriptor set. DESCRIPTION
The select() function checks the status of objects identified by bit masks called I/O descriptor sets. Each I/O descriptor set consists of an array of bits whose relative position and state represent a file descriptor and the status of its corresponding object. There is an I/O descriptor set for reading, writing, and for pending exceptions. These I/O descriptor sets are pointed to by the readfds, writefds, and exceptfds parameters, respectively. The I/O descriptor sets provide a means of monitoring the read, write, and exception status of objects represented by file descriptors. The status of nfds-1 file descriptors in each referenced I/O descriptor set is checked when the select() function is called. The select() function returns a modified I/O descriptor set, which has the following characteristics: for any selected I/O descriptor set pointed to by the readfds, writefds, and exceptfds parameters, if the state of any bit corresponding with an active file descriptor is set on entry, when the object represented by the set bit is ready for reading, writing, or its exception condition has been satisfied, a corresponding bit position is also set in the returned I/O descriptor set pointed to by the readfds, writefds, or exceptfds parameters. When it returns successfully, select() does the following: First, it replaces the original I/O descriptor sets with the corresponding I/O descriptor sets (that have a set bit for each file descriptor representing those objects that are ready for the requested operation). Sec- ond, it returns the total number of ready objects represented by set bits in all the I/O descriptor sets. Note: When objects are ready for the requested operation, the operation will not block. This does not necessarily mean, however, that data is available for the operation. See read(2) and write(2) for information on when these calls would block. After an I/O descriptor set is created, it may be modified with the following macros: Clears the I/O descriptor bit specified by file descriptor fd in the I/O descriptor set addressed by fdset. Returns a nonzero value when the I/O descriptor bit for fd is included in the I/O descriptor set addressed by fdset. Otherwise 0 (zero) is returned. Includes the particular I/O descriptor bit specified by fd in the I/O descriptor set addressed by fdset. Initializes the I/O descriptor set addressed by fdset to a null value. The behavior of these macros is undefined when parameter fd has a value less than 0 (zero) or greater than or equal to FD_SETSIZE, which is normally at least equal to the maximum number of file descriptors supported by the system. The select( function supports regular files, terminal and pseudo-terminal devices, STREAMS-based files, FIFOs, and pipes. The behavior of the select( function on file descriptors that refer to other types of files is unspecified. For sockets, a file descriptor for a socket that is listening for connections indicates that it is ready for reading when connections are available. A file descriptor for a socket that is connecting asynchronously indicates that it is ready for writing after a connection is established. NOTES
This function supports up to 64K open file descriptors per process if that capability is enabled. If not already defined, FD_SETSIZE is set in the <sys/select.h> header file to be 4K. New applications can use any of these features for processes using more than 4K open file descriptors. When they do so, however, they must specify an alternate value for FD_SETSIZE--one that does not exceed 64K--before they include <sys/select.h> in a program to be compiled. RETURN VALUES
Upon successful completion, the select() function returns the number of ready objects represented by corresponding file descriptor bits in the I/O descriptor sets. When an error occurs, -1 is returned and errno is set to indicate the error. If the time limit expires before any event occurs that would cause one of the masks to be set to a non-zero value, select() completes suc- cessfully and returns 0 (zero). When select() returns an error, including a process interrupt, the I/O descriptor sets pointed to by the readfds, writefds, and exceptfds parameters remain unmodified. ERRORS
The select() function sets errno to the specified values for the following conditions: One or more of the I/O descriptor sets specified an invalid file descriptor. A signal was delivered before the time limit specified by the timeout parameter expired and before any of the selected events occurred. The time limit specified by the timeout parameter is invalid. The nfds parameter is less than 0, or greater than or equal to FD_SETSIZE. One of the specified file descriptors refers to a STREAM or multiplexer that is linked (directly or indirectly) downstream from a multiplexer. [Tru64 UNIX] Allocation of internal data structures failed. A later call to the select() function may complete suc- cessfully. RELATED INFORMATION
Functions: accept(2), connect(2), getdtablesize(2), poll(2) read(2), recv(2), send(2), setsysinfo(2), write(2) Standards: standards(5) delim off select(2)
All times are GMT -4. The time now is 12:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy