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_circ_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); } } }
int send_packet(const byte buffer[], byte len, void (*send_cb)(byte[], byte len)) { int byte_counter=0; byte *payload_buf = (byte *)malloc(len*2); byte actual_length_payload = escape_buffer(buffer, payload_buf, len); byte actual_length_buf[2]; // we also need to escape the length byte byte actual_length_length = escape_buffer(&len, actual_length_buf, 1); send_cb(&start_byte, 1); send_cb(actual_length_buf, actual_length_length); send_cb(payload_buf, actual_length_payload); send_cb(&stop_byte, 1); free(payload_buf); byte_counter += (1 + 1 + actual_length_length + actual_length_payload); return byte_counter; }
/** * 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_circ_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); } }
/* Write tasklet handler: Continue sending current skb, or send command, or * start sending an skb from the send queue. */ static void gigaset_modem_fill(unsigned long data) { struct cardstate *cs = (struct cardstate *) data; struct bc_state *bcs = &cs->bcs[0]; /* only one channel */ struct cmdbuf_t *cb; unsigned long flags; int again; gig_dbg(DEBUG_OUTPUT, "modem_fill"); if (atomic_read(&cs->hw.usb->busy)) { gig_dbg(DEBUG_OUTPUT, "modem_fill: busy"); return; } do { again = 0; if (!bcs->tx_skb) { /* no skb is being sent */ spin_lock_irqsave(&cs->cmdlock, flags); cb = cs->cmdbuf; spin_unlock_irqrestore(&cs->cmdlock, flags); if (cb) { /* commands to send? */ gig_dbg(DEBUG_OUTPUT, "modem_fill: cb"); if (send_cb(cs, cb) < 0) { gig_dbg(DEBUG_OUTPUT, "modem_fill: send_cb failed"); again = 1; /* no callback will be called! */ } } else { /* skbs to send? */ bcs->tx_skb = skb_dequeue(&bcs->squeue); if (bcs->tx_skb) gig_dbg(DEBUG_INTR, "Dequeued skb (Adr: %lx)!", (unsigned long) bcs->tx_skb); } } if (bcs->tx_skb) { gig_dbg(DEBUG_OUTPUT, "modem_fill: tx_skb"); if (write_modem(cs) < 0) { gig_dbg(DEBUG_OUTPUT, "modem_fill: write_modem failed"); // FIXME should we tell the LL? again = 1; /* no callback will be called! */ } } } while (again); }
static void gigaset_modem_fill(unsigned long data) { struct cardstate *cs = (struct cardstate *) data; struct bc_state *bcs = &cs->bcs[0]; struct cmdbuf_t *cb; int again; gig_dbg(DEBUG_OUTPUT, "modem_fill"); if (cs->hw.usb->busy) { gig_dbg(DEBUG_OUTPUT, "modem_fill: busy"); return; } do { again = 0; if (!bcs->tx_skb) { cb = cs->cmdbuf; if (cb) { gig_dbg(DEBUG_OUTPUT, "modem_fill: cb"); if (send_cb(cs, cb) < 0) { gig_dbg(DEBUG_OUTPUT, "modem_fill: send_cb failed"); again = 1; } } else { bcs->tx_skb = skb_dequeue(&bcs->squeue); if (bcs->tx_skb) gig_dbg(DEBUG_INTR, "Dequeued skb (Adr: %lx)!", (unsigned long) bcs->tx_skb); } } if (bcs->tx_skb) { gig_dbg(DEBUG_OUTPUT, "modem_fill: tx_skb"); if (write_modem(cs) < 0) { gig_dbg(DEBUG_OUTPUT, "modem_fill: write_modem failed"); again = 1; } } } while (again); }