static void
flap_connection_send_byte_stream(ByteStream *bs, FlapConnection *conn, size_t count)
{
	if (conn == NULL)
		return;

	/* Make sure we don't send past the end of the bs */
	if (count > byte_stream_bytes_left(bs))
		count = byte_stream_bytes_left(bs); /* truncate to remaining space */

	if (count == 0)
		return;

	/* Add everything to our outgoing buffer */
	purple_circular_buffer_append(conn->buffer_outgoing, bs->data, count);

	/* If we haven't already started writing stuff, then start the cycle */
	if (conn->watcher_outgoing == 0)
	{
		if (conn->gsc) {
			conn->watcher_outgoing = purple_input_add(conn->gsc->fd,
					PURPLE_INPUT_WRITE, send_cb, conn);
			send_cb(conn, -1, 0);
		} else if (conn->fd >= 0) {
			conn->watcher_outgoing = purple_input_add(conn->fd,
					PURPLE_INPUT_WRITE, send_cb, conn);
			send_cb(conn, -1, 0);
		}
	}
}
Example #2
0
static void ycht_packet_send(YchtConn *ycht, YchtPkt *pkt)
{
	int len, pos, written;
	char *buf;
	GList *l;

	g_return_if_fail(ycht != NULL);
	g_return_if_fail(pkt != NULL);
	g_return_if_fail(ycht->fd != -1);

	pos = 0;
	len = ycht_packet_length(pkt);
	buf = g_malloc(len);

	memcpy(buf + pos, "YCHT", 4); pos += 4;
	pos += yahoo_put32(buf + pos, pkt->version);
	pos += yahoo_put32(buf + pos, pkt->service);
	pos += yahoo_put16(buf + pos, pkt->status);
	pos += yahoo_put16(buf + pos, len - YCHT_HEADER_LEN);

	for (l = pkt->data; l; l = l->next) {
		int slen = strlen(l->data);
		memcpy(buf + pos, l->data, slen); pos += slen;

		if (l->next) {
			memcpy(buf + pos, YCHT_SEP, strlen(YCHT_SEP));
			pos += strlen(YCHT_SEP);
		}
	}

	if (!ycht->tx_handler)
		written = write(ycht->fd, buf, len);
	else {
		written = -1;
		errno = EAGAIN;
	}

	if (written < 0 && errno == EAGAIN)
		written = 0;
	else if (written <= 0) {
		/* TODO: Error handling (was none before NBIO changes) */
		written = 0;
	}

	if (written < len) {
		if (!ycht->tx_handler)
			ycht->tx_handler = purple_input_add(ycht->fd,
				PURPLE_INPUT_WRITE, ycht_packet_send_write_cb,
				ycht);
		purple_circular_buffer_append(ycht->txbuf, buf + written,
			len - written);
	}

	g_free(buf);
}
Example #3
0
/**
 * This should be called by OFT/ODC code to send a standard OFT or ODC
 * frame across the peer connection along with some payload data.  Or
 * maybe a file.  Anything, really.
 */
void
peer_connection_send(PeerConnection *conn, ByteStream *bs)
{
	/* Add everything to our outgoing buffer */
	purple_circular_buffer_append(conn->buffer_outgoing, bs->data, bs->len);

	/* If we haven't already started writing stuff, then start the cycle */
	if ((conn->watcher_outgoing == 0) && (conn->fd >= 0))
	{
		conn->watcher_outgoing = purple_input_add(conn->fd,
				PURPLE_INPUT_WRITE, send_cb, conn);
		send_cb(conn, conn->fd, 0);
	}
}