1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
/* Swrite.c: this file contains the Swrite() function
* Authors: Charles E. Campbell, Jr.
* Terry McRoberts
* Copyright: Copyright (C) 1999-2005 Charles E. Campbell, Jr. {{{1
* Permission is hereby granted to use and distribute this code,
* with or without modifications, provided that this copyright
* notice is copied with it. Like anything else that's free,
* Swrite.c is provided *as is* and comes with no warranty
* of any kind, either expressed or implied. By using this
* software, you agree that in no event will the copyright
* holder be liable for any damages resulting from the use
* of this software.
* Date: Aug 22, 2005
*/
#include <stdio.h>
#include "sockets.h"
/* Swrite: this function performs a socket write of a string.
* It will write out the requested bytes (up to a null byte),
* even if the socket buffer is full.
*
* If the write fails, it will return the negative of the number
* of bytes actually transmitted. Otherwise, it will return the
* number of bytes transmitted, which ought to be the same as buflen
* if life is just.
*/
#ifdef __PROTOTYPE__
int Swrite(
Socket *skt, /* socket handle */
const void *buf, /* socket character buffer */
int buflen) /* length of buffer */
#else
int Swrite(
skt, /* socket handle */
buf, /* socket character buffer */
buflen) /* length of buffer */
Socket *skt;
const void *buf;
int buflen;
#endif
{
int cnt;
int wcnt;
/* sanity check */
if (!skt) {
return -1;
}
/* write buflen bytes, no matter the wait */
for (cnt = 0; cnt < buflen; cnt += wcnt) {
wcnt = send(skt->skt, (void *) (((char *) buf) + cnt),
(unsigned) (buflen - cnt), 0);
if (wcnt < 0) {
return cnt;
}
}
return cnt;
}
/* ---------------------------------------------------------------------
* vim: ts=4
*/
|