473,411 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

How do you flush a socket in C?

1
Hey there!

Currently I'm working on a project that handles alot of sockets (this application is *NIX).

At the moment, I got this code:
char *failed = "Some info about the error, bla\r\nbla bla (aprx. 181 chars long)\r\n";
send(fd, failed, strlen(failed), 0);
fflush(fd);
if(close(fd) != 0)
addlog("Error closing socket [%d]: %s", errno, strerror(errno));

fd is a INT.

The error I get is:
[connections.c:237] (Thread 0) **READ_WILD**
>> fflush(fd);

Reading wild pointer: <argument 1>

Pointer: 0x00000009

Stack trace where the error occurred:
fflush() (interface)
new_connection() src/connections.c, 237

Which causes a SEGFAULT (but the client gets the error msg \o/).

Best regards,
Anton.
Oct 22 '07 #1
1 16766
RRick
463 Expert 256MB
The problem is that you are treating an unix integer file descriptor (ufd) as a C style FILE pointer. As you found out, this doesn't work.

One option is to turn the ufd into a FILE handle (i.e. use fdopen) and then use the C style functions(fflush, fprint, etc). If you do this, then stay with the C routines exclusively. See following for more info:http://www.uwo.ca/its/doc/courses/notes/socket/.

If you want to stay with the unix fds, then you need to use the ioctl function. Do a "man ioctl" on your system for more info. This will tell what parameters and system include files are needed.
Oct 22 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: JnlSeb | last post by:
According to Sun's web site, the flush method of the OutputStream object does nothing. So, what does actually happens when you call it? At times I may see different behavior when including it...
7
by: Jon Spivey | last post by:
Experimenting with response.flush() but can't seem to get it to work. This code <% response.write "<p>started</p>" response.flush() for i = 1 to 10000000 i = i +1 next response.write...
0
by: ruhunu Gamarala | last post by:
Hi, I get the following exception periodically. does anybody what is the reason for it to throw this exception? I really appriciate if anyone can help me on this. thanks, Chinthaka at...
5
by: Simon Johnson | last post by:
I have a TCP Client class for which I use StreamWriter to send data across the network. The question I have is does the StreamWriter.Flush() method block code execution until all the data has been...
3
by: Nuno Magalhaes | last post by:
How to do a TCP socket flush in order to get the packets to their real sizes (and not accumulate) like when we send a datagram UDP. When we send UDP it comes with the real packet size, in other...
2
by: Kiran | last post by:
Hello Everybody! I am writing a networking application in python for a small piece of hardware, in which there could sometimes be timeouts. I am using sockets to communicate to this device. Data...
6
by: ppuniversal | last post by:
Can anyone tell me how to flush a socket stream in C++. I am making an Client Server application in C++ and use the send() and recv() functions. i want to flush the socket buffer as i am getting...
0
by: mike | last post by:
I have called the setsockopt() to set no delay after connecting like this way: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('192.168.10.1', 21980))...
3
by: iceman | last post by:
Hi all, HOw can I flush the socket. eg how can I ensure that the send takes place immediately if (send(socketDescriptor, buf, strlen(buf) + 1, 0) < 0) { int km=socketDescriptor.flush();...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.