td_t tsplit(spdid_t spdid, td_t td, char *param, int len, tor_flags_t tflags, long evtid) { td_t ret = -1; struct torrent *t, *nt; struct fsobj *fso, *fsc, *parent; /* obj, child, and parent */ char *subpath; if (tor_isnull(td)) return -EINVAL; LOCK(); t = tor_lookup(td); if (!t) ERR_THROW(-EINVAL, done); fso = t->data; fsc = fsobj_path2obj(param, len, fso, &parent, &subpath); if (!fsc) return -ENOENT; fsobj_take(fsc); nt = tor_alloc(fsc, tflags); if (!nt) ERR_THROW(-ENOMEM, done); ret = nt->td; /* If we created the torrent, then trigger an event as we have data! */ evt_trigger(cos_spd_id(), evtid); done: UNLOCK(); return ret; }
td_t tsplit(spdid_t spdid, td_t tid, char *param, int len, tor_flags_t tflags, long evtid) { td_t ret = -EINVAL; struct torrent *t; net_connection_t nc = 0; int accept = 0; if (tor_isnull(tid)) return -EINVAL; NET_LOCK_TAKE(); /* creating a new connection */ if (tid == td_root || len == 0 || strstr(param, "accept")) { if (tid == td_root) { /* new connection */ nc = net_create_tcp_connection(spdid, cos_get_thd_id(), evtid); if (nc <= 0) ERR_THROW(-ENOMEM, done); } else { /* len == 0 || strstr(param, "accept"), accept on connection */ t = tor_lookup(tid); if (!t) goto done; nc = net_accept(spdid, (net_connection_t)t->data); if (nc == -EAGAIN) { /* printc("net accept return EAGAIN\n"); */ ERR_THROW(-EAGAIN, done); } if (nc < 0) ERR_THROW(-EINVAL, done); if (0 < net_accept_data(spdid, nc, evtid)) BUG(); accept = 1; } t = tor_alloc((void*)nc, tflags); if (!t) ERR_THROW(-ENOMEM, free); ret = t->td; } else { /* modifying an existing connection */ t = tor_lookup(tid); if (!t) goto done; nc = (net_connection_t)t->data; } if (!accept && len != 0) { int r; NET_LOCK_RELEASE(); r = modify_connection(spdid, nc, param, len); if (r < 0) ret = r; NET_LOCK_TAKE(); } done: NET_LOCK_RELEASE(); assert(lock_contested(&net_lock) != cos_get_thd_id()); return ret; free: net_close(spdid, nc); goto done; }
td_t tsplit(spdid_t spdid, td_t tid, char *param, int len, tor_flags_t tflags, long evtid) { td_t ret = -ENOMEM; struct torrent *t; if (tid != td_root) return -EINVAL; netif_event_create(spdid); t = tor_alloc((void*)1, tflags); if (!t) ERR_THROW(-ENOMEM, err); ret = t->td; err: return ret; }
td_t tsplit(spdid_t spdid, td_t tid, char *param, int len, tor_flags_t tflags, long evtid) { td_t ret = -ENOMEM, ntd; struct torrent *t; if (tid != td_root) return -EINVAL; ntd = parent_tsplit(cos_spd_id(), tid, param, len, tflags, evtid); if (ntd <= 0) ERR_THROW(ntd, err); t = tor_alloc((void*)ntd, tflags); if (!t) ERR_THROW(-ENOMEM, err); ret = t->td; err: return ret; }
td_t tsplit(spdid_t spdid, td_t td, char *param, int len, tor_flags_t tflags, long evtid) { td_t ret = -1; struct torrent *t, *nt; int channel, direction; LOCK(); if (tor_isnull(td)) ERR_THROW(-EINVAL, done); t = tor_lookup(td); if (!t) ERR_THROW(-EINVAL, done); if (len > 1) ERR_THROW(-EINVAL, done); channel = (int)(*param - '0'); if (channel > 9 || channel < 0) ERR_THROW(-EINVAL, done); if (!channels[channel].exists) ERR_THROW(-ENOENT, done); nt = tor_alloc(&channels[channel], tflags); if (!nt) ERR_THROW(-ENOMEM, done); ret = nt->td; direction = channels[channel].direction; if (direction == COS_TRANS_DIR_LTOC) { if (tflags != TOR_READ) ERR_THROW(-EINVAL, free); if (channels[channel].t) ERR_THROW(-EBUSY, free); } if (direction == COS_TRANS_DIR_CTOL && tflags != TOR_WRITE) ERR_THROW(-EINVAL, free); if (direction == COS_TRANS_DIR_LTOC) { nt->evtid = evtid; channels[channel].t = nt; } else { nt->evtid = 0; } done: UNLOCK(); return ret; free: tor_free(nt); goto done; }
td_t tsplit(spdid_t spdid, td_t tid, char *param, int len, tor_flags_t tflags, long evtid) { td_t ret = -1; struct torrent *t; struct connection *c; if (tor_isnull(tid)) return -EINVAL; LOCK(); c = http_new_connection(0, evtid); if (!c) ERR_THROW(-ENOMEM, err); /* ignore the param for now */ t = tor_alloc(c, tflags); if (!t) ERR_THROW(-ENOMEM, free); c->conn_id = ret = t->td; err: UNLOCK(); return ret; free: http_free_connection(c); goto err; }