int send_msg()

in src/generic/messages.c [256:317]


int send_msg(Tcl_Channel f, int command, int flags, int size, void *data)
{

    /*  void *origsig; */
    MsgHeader mh;
    int ret;

    /* remember SIGPIPE handler and ignore from now on: */
    /* origsig=signal(SIGPIPE,SIG_IGN); */

    /* fill in message header */
    mh.magic = htonl(WMSG_MAGIC);
    mh.version = htonl(WMSG_VERSION);
    mh.command = htonl((u_long) ((command & 0xffff) | (flags & 0xffff0000)));
    mh.size = htonl((u_long) size);

    /* send header */
    ret = Tcl_Write(f, (char *) &mh, sizeof(MsgHeader));
    if (ret == -1) {
	/*signal(SIGPIPE,origsig); */
#ifdef MSGDEBUG
	printf("Error writing to socket\n");
#endif
	return (-1);
    }
    if (ret != sizeof(MsgHeader)) {
	/*signal(SIGPIPE,origsig); */
#ifdef MSGDEBUG
	printf("Could only write %d instead of %d bytes\n", ret,
	       sizeof(MsgHeader));
#endif
	errno = EIO;
	return (-1);
    }

    /* send data */
    ret = 0;
    if (size != 0) {
	ret = Tcl_Write(f, (char *) data, size * sizeof(char));
	if (ret == -1) {
	    /* signal(SIGPIPE,origsig); */
#ifdef MSGDEBUG
	    printf("Error writing to socket\n");
#endif
	    return (-1);
	}
	if (ret != (int) (size * sizeof(char))) {
	    /*signal(SIGPIPE,origsig); */
#ifdef MSGDEBUG
	    printf("Could only write %d instead of %d bytes\n", ret,
		   sizeof(MsgHeader));
#endif
	    errno = EIO;
	    return (-1);
	}
    }
/*signal(SIGPIPE,origsig); */
    if (!(flags & WMSG_FLAG_MULT)) {
	Tcl_Flush(f);
    }
    return 0;
}