Commit eaf0b478 authored by Niels Möller's avatar Niels Möller
Browse files

Use write_raw() and write_Raw_with_poll().

Rev: src/blocking_write.c:1.9
Rev: src/blocking_write.h:1.6
parent 9bbc0cab
......@@ -4,61 +4,38 @@
#include "blocking_write.h"
#include "io.h"
#include "xalloc.h"
#include "werror.h"
#include <string.h>
/* CLASS:
(class
(name blocking_write)
(super abstract_write)
(vars
(fd . int)
(write . (pointer (function int int UINT32 "UINT8 *")))))
*/
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <errno.h>
#define CLASS_DEFINE
#include "blocking_write.h.x"
#undef CLASS_DEFINE
#include "blocking_write.c.x"
static int do_blocking_write(struct abstract_write *w,
struct lsh_string *packet)
{
CAST(blocking_write, closure, w);
UINT32 left = packet->length;
UINT8 *p = packet->data;
while(left)
{
int written = write(closure->fd, p, left);
if ( (written < 0)
&& (errno == EINTR) )
continue;
if (written <= 0)
{
werror("blocking_write: writ failed (errno = %d): %s\n",
errno, strerror(errno));
return LSH_FAIL;
}
left -= written;
p += written;
}
int success = closure->write(closure->fd, packet->length, packet->data);
lsh_string_free(packet);
return LSH_OK;
return success ? LSH_OK : LSH_FAIL | LSH_DIE;
}
struct abstract_write *make_blocking_write(int fd)
struct abstract_write *make_blocking_write(int fd, int with_nonblocking)
{
NEW(blocking_write, closure);
closure->super.write = do_blocking_write;
closure->write = (with_nonblocking ? write_raw_with_poll : write_raw);
closure->fd = fd;
return &closure->super;
}
......@@ -7,18 +7,6 @@
#include "abstract_io.h"
#define CLASS_DECLARE
#include "blocking_write.h.x"
#undef CLASS_DECLARE
/* CLASS:
(class
(name blocking_write)
(super abstract_write)
(vars
(fd . int)))
*/
struct abstract_write *make_blocking_write(int fd);
struct abstract_write *make_blocking_write(int fd, int with_nonblocking);
#endif /* LSH_BLOCKING_WRITE_H_INCLUDED */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment