Sponsored Content
Top Forums Programming TCP trashing data on application close Post 302455790 by metrix on Wednesday 22nd of September 2010 12:02:59 PM
Old 09-22-2010
MySQL TCP trashing data on application close

I am using c to send data to a socket with the following commands:

Code:
socket = socket(AF_INET, SOCK_STREAM, ptrp->p_proto);
ioctl(socket, FIONBIO, (char *)&on);
connect(socket)
send(socket,data)
shutdown(socket, SHUT_WR);
recv(socket) //ready last of data waiting on the port

//note this is the same port and address as the connection above
socket = socket(AF_INET, SOCK_STREAM, ptrp->p_proto);
ioctl(socket, FIONBIO, (char *)&on);
connect(socket)
send(socket,data)
shutdown(socket, SHUT_WR);
recv(socket) //read last of data waiting on the port

The other end of the connection takes approximately half a second to process all of this information, but my application finishes immediately.

The problem is that some of the data at the end of the first send is truncated though all of the data from the second send statement makes it to the other end, but if I add a 1 second sleep to the end of my application all of the data makes it successfully.

Why is this happening?
Brandon
 

10 More Discussions You Might Find Interesting

1. IP Networking

secondary TCP application

:cool: I want to use 2 tcp applications in SCO 5.05 senerio I am using VisionFS 3.1 and I need to set it up as a secondary tcp app. I follow the profeditoir and change the tcp port from the primary port (139) to any other number below port 1024 and then restart the VisionFS server it is still... (2 Replies)
Discussion started by: lanman
2 Replies

2. UNIX for Dummies Questions & Answers

Which application has a TCP socket open

If I do a netstat -a I can see all the sockets currently open, is there a way that I can tell which application is holding open these sockets ? (3 Replies)
Discussion started by: murphyboy
3 Replies

3. UNIX for Dummies Questions & Answers

close tcp port

Hello, I have a service running (ODBC) and every now and then it will hang and I will have to stop and restart the service. The problem is when I stop the service, it indeed stops the service, but netstat reports a tcp port still open with the fin_wait_2 status. Then I must close the client... (1 Reply)
Discussion started by: raidzero
1 Replies

4. Programming

problem receiving data from TCP socket

Hi all, I'm writing a socket program which sends a structure from one machine to another. When I run my client first time it runs well, however after the first time I couldn't receive all the data inside the structure (it is like, half of the array is received and the other half is not set). I... (1 Reply)
Discussion started by: SaTYR
1 Replies

5. Programming

close existing tcp connection in C

Hello. I would like to know how to close an existing tcp socket. I have read some stuff and learned how to create a socket and then close it but have not found anything about how to close an existing tcp socket created by another application. The situation is this: I have an ODBC server running and... (6 Replies)
Discussion started by: raidzero
6 Replies

6. Solaris

many tcp connection in close-wait

Hi, I use solaris Unix . I find there is some problem in application and it generate many "close-wait" tcp connect and stay in the server . it is generate by process id 7740 root@XX # netstat -an | grep CLOSE_WAIT | wc -l 285 root@XX # netstat -an | grep CLOSE_WAIT 10.158.35.4.34805 ... (2 Replies)
Discussion started by: abcdef
2 Replies

7. Programming

when parent process close, how to close the child?

can someone provide an example, where if the parent process quits for any reason, then the child process will also close? (3 Replies)
Discussion started by: omega666
3 Replies

8. IP Networking

Packetize data to send it over tcp sockets

Hello All, I am very new to socket programming and client server architecture. I have to write a client which will send some data to server and server will display it on its console. I am ready with both client and server but my problem is with packetizing of data -- I have... (1 Reply)
Discussion started by: anand.shah
1 Replies

9. Shell Programming and Scripting

Want to backup dirs on application start and close.

Hi I want to write a script that will back up one directory if a certain application launches and then backs up another directory if that same application is closed down. NFI where to start. It seems like cron isn't the tool for this because that is time based. I'm thinking I need... (6 Replies)
Discussion started by: zorrokan
6 Replies

10. UNIX for Advanced & Expert Users

30 tcp connections Established for a while and after a few minutes are close

Good morning, I need your help please After Restarting Aps or connection, these are connections tcp 0 0 10.80.1.26.57597 10.81.248.79.53008 ESTABLISHED tcp 0 47 10.80.1.26.57607 10.81.248.79.53008 ESTABLISHED tcp 0 0 ... (4 Replies)
Discussion started by: alexcol
4 Replies
listen(3SOCKET) 					     Sockets Library Functions						   listen(3SOCKET)

NAME
listen - listen for connections on a socket SYNOPSIS
cc [ flag ... ] file ... -lsocket -lnsl [ library ... ] #include <sys/types.h> #include <sys/socket.h> int listen(int s, int backlog); DESCRIPTION
To accept connections, a socket is first created with socket(3SOCKET), a backlog for incoming connections is specified with listen() and then the connections are accepted with accept(3SOCKET). The listen() call applies only to sockets of type SOCK_STREAM or SOCK_SEQPACKET. The backlog parameter defines the maximum length the queue of pending connections may grow to. If a connection request arrives with the queue full, the client will receive an error with an indication of ECONNREFUSED for AF_UNIX sock- ets. If the underlying protocol supports retransmission, the connection request may be ignored so that retries may succeed. For AF_INET and AF_INET6sockets, the TCP will retry the connection. If the backlog is not cleared by the time the tcp times out, the connect will fail with ETIMEDOUT. RETURN VALUES
A 0 return value indicates success; -1 indicates an error. ERRORS
The call fails if: EBADF The argument s is not a valid file descriptor. ENOTSOCK The argument s is not a socket. EOPNOTSUPP The socket is not of a type that supports the operation listen(). ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |Safe | +-----------------------------+-----------------------------+ SEE ALSO
accept(3SOCKET), connect(3SOCKET), socket(3SOCKET), attributes(5), socket.h(3HEAD) NOTES
There is currently no backlog limit. SunOS 5.11 8 Nov 1999 listen(3SOCKET)
All times are GMT -4. The time now is 04:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy