Logo Search packages:      
Sourcecode: dbus version File versions

int _dbus_write_two ( int  fd,
const DBusString buffer1,
int  start1,
int  len1,
const DBusString buffer2,
int  start2,
int  len2 

Like _dbus_write() but will use writev() if possible to write both buffers in sequence. The return value is the number of bytes written in the first buffer, plus the number written in the second. If the first buffer is written successfully and an error occurs writing the second, the number of bytes in the first is returned (i.e. the error is ignored), on systems that don't have writev. Handles EINTR for you. The second buffer may be NULL.

fd the file descriptor
buffer1 first buffer
start1 first byte to write in first buffer
len1 number of bytes to write from first buffer
buffer2 second buffer, or NULL
start2 first byte to write in second buffer
len2 number of bytes to write in second buffer
total bytes written from both buffers, or -1 on error

Definition at line 295 of file dbus-sysdeps.c.

References _dbus_assert, _dbus_string_get_const_data_len(), _dbus_write(), and NULL.

  _dbus_assert (buffer1 != NULL);
  _dbus_assert (start1 >= 0);
  _dbus_assert (start2 >= 0);
  _dbus_assert (len1 >= 0);
  _dbus_assert (len2 >= 0);
    struct iovec vectors[2];
    const char *data1;
    const char *data2;
    int bytes_written;

    data1 = _dbus_string_get_const_data_len (buffer1, start1, len1);

    if (buffer2 != NULL)
      data2 = _dbus_string_get_const_data_len (buffer2, start2, len2);
        data2 = NULL;
        start2 = 0;
        len2 = 0;
    vectors[0].iov_base = (char*) data1;
    vectors[0].iov_len = len1;
    vectors[1].iov_base = (char*) data2;
    vectors[1].iov_len = len2;

    bytes_written = writev (fd,
                            data2 ? 2 : 1);

    if (bytes_written < 0 && errno == EINTR)
      goto again;
    return bytes_written;
#else /* HAVE_WRITEV */
    int ret1;
    ret1 = _dbus_write (fd, buffer1, start1, len1);
    if (ret1 == len1 && buffer2 != NULL)
        ret2 = _dbus_write (fd, buffer2, start2, len2);
        if (ret2 < 0)
          ret2 = 0; /* we can't report an error as the first write was OK */
        return ret1 + ret2;
      return ret1;
#endif /* !HAVE_WRITEV */   

Generated by  Doxygen 1.6.0   Back to index