1. 12 6月, 2012 3 次提交
    • M
      rewrite iov_send_recv() and move it to iov.c · 25e5e4c7
      Michael Tokarev 提交于
      Make it much more understandable, add a missing
      iov_cnt argument (number of iovs in the iov), and
      add comments to it.
      
      The new implementation has been extensively tested
      by splitting a large buffer into many small
      randomly-sized chunks, sending it over socket to
      another, slow process and verifying the receiving
      data is the same.
      
      Also add a unit test for iov_send_recv(), sending/
      receiving data between two processes over a socketpair
      using random vectors and random sizes.
      Signed-off-by: NMichael Tokarev <mjt@tls.msk.ru>
      25e5e4c7
    • M
      export iov_send_recv() and use it in iov_send() and iov_recv() · e3e87df4
      Michael Tokarev 提交于
      Rename do_sendv_recvv() to iov_send_recv(), change its last arg
      (do_send) from int to bool, export it in iov.h, and made the two
      callers of it (iov_send() and iov_recv()) to be trivial #defines
      just adding 5th arg.
      
      iov_send_recv() will be used later.
      Signed-off-by: NMichael Tokarev <mjt@tls.msk.ru>
      e3e87df4
    • M
      rename qemu_sendv to iov_send, change proto and move declarations to iov.h · 3e80bf93
      Michael Tokarev 提交于
      Rename arguments and use size_t for sizes instead of int,
      from
       int
       qemu_sendv(int sockfd, struct iovec *iov,
                  int len, int iov_offset)
      to
       ssize_t
       iov_send(int sockfd, struct iovec *iov,
                size_t offset, size_t bytes)
      
      The main motivation was to make it clear that length
      and offset are in _bytes_, not in iov elements: it was
      very confusing before, because all standard functions
      which deals with iovecs expects number of iovs, not
      bytes, even the fact that struct iovec has iov_len and
      iov_ prefix does not help.  With "bytes" and "offset",
      especially since they're now size_t, it is much more
      explicit.  Also change the return type to be ssize_t
      instead of int.
      
      This also changes it to match other iov-related functons,
      but not _quite_: there's still no argument indicating
      where iovec ends, ie, no iov_cnt parameter as used
      in iov_size() and friends.  If will be added in subsequent
      patch/rewrite.
      
      All callers of qemu_sendv() and qemu_recvv() and
      related, like qemu_co_sendv() and qemu_co_recvv(),
      were checked to verify that it is safe to use unsigned
      datatype instead of int.
      
      Note that the order of arguments is changed to: offset
      and bytes (len and iov_offset) are swapped with each
      other.  This is to make them consistent with very similar
      functions from qemu_iovec family, where offset always
      follows qiov, to mean the place in it to start from.
      Signed-off-by: NMichael Tokarev <mjt@tls.msk.ru>
      3e80bf93
  2. 08 6月, 2012 2 次提交
    • M
      rewrite iov_* functions · 2278a69e
      Michael Tokarev 提交于
      This changes implementations of all iov_*
      functions, completing the previous step.
      
      All iov_* functions now ensure that this offset
      argument is within the iovec (using assertion),
      but lets to specify `bytes' value larger than
      actual length of the iovec - in this case they
      stops at the actual end of iovec.  It is also
      suggested to use convinient `-1' value as `bytes'
      to mean just this -- "up to the end".
      
      There's one very minor semantic change here: new
      requiriment is that `offset' points to inside of
      iovec.  This is checked just at the end of functions
      (assert()), it does not actually need to be enforced,
      but using any of these functions with offset pointing
      past the end of iovec is wrong anyway.
      
      Note: the new code in iov.c uses arithmetic with
      void pointers.  I thought this is not supported
      everywhere and is a GCC extension (indeed, the C
      standard does not define void arithmetic).  However,
      the original code already use void arith in
      iov_from_buf() function:
        (memcpy(..., buf + buf_off,...)
      which apparently works well so far (it is this
      way in qemu 1.0).  So I left it this way and used
      it in other places.
      
      While at it, add a unit-test file test-iov.c,
      to check various corner cases with iov_from_buf(),
      iov_to_buf() and iov_memset().
      Signed-off-by: NMichael Tokarev <mjt@tls.msk.ru>
      2278a69e
    • M
      change iov_* function prototypes to be more appropriate · dcf6f5e1
      Michael Tokarev 提交于
      Reorder arguments to be more natural, readable and
      consistent with other iov_* functions, and change
      argument names, from:
       iov_from_buf(iov, iov_cnt, buf, iov_off, size)
      to
       iov_from_buf(iov, iov_cnt, offset, buf, bytes)
      
      The result becomes natural English:
      
       copy data to this `iov' vector with `iov_cnt'
       elements starting at byte offset `offset'
       from memory buffer `buf', processing `bytes'
       bytes max.
      
      (Try to read the original prototype this way).
      
      Also change iov_clear() to more general iov_memset()
      (it uses memset() internally anyway).
      
      While at it, add comments to the header file
      describing what the routines actually does.
      
      The patch only renames argumens in the header, but
      keeps old names in the implementation.  The next
      patch will touch actual code to match.
      
      Now, it might look wrong to pay so much attention
      to so small things.  But we've so many badly designed
      interfaces already so the whole thing becomes rather
      confusing or error prone.  One example of this is
      previous commit and small discussion which emerged
      from it, with an outcome that the utility functions
      like these aren't well-understdandable, leading to
      strange usage cases.  That's why I paid quite some
      attention to this set of functions and a few
      others in subsequent patches.
      Signed-off-by: NMichael Tokarev <mjt@tls.msk.ru>
      dcf6f5e1
  3. 04 8月, 2011 2 次提交
  4. 18 7月, 2011 1 次提交
  5. 11 5月, 2010 1 次提交
  6. 28 4月, 2010 2 次提交