Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Partial Write for sockets in LINUX Post 302521899 by Loic Domaigne on Thursday 12th of May 2011 04:20:36 PM
Old 05-12-2011
Quote:
Also these sockets are in Non Blocking mode (O_NONBLOCK)
Any reason for not using standard blocking mode?

Quote:
Consider the server tried to write 2464 bytes. But after the repeated 30 attempts it could write only 1080 bytes. Server will raise a EAGAIN at this point. Client try to read 2464 bytes. The read command will return 2464 and hence the read itself is ok. But the data we received is a corrupted one (Partially written data only). So client crashes.
I can't quite follow. If only 1080 has been sent, I don't think that read() returns 2464 bytes...

Quote:
2) Is there any way to identify in client side that we had read a partially written message?.
You need to handle partial read anyway with TCP, since you don't know how your message will be segmented. The usual design pattern goes along those lines:
- a message is composed of a header and payload section,
- the header contains (among other) the payload size,
- the receiver read() first the header (a few bytes), decodes the expected payload length. To get the payload, it re-iterates read() until the wanted size is reached or an error occurs.

Quote:
Please note that we are facing the partial write issue in LINUX(REDHAT 5.4) only. System is working fine in Solaris (In solaris either eh entire data will be written OR NO data witll be written with in 30 tries of write).
Perhaps tune kernel parameters TCP send/recv queue length ?

HTH, Loïc
This User Gave Thanks to Loic Domaigne For This Post:
 

9 More Discussions You Might Find Interesting

1. Programming

Linux BSD sockets blocking issue

I am using BSD TCP sockets under Debian Linux 2.6 and no matter what I do, the socket blocks on recv. I have set O_NONBLOCK and O_NDELAY using fcntl to no effect. Any ideas ? (3 Replies)
Discussion started by: johnmb
3 Replies

2. IP Networking

read/write,write/write lock with smbclient fails

Hi, We have smb client running on two of the linux boxes and smb server on another linux system. During a backup operation which uses smb, read of a file was allowed while write to the same file was going on.Also simultaneous writes to the same file were allowed.Following are the settings in the... (1 Reply)
Discussion started by: swatidas11
1 Replies

3. Programming

c++, raw sockets, stopping kernel write in header?

Hi, im trying to lern about raw sockets with my debian and c++. Tried to make a icmp and tcp packet and send it with sendto. Checked on wireshark and recognized that kernel changed my headers. So searched about stopping the kernel change the header and tried it with setsockopt, like said in at this... (4 Replies)
Discussion started by: sandcastle
4 Replies

4. Shell Programming and Scripting

AWK - Print partial line/partial field

Hello, this is probably a simple request but I've been toying with it for a while. I have a large list of devices and commands that were run with a script, now I have lines such as: a-router-hostname-C#show ver I want to print everything up to (and excluding) the # and everything after it... (3 Replies)
Discussion started by: ippy98
3 Replies

5. Shell Programming and Scripting

How to bulk changing partial file name in Linux?

I have a bunch of database files in a directory. Their name are like: 1234_ABCD_01.dbf, 28hrs_ABCD_02.dbf I want to change them in bulk to: 1234_XXXU_01.dbf, 28hrs_XXXU_02.dbf. I mean I just want to replace ABCD by XXXU. don't change other part of the file name and the contents of the... (4 Replies)
Discussion started by: duke0001
4 Replies

6. Programming

Sockets (C under Linux)

Hi, I have to write an UDP broadcast. It works so far, but how can I get the actual network address at runtime? Should run under Linux and Unix (Solaris). Thanks (1 Reply)
Discussion started by: peng1967
1 Replies

7. Programming

help: problem with sockets write/read

I am trying to make a server and client, the client will choose between some options and the server will react accordingly. After a some reads and writes that work the server needs to read from client an INT i use this: read(newSd,&k,sizeof(int));But even if all the other times there was no... (1 Reply)
Discussion started by: theSling
1 Replies

8. Cybersecurity

root cannot write to Linux RAM

void main() { long ((long)(&array)); int x; for (;;) { (array) =+ 1023; printf("%c", array); } } What is wrong with this code to print Linux RAM? (13 Replies)
Discussion started by: Alux
13 Replies

9. Red Hat

SE Linux write permission denied

Hi, In my server I am getting below errors in "/var/log/messages": Oct 8 14:45:44 LKOGOMEEMM01 kernel: type=1400 audit(1444295744.792:15818): avc: denied { write } for pid=53421 comm="ip" path="/var/VRTSvcs/log/tmp/IPMultiNIC-8" dev=dm-0 ino=2754879 scontext=system_u:system_r:ifconfig_t:s0... (4 Replies)
Discussion started by: rochitsharma
4 Replies
tcp(4p) 																   tcp(4p)

Name
       tcp - Internet Transmission Control Protocol

Syntax
       #include <sys/socket.h>
       #include <netinet/in.h>

       s = socket(AF_INET, SOCK_STREAM, 0);

Description
       The  TCP  protocol  provides  reliable,	flow-controlled,  two-way  transmission of data.  It is a byte-stream protocol used to support the
       SOCK_STREAM abstraction.  TCP uses the standard Internet address format	and,  in  addition,  provides  a  per-host  collection	of  ``port
       addresses''.   Thus,  each address is composed of an Internet address specifying the host and network, with a specific TCP port on the host
       identifying the peer entity.

       Sockets utilizing the TCP protocol are either ``active'' or ``passive''.  Active sockets  initiate  connections	to  passive  sockets.	By
       default	TCP  sockets  are created active; to create a passive socket the system call must be used after binding the socket with the system
       call.  Only passive sockets can use the call to accept incoming connections.  Only active sockets can use the call to initiate connections.

       Passive sockets can ``underspecify'' their location to match incoming connection requests from multiple networks.  This	technique,  termed
       ``wildcard addressing'', allows a single server to provide service to clients on multiple networks.  To create a socket that listens on all
       networks, the Internet address INADDR_ANY must be bound.  The TCP port can still be specified at this time.  If the port is not	specified,
       the  system  will  assign one.  Once a connection has been established,	the socket's address is fixed by the peer entity's location.   The
       address assigned the socket is the address associated with the network interface through which packets are being transmitted and  received.
       Normally, this address corresponds to the peer entity's network.

       TCP  supports  one  socket option that is set with and tested with Under most circumstances, TCP sends data when it is presented; when out-
       standing data has not yet been acknowledged, it gathers small amounts of output to be sent in a single packet, once an  acknowledgement	is
       received.   For a small number of clients, such as window systems that send a stream of mouse events that receive no replies, this packeti-
       zation may cause significant delays.  Therefore, TCP provides a Boolean option, TCP_NODELAY (from to defeat  this  algorithm.   The  option
       level for the call is the protocol number for TCP, available from

Diagnostics
       A socket operation may fail with one of the following errors returned:

       [EISCONN]	   Try to establish a connection on a socket which already has one.

       [ENOBUFS]	   The system runs out of memory for an internal data structure.

       [ETIMEDOUT]	   A connection was dropped due to excessive retransmissions.

       [ECONNRESET]	   The remote peer forces the connection to be closed.

       [ECONNREFUSED]	   The remote peer actively refuses connection establishment (usually because no process is listening to the port).

       [EADDRINUSE]	   An attempt is made to create a socket with a port that has already been allocated.

       [EADDRNOTAVAIL]	   An attempt is made to create a socket with a network address for which no network interface exists.

See Also
       getsockopt(2), socket(2), inet(4f), intro(4n), ip(4p)

																	   tcp(4p)
All times are GMT -4. The time now is 03:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy