/** * Start a new ttcp transfer. It should be possible to call this function * multiple times in order to get multiple ttcp streams. done_cb() will be * invoked upon completion. * */ int ttcp_start(struct ip_addr addr, uint16_t port, void *opaque, ttcp_done_cb_t *done_cb, int mode, uint16_t nbuf, uint16_t buflen, int udp, int verbose) { struct ttcp* ttcp; int status; if (mode != TTCP_MODE_TRANSMIT && mode != TTCP_MODE_RECEIVE) { printk("TTCP [-]: invalid mode\n"); return -1; } if (nbuf == 0) { printk("TTCP [-]: invalid nbuf\n"); return -1; } if (buflen == 0) { printk("TTCP [-]: invalid buflen\n"); return -1; } ttcp = calloc(1, sizeof(struct ttcp)); if (ttcp == NULL) { printk("TTCP [-]: could not allocate memory for ttcp\n"); return -1; } ttcp->addr = addr; ttcp->port = port; ttcp->nbuf = nbuf; ttcp->mode = mode; ttcp->left = nbuf * buflen; ttcp->done_cb = done_cb; ttcp->opaque = opaque; ttcp->udp = udp; ttcp->verbose = verbose; ttcp->buflen = buflen; printk("TTCP [%p]: nbuf=%d, buflen=%d, port=%d (%s/%s)\n", ttcp, ttcp->nbuf, ttcp->buflen, ttcp->port, ttcp->udp ? "udp" : "tcp", ttcp->mode == TTCP_MODE_TRANSMIT ? "tx" : "rx"); if (ttcp->udp) status = udp_start(ttcp); else status = tcp_start(ttcp); if (status) goto fail; return 0; fail: ttcp_destroy(ttcp); return -1; }
int main(int argc, char **argv) { struct sigaction sig_stop; struct sigaction sig_time; _main = main_init(argc, argv); _log = log_init(); _main->conf = conf_init(argc, argv); _main->work = work_init(); _main->tcp = tcp_init(); _main->node = node_init(); _main->mime = mime_init(); /* Check configuration */ conf_print(); /* Catch SIG INT */ unix_signal(&sig_stop, &sig_time); /* Fork daemon */ unix_fork(log_console(_log)); /* Increase limits */ unix_limits(_main->conf->cores, CONF_EPOLL_MAX_EVENTS); /* Load mime types */ mime_load(); mime_hash(); /* Prepare TCP daemon */ tcp_start(); /* Drop privileges */ unix_dropuid0(); /* Start worker threads */ work_start(); /* Stop worker threads */ work_stop(); /* Stop TCP daemon */ tcp_stop(); mime_free(); node_free(); tcp_free(); work_free(); conf_free(); log_free(_log); main_free(); return 0; }
static EFI_STATUS fastboot_tcp_start(start_callback_t start_cb, data_callback_t rx_cb, data_callback_t tx_cb) { EFI_STATUS ret; EFI_IPv4_ADDRESS station_address; start_callback = start_cb; rx_callback = rx_cb; tx_callback = tx_cb; ret = tcp_start(TCP_PORT, fastboot_tcp_start_cb, transport_tcp_rx_cb, transport_tcp_tx_cb, &station_address); if (EFI_ERROR(ret)) return ret; print_tcpip_information(&station_address); return EFI_SUCCESS; }