/**********************************************************************
 * ti library's send-message routine
 *
 * $Author: brlewis $
 * $Source: /afs/net.mit.edu/project/net_dev/brlewis/src/lib/RCS/sendmsg.c,v $
 * $Header: /afs/net.mit.edu/project/net_dev/brlewis/src/lib/RCS/sendmsg.c,v 0.2 92/04/01 16:15:52 brlewis Exp $
 *
 * Copyright 1991 by the Massachusetts Institute of Technology.
 *
 * For copying and distribution information, please see the file
 * <mit-copyright.h>.
 **********************************************************************/
#include <mit-copyright.h>

#ifndef lint
static char rcsid__ti_sendmsg_c[] = "$Header: /afs/net.mit.edu/project/net_dev/brlewis/src/lib/RCS/sendmsg.c,v 0.2 92/04/01 16:15:52 brlewis Exp $";
#endif /* lint */

#include <errno.h>
#include <ti/ti.h>

/**********************************************************************
 * _ti_sendmsg(TI *tp, char *buf, int bufsize)
 *
 * - writes message from buf into tp->sock
 * - returns error code
 **********************************************************************/

long
_ti_sendmsg(tp, buf, bufsize)
    TI *tp;
    char *buf;
    int bufsize;
{
  int wrote=0, total;

  /* write message */
  for (total=0; total<bufsize; total += wrote)
    {
      /* send as many bytes as the server will take */
      wrote = write(tp->sock, buf+total, bufsize-total);

      /* handle error */
      if (wrote<0)
	{
	  *ti_context = '\0';
	  return((long) errno);
	}
    }

  /* success */
  return(0L);
}
