当前位置: 首页>>代码示例>>C++>>正文


C++ write_packet函数代码示例

本文整理汇总了C++中write_packet函数的典型用法代码示例。如果您正苦于以下问题:C++ write_packet函数的具体用法?C++ write_packet怎么用?C++ write_packet使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了write_packet函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: dbg_reply_get_thread_list

void dbg_reply_get_thread_list(struct dbg_context* dbg,
                               const dbg_threadid_t* threads, size_t len)
{
    assert(DREQ_GET_THREAD_LIST == dbg->req.type);

    if (0 == len) {
        write_packet(dbg, "l");
    } else {
        size_t maxlen =	1/*m char*/ +
                        (2 * sizeof(pid_t) + 1/*,*/) * len +
                        1/*\0*/;
        char* str = sys_malloc(maxlen);
        int i, offset = 0;

        str[offset++] = 'm';
        for (i = 0; i < len; ++i) {
            offset += snprintf(&str[offset], maxlen - offset,
                               "%02x,", threads[i]);
        }
        /* Overwrite the trailing ',' */
        str[offset - 1] = '\0';

        write_packet(dbg, str);
        sys_free((void**)&str);
    }

    consume_request(dbg);
}
开发者ID:smillaedler,项目名称:rr,代码行数:28,代码来源:dbg_gdb.c

示例2: test_already_launched

void
test_already_launched (void)
{
    const gchar *packet;
    gsize packet_size;
    GString *output;
    GString *expected_packet;
    const gchar command_line[] = "/bin/cat";
    const gchar *user_name;

    user_name = g_get_user_name();
    milter_manager_launch_command_encoder_encode_launch(command_encoder,
                                                        &packet, &packet_size,
                                                        command_line, user_name);
    cut_trace(write_packet(packet, packet_size));
    cut_trace(write_packet(packet, packet_size));
    pump_all_events();

    milter_manager_reply_encoder_encode_success(reply_encoder,
                                                &packet, &packet_size);
    expected_packet = g_string_new_len(packet, packet_size);
    milter_manager_reply_encoder_encode_error(reply_encoder,
                                              &packet, &packet_size,
                                              "already launched: </bin/cat>");
    g_string_append_len(expected_packet, packet, packet_size);
    output = gcut_string_io_channel_get_string(output_channel);
    cut_assert_equal_memory(expected_packet->str, expected_packet->len,
                            output->str, output->len);
}
开发者ID:michaelm260,项目名称:milter-manager,代码行数:29,代码来源:test-process-launcher.c

示例3: ADB_LOGD

static void *output_thread(void *_t)
{
    atransport *t = reinterpret_cast<atransport*>(_t);
    apacket *p;

    ADB_LOGD(ADB_TSPT,
             "%s: starting transport output thread on fd %d, SYNC online (%d)",
             t->serial, t->fd, t->sync_token + 1);
    p = get_apacket();
    p->msg.command = A_SYNC;
    p->msg.arg0 = 1;
    p->msg.arg1 = ++(t->sync_token);
    p->msg.magic = A_SYNC ^ 0xffffffff;
    if (write_packet(t->fd, t->serial, &p)) {
        put_apacket(p);
        ADB_LOGE(ADB_TSPT, "%s: failed to write SYNC packet", t->serial);
        goto oops;
    }

    ADB_LOGD(ADB_TSPT, "%s: data pump started", t->serial);
    for (;;) {
        p = get_apacket();

        if (t->read_from_remote(p, t) == 0) {
            ADB_LOGD(ADB_TSPT,
                     "%s: received remote packet, sending to transport",
                     t->serial);
            if (write_packet(t->fd, t->serial, &p)) {
                put_apacket(p);
                ADB_LOGE(ADB_TSPT,
                         "%s: failed to write apacket to transport", t->serial);
                goto oops;
            }
        } else {
            ADB_LOGE(ADB_TSPT,
                     "%s: remote read failed for transport", t->serial);
            put_apacket(p);
            break;
        }
    }

    ADB_LOGD(ADB_TSPT, "%s: SYNC offline for transport", t->serial);
    p = get_apacket();
    p->msg.command = A_SYNC;
    p->msg.arg0 = 0;
    p->msg.arg1 = 0;
    p->msg.magic = A_SYNC ^ 0xffffffff;
    if (write_packet(t->fd, t->serial, &p)) {
        put_apacket(p);
        ADB_LOGW(ADB_TSPT,
                 "%s: failed to write SYNC apacket to transport", t->serial);
    }

oops:
    ADB_LOGD(ADB_TSPT, "%s: transport output thread is exiting", t->serial);
    kick_transport(t);
    transport_unref(t);
    return 0;
}
开发者ID:Anik1199,项目名称:DualBootPatcher,代码行数:59,代码来源:transport.cpp

示例4: adb_thread_setname

// The transport is opened by transport_register_func before
// the read_transport and write_transport threads are started.
//
// The read_transport thread issues a SYNC(1, token) message to let
// the write_transport thread know to start things up.  In the event
// of transport IO failure, the read_transport thread will post a
// SYNC(0,0) message to ensure shutdown.
//
// The transport will not actually be closed until both threads exit, but the threads
// will kick the transport on their way out to disconnect the underlying device.
//
// read_transport thread reads data from a transport (representing a usb/tcp connection),
// and makes the main thread call handle_packet().
static void *read_transport_thread(void *_t)
{
    atransport *t = reinterpret_cast<atransport*>(_t);
    apacket *p;

    adb_thread_setname(android::base::StringPrintf("<-%s",
                                                   (t->serial != nullptr ? t->serial : "transport")));
    D("%s: starting read_transport thread on fd %d, SYNC online (%d)",
       t->serial, t->fd, t->sync_token + 1);
    p = get_apacket();
    p->msg.command = A_SYNC;
    p->msg.arg0 = 1;
    p->msg.arg1 = ++(t->sync_token);
    p->msg.magic = A_SYNC ^ 0xffffffff;
    if(write_packet(t->fd, t->serial, &p)) {
        put_apacket(p);
        D("%s: failed to write SYNC packet", t->serial);
        goto oops;
    }

    D("%s: data pump started", t->serial);
    for(;;) {
        p = get_apacket();

        if(t->read_from_remote(p, t) == 0){
            D("%s: received remote packet, sending to transport",
              t->serial);
            if(write_packet(t->fd, t->serial, &p)){
                put_apacket(p);
                D("%s: failed to write apacket to transport", t->serial);
                goto oops;
            }
        } else {
            D("%s: remote read failed for transport", t->serial);
            put_apacket(p);
            break;
        }
    }

    D("%s: SYNC offline for transport", t->serial);
    p = get_apacket();
    p->msg.command = A_SYNC;
    p->msg.arg0 = 0;
    p->msg.arg1 = 0;
    p->msg.magic = A_SYNC ^ 0xffffffff;
    if(write_packet(t->fd, t->serial, &p)) {
        put_apacket(p);
        D("%s: failed to write SYNC apacket to transport", t->serial);
    }

oops:
    D("%s: read_transport thread is exiting", t->serial);
    kick_transport(t);
    transport_unref(t);
    return 0;
}
开发者ID:sprindy,项目名称:platform_system_core,代码行数:69,代码来源:transport.cpp

示例5: D

static void *output_thread(void *_t)
{
    atransport *t = _t;
    apacket *p;

    D("from_remote: starting thread for transport %p, on fd %d\n", t, t->fd );

    D("from_remote: transport %p SYNC online (%d)\n", t, t->sync_token + 1);
    p = get_apacket();
    p->msg.command = A_SYNC;
    p->msg.arg0 = 1;
    p->msg.arg1 = ++(t->sync_token);
    p->msg.magic = A_SYNC ^ 0xffffffff;
    if(write_packet(t->fd, &p)) {
        put_apacket(p);
        D("from_remote: failed to write SYNC apacket to transport %p", t);
        goto oops;
    }

    D("from_remote: data pump  for transport %p\n", t);
    for(;;) {
        p = get_apacket();

        if(t->read_from_remote(p, t) == 0){
            D("from_remote: received remote packet, sending to transport %p\n",
              t);
            if(write_packet(t->fd, &p)){
                put_apacket(p);
                D("from_remote: failed to write apacket to transport %p", t);
                goto oops;
            }
        } else {
            D("from_remote: remote read failed for transport %p\n", p);
            put_apacket(p);
            break;
        }
    }

    D("from_remote: SYNC offline for transport %p\n", t);
    p = get_apacket();
    p->msg.command = A_SYNC;
    p->msg.arg0 = 0;
    p->msg.arg1 = 0;
    p->msg.magic = A_SYNC ^ 0xffffffff;
    if(write_packet(t->fd, &p)) {
        put_apacket(p);
        D("from_remote: failed to write SYNC apacket to transport %p", t);
    }

oops:
    D("from_remote: thread is exiting for transport %p\n", t);
    kick_transport(t);
    transport_unref(t);
    return 0;
}
开发者ID:AnahiAramayo,项目名称:rxwen-blog-stuff,代码行数:55,代码来源:transport.c

示例6: send_stop_reply_packet

static void send_stop_reply_packet(struct dbg_context* dbg,
                                   dbg_threadid_t thread, int sig)
{
    if (sig >= 0) {
        char buf[64];
        snprintf(buf, sizeof(buf) - 1, "T%02xthread:%02x;",
                 sig, thread);
        write_packet(dbg, buf);
    } else {
        write_packet(dbg, "E01");
    }
}
开发者ID:smillaedler,项目名称:rr,代码行数:12,代码来源:dbg_gdb.c

示例7: process_vpacket

static int process_vpacket(struct dbg_context* dbg, char* payload)
{
    const char* name;
    char* args;

    args = strchr(payload, ';');
    if (args) {
        *args++ = '\0';
    }
    name = payload;

    if (!strcmp("Cont", name)) {
        char cmd = *args++;
        if ('\0' != args[1]) {
            *args++ = '\0';
        }

        switch (cmd) {
        case 'c':
            dbg->req.type = DREQ_CONTINUE;
            dbg->req.target = dbg->resume_thread;
            return 1;
        case 's':
            dbg->req.type = DREQ_STEP;
            if (args) {
                dbg->req.target = parse_threadid(args, &args);
                assert('\0' == *args || !strcmp(args, ";c"));
            } else {
                dbg->req.target = dbg->resume_thread;
            }
            return 1;
        default:
            log_warn("Unhandled vCont command %c(%s)", cmd, args);
            write_packet(dbg, "");
            return 0;
        }
    }

    if (!strcmp("Cont?", name)) {
        debug("gdb queries which continue commands we support");
        write_packet(dbg, "vCont;c;C;s;S;t;");
        return 0;
    }

    log_warn("Unhandled gdb vpacket: v%s", name);
    write_packet(dbg, "");
    return 0;
}
开发者ID:smillaedler,项目名称:rr,代码行数:48,代码来源:dbg_gdb.c

示例8: D

/* The transport is opened by transport_register_func before
** the input and output threads are started.
**
** The output thread issues a SYNC(1, token) message to let
** the input thread know to start things up.  In the event
** of transport IO failure, the output thread will post a
** SYNC(0,0) message to ensure shutdown.
**
** The transport will not actually be closed until both
** threads exit, but the input thread will kick the transport
** on its way out to disconnect the underlying device.
*/
void *output_thread(void *_t, struct dll_io_bridge * _io_bridge)
{
    o_bridge = _io_bridge;

    atransport *t = (atransport *)_t;
    apacket *p;

    D("%s: starting transport output thread on fd %d, SYNC online (%d)\n",
       t->serial, t->fd, t->sync_token + 1);
    p = get_apacket();
    p->msg.command = A_SYNC;
    p->msg.arg0 = 1;
    p->msg.arg1 = ++(t->sync_token);
    p->msg.magic = A_SYNC ^ 0xffffffff;
    if(write_packet(t->fd, t->serial, &p)) {
        put_apacket(p);
        D("%s: failed to write SYNC packet\n", t->serial);
        goto oops;
    }

    D("%s: data pump started\n", t->serial);
    for(;;) {
        p = get_apacket();

        if(t->read_from_remote(p, t) == 0){
            D("%s: received remote packet, sending to transport\n",
              t->serial);
            if(write_packet(t->fd, t->serial, &p)){
                put_apacket(p);
                D("%s: failed to write apacket to transport\n", t->serial);
                goto oops;
            }
        } else {
            D("%s: remote read failed for transport\n", t->serial);
            put_apacket(p);
            break;
        }
    }

    handle_output_offline(t);
oops:
#ifdef WIN32
    handle_output_oops(t, o_bridge->AdbCloseHandle);
#else
    handle_output_oops(t, NULL);
#endif
    return NULL;
}
开发者ID:ajsb85,项目名称:libadb.js,代码行数:60,代码来源:transport.cpp

示例9: test_launch_error

void
test_launch_error (gconstpointer data)
{
    const gchar *packet;
    gsize packet_size;
    GString *output;
    const gchar *command;
    const gchar *user_name;
    const gchar *expected_error_message;

    command = gcut_data_get_string(data, "command");
    user_name = gcut_data_get_string(data, "user-name");
    expected_error_message = gcut_data_get_string(data,
                                                  "expected-error-message");

    milter_manager_launch_command_encoder_encode_launch(command_encoder,
                                                        &packet, &packet_size,
                                                        command, user_name);
    cut_trace(write_packet(packet, packet_size));
    pump_all_events();

    milter_manager_reply_encoder_encode_error(reply_encoder,
                                              &packet, &packet_size,
                                              expected_error_message);
    output = gcut_string_io_channel_get_string(output_channel);
    cut_assert_equal_memory(packet, packet_size,
                            output->str, output->len);
}
开发者ID:michaelm260,项目名称:milter-manager,代码行数:28,代码来源:test-process-launcher.c

示例10: write_hex_packet

static void write_hex_packet(struct dbg_context* dbg, unsigned long hex)
{
    char buf[32];

    snprintf(buf, sizeof(buf) - 1, "%02lx", hex);
    write_packet(dbg, buf);
}
开发者ID:smillaedler,项目名称:rr,代码行数:7,代码来源:dbg_gdb.c

示例11: ether_do_write

static int16 ether_do_write(uint32 arg)
{
	D(bug("ether_write\n"));

	// Copy packet to buffer
	uint8 packet[1514], *p = packet;
	int len = ether_arg_to_buffer(arg, p);

	if(len > 1514) {
		D(bug("illegal packet length: %d\n",len));
		return eLenErr;
	} else {
#if MONITOR
		bug("Sending Ethernet packet (%d bytes):\n",(int)len);
		dump_packet( packet, len );
#endif
	}

	// Transmit packet
	if (!write_packet(packet, len)) {
		D(bug("WARNING: couldn't transmit packet\n"));
		return excessCollsns;
	} else {
		// It's up to the protocol drivers to do the error checking. Even if the
		// i/o completion routine returns ok, there can be errors, so there is
		// no point to wait for write completion and try to make some sense of the
		// possible error codes.
		return noErr;
	}
}
开发者ID:tycho,项目名称:sheepshaver,代码行数:30,代码来源:ether_windows.cpp

示例12: write_cryptpacket

/*  return 0 if data could not be put in packet queue.
 *  return 1 if data was put into the queue.
 */
int write_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uint32_t length)
{
    if (crypt_connection_id_not_valid(c, crypt_connection_id))
        return 0;

    if (length - crypto_box_BOXZEROBYTES + crypto_box_ZEROBYTES > MAX_DATA_SIZE - 1)
        return 0;

    if (c->crypto_connections[crypt_connection_id].status != CRYPTO_CONN_ESTABLISHED)
        return 0;

    uint8_t temp_data[MAX_DATA_SIZE];
    int len = encrypt_data_fast(c->crypto_connections[crypt_connection_id].shared_key,
                                c->crypto_connections[crypt_connection_id].sent_nonce,
                                data, length, temp_data + 1);

    if (len == -1)
        return 0;

    temp_data[0] = 3;

    if (write_packet(c->lossless_udp, c->crypto_connections[crypt_connection_id].number, temp_data, len + 1) == 0)
        return 0;

    increment_nonce(c->crypto_connections[crypt_connection_id].sent_nonce);
    return 1;
}
开发者ID:psihodelia,项目名称:ProjectTox-Core,代码行数:30,代码来源:net_crypto.c

示例13: write_cryptpacket

/* return 0 if data could not be put in packet queue
   return 1 if data was put into the queue */
int write_cryptpacket(int crypt_connection_id, uint8_t * data, uint32_t length)
{
    if(crypt_connection_id < 0 || crypt_connection_id >= MAX_CRYPTO_CONNECTIONS)
    {
        return 0;   
    }
    if(length - crypto_box_BOXZEROBYTES + crypto_box_ZEROBYTES > MAX_DATA_SIZE - 1)
    {
        return 0;
    }
    if(crypto_connections[crypt_connection_id].status != 3)
    {
        return 0;
    }
    uint8_t temp_data[MAX_DATA_SIZE];
    int len = encrypt_data(crypto_connections[crypt_connection_id].peersessionpublic_key, 
                           crypto_connections[crypt_connection_id].sessionsecret_key,
                           crypto_connections[crypt_connection_id].sent_nonce, data, length, temp_data + 1);
    if(len == -1)
    {
        return 0;
    }
    temp_data[0] = 3;
    if(write_packet(crypto_connections[crypt_connection_id].number, temp_data, len + 1) == 0)
    {
        return 0;
    }
    increment_nonce(crypto_connections[crypt_connection_id].sent_nonce);
    return 1;
}
开发者ID:krisl,项目名称:Poison,代码行数:32,代码来源:net_crypto.c

示例14: net_stream_open

static int net_stream_open(client_t* cl,char* url) {
  int file_format=DEMUXER_TYPE_UNKNOWN;
  mp_net_stream_opened_t ret;

  if(cl->stream) {
    if(!write_error(cl->fd,"A stream is currently opened\n"))
      return 0;
    return 1;
  }

  mp_msg(MSGT_NETST,MSGL_V,"Open stream %s\n",url);
  cl->stream = open_stream(url,NULL,&file_format);
  if(!cl->stream) {
    if(!write_error(cl->fd,"Open failed\n"))
      return 0;
    return 1;
  }
  stream_reset(cl->stream);
  stream_seek(cl->stream,cl->stream->start_pos);
  ret.file_format = file_format;
  ret.flags = cl->stream->flags;
  ret.sector_size = cl->stream->sector_size;
  ret.start_pos = cl->stream->start_pos;
  ret.end_pos = cl->stream->end_pos;
  net_stream_opened_2_me(&ret);

  if(!write_packet(cl->fd,NET_STREAM_OK,(char*)&ret,sizeof(mp_net_stream_opened_t)))
    return 0;
  return 1;
}
开发者ID:OpenSageTV,项目名称:mplayer-sage9orig,代码行数:30,代码来源:netstream.c

示例15: buffer_packet

/*
 * buffer_packet()
 *
 * Add the FLV packet "packet" to an internal statically-held array of FLVpacket
 * structs. Duplicate the data payload and update the data pointer in the packet
 * to point to the duplicated data.
 * If "flush" is non-zero, write out all the packets in the buffer using
 * write_packet() in order received, free all the memory used for the
 * payloads and reset the packet buffer count to 0.
 * "file_start_timestamp" should contain the timestamp for the start of the
 * current file, and is passed to write_packet() when flushing the buffer.
 */
static void buffer_packet(struct FLVpacket *packet, long file_start_timestamp, char flush)
{
    static struct FLVpacket *pktarray = NULL;
    static int packets = 0, max_packets = 0;

    if( packets >= max_packets )
    {
        max_packets += 5;
        pktarray = realloc( pktarray, max_packets * sizeof(struct FLVpacket) );
    }

    pktarray[packets] = *packet;
    pktarray[packets].data = malloc(packet->datasize);
    memcpy(pktarray[packets].data, packet->data, packet->datasize);

    packets++;

    if(flush) /* Flush the buffer and free all data */
    {   /* Don't free the FLVpacket array as we may use it again */
        int i;

        for( i = 0; i < packets; i++ )
        {
            write_packet( &pktarray[i], file_start_timestamp );
            free(pktarray[i].data);
        }
        packets = 0;
    }

    return;
}
开发者ID:pdkelly,项目名称:flvjoin,代码行数:43,代码来源:flvjoin.c


注:本文中的write_packet函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。