473,326 Members | 2,090 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,326 software developers and data experts.

writev() on a SOCK_STREAM socket

Hi,

Do I need to retry writev() on a blocking Unix-domain SOCK_STREAM socket,
or will it always write out the exact number of bytes I asked for?

For example:

if (write(fd, (const char *) presp, resp_size) != resp_size)
{
warn("Writing %lu bytes failed\n", resp_size);
return;
}

this seems to work, but I want to know if it's "really OK" in terms of
ANSI Standards etc.

Jun 27 '08 #1
7 3882
kid joe wrote:
Hi,

Do I need to retry writev() on a blocking Unix-domain SOCK_STREAM socket,
or will it always write out the exact number of bytes I asked for?

For example:

if (write(fd, (const char *) presp, resp_size) != resp_size)
{
warn("Writing %lu bytes failed\n", resp_size);
return;
}

this seems to work, but I want to know if it's "really OK" in terms of
ANSI Standards etc.
The ANSI C standards have nothing to do with
write(), writev(), Unix, and sockets.

--
pete
Jun 27 '08 #2
kid joe <sp******@spamtrap.invalidwrote:
Do I need to retry writev() on a blocking Unix-domain SOCK_STREAM socket,
or will it always write out the exact number of bytes I asked for?
For example:
if (write(fd, (const char *) presp, resp_size) != resp_size)
{
warn("Writing %lu bytes failed\n", resp_size);
return;
}
this seems to work, but I want to know if it's "really OK" in terms of
ANSI Standards etc.
The C standard won't tell you anything about this problem since
there's not even a write() function (or an open() function to
start with;-) defined there. But even if you ask in e.g. the
comp.unix.programmmer group you will have to tell how exactly
you did open the file (descriptor). If you e.g. did open it in
non-blocking mode then for sure write() may return before even
a single byte was written. Results may also depend on signals
being blocked etc. - the POSIX standard is what you need to refer
to in this case.
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
Jun 27 '08 #3
pete wrote, On 20/06/08 00:01:
kid joe wrote:
>Do I need to retry writev() on a blocking Unix-domain SOCK_STREAM socket,
or will it always write out the exact number of bytes I asked for?
<snip>
>this seems to work, but I want to know if it's "really OK" in terms of
ANSI Standards etc.

The ANSI C standards have nothing to do with
write(), writev(), Unix, and sockets.
As this appears to be about Uni like systems comp.unix.programmer would
be a good place to ask. I suspect the answer is "no" but I could easily
be wrong.
--
Flash Gordon
Jun 27 '08 #4
On Jun 20, 3:50 am, kid joe <spamt...@spamtrap.invalidwrote:
Hi,

Do I need to retry writev() on a blocking Unix-domain SOCK_STREAM socket,
or will it always write out the exact number of bytes I asked for?

For example:

if (write(fd, (const char *) presp, resp_size) != resp_size)
{
warn("Writing %lu bytes failed\n", resp_size);
return;
}

this seems to work, but I want to know if it's "really OK" in terms of
ANSI Standards etc.
This topic is not about ANSI but POSIX standards.
<off-topic>
You asked about writev and you are using write. Nevertheless, the same
errors are defined for both. write can fail in various cases: EPIPE(if
pipe is broken), EINT(if interrupted by a signal) and EAGAIN ( if fd
opened as O_NONBLOCK and the call would block). There are a few more
error scenarios which the man pages document. Its always a good idea
to consult the man pages(or any equivalent documentation).
</off-topic>
Jun 27 '08 #5
rahul wrote:
>
.... snip ...
>
This topic is not about ANSI but POSIX standards.
<off-topic>
You asked about writev and you are using write. Nevertheless, the
same errors are defined for both. write can fail in various cases:
EPIPE (if pipe is broken), EINT (if interrupted by a signal) and
EAGAIN ( if fd opened as O_NONBLOCK and the call would block).
There are a few more error scenarios which the man pages document.
Its always a good idea to consult the man pages(or any equivalent
documentation). </off-topic>
Most here prefer that you only refer the enquirer to a suitable
newsgroup, rather than attempt to answer off-topic questions. The
reason is that the people to criticize your answer just don't exist
here, so faulty answers won't get exposed. And we all make
mistakes.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
** Posted from http://www.teranews.com **
Jun 27 '08 #6
On 20 Jun 2008 at 7:19, CBFalconer wrote:
rahul wrote:
>write can fail in various cases:
[snip good answer]
>There are a few more error scenarios which the man pages document.
Its always a good idea to consult the man pages(or any equivalent
documentation).

Most here prefer that you only refer the enquirer to a suitable
newsgroup, rather than attempt to answer off-topic questions.
s/Most/A vocal minority/
The reason is that the people to criticize your answer just don't
exist here, so faulty answers won't get exposed.
This is materially false: the intersection between posters to clc and
posters to cup is large, and might well be larger still if it wasn't for
the topicality zealots stifling POSIX discussions here.

In any case, the answer is a precis of formal documentation (the write
manpage), so it's very unlikely to be "faulty".
And we all make mistakes.
Yes - some more than others.

Jun 27 '08 #7
On Jun 20, 10:19 am, CBFalconer <cbfalco...@yahoo.comwrote:
rahul wrote:

... snip ...
This topic is not about ANSI but POSIX standards.
<off-topic>
You asked about writev and you are using write. Nevertheless, the
same errors are defined for both. write can fail in various cases:
EPIPE (if pipe is broken), EINT (if interrupted by a signal) and
EAGAIN ( if fd opened as O_NONBLOCK and the call would block).
There are a few more error scenarios which the man pages document.
Its always a good idea to consult the man pages(or any equivalent
documentation). </off-topic>

Most here prefer that you only refer the enquirer to a suitable
newsgroup, rather than attempt to answer off-topic questions. The
reason is that the people to criticize your answer just don't exist
here, so faulty answers won't get exposed. And we all make
mistakes.
Agreed. I posted a follow-up to comp.unix.programmer only, advicing
rahul that, along with correcting his reply (and answering OP).
I hope the discussion continues there...
Jun 27 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Adam DePrince | last post by:
Often I've written code that generates some textual output and dumps said output to a file or socket. Of course, we are all familiar with the performance impact (multiple copies of text data and...
4
by: DreJoh | last post by:
I've read many articles on the subject and the majority of them give the same solution that's in article 821625 on the MSDN website. I'm using the following code and when a the client disconnects...
1
by: Rolln_Thndr | last post by:
I'm vey new to network programing and have a few rather fundemental questions. I'm creating a very basic UDP proxy server and having a few issues regarding the sockets. Is it possible to change...
2
by: Ali Hamad | last post by:
Hello All : A socket question from a networking newbie. I need to create a server that: 1) receive a message from client. 2) check that message and response to it. 3) the client get the...
1
by: john2357 | last post by:
I can not use the LWP module, and must use IO::Socket. Using 'Wireshark' and Mozilla and passing in the parameters below I get a valid reply. However Wireshark shows HTTP needs to be 1.1 and that the...
2
Xx r3negade
by: Xx r3negade | last post by:
I am having trouble using connect() when entering struct addrinfo members as parameters. int tcpConnect() { struct addrinfo hints; struct addrinfo *ai = NULL; int res; int...
3
by: oberon | last post by:
Hi, I hope it's ok for me to place an IronPython question in this forum(?). I am running IronPython 1.1.2 and Python 2.5. OS is Windows XP SP3. Currently I'm developing a lightweight test...
5
by: AmeL | last post by:
Hi all. I have a socket. I want to create two threads, one is to read from socket, and another is to write to socket. However, I want these two threads to be able to share the same data, so I...
1
by: shailesh333 | last post by:
I have written a small piece of code in 'c' for a simple server However when I call the socket function , it returns the value -1. What could be the problem?? Any help will be appreciated......
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.