static int connection_process_requests(struct connection *c, char *req, int req_sz, char *resp, int resp_sz) { /* FIXME: close connection on error? */ if (connection_parse_requests(c, req, req_sz)) return -EINVAL; return connection_get_reply(c, resp, resp_sz); }
int twrite(spdid_t spdid, td_t td, int cbid, int sz) { struct connection *c = NULL; struct torrent *t; char *buf; int ret = -1; if (tor_isnull(td)) return -EINVAL; buf = cbuf2buf(cbid, sz); if (!buf) ERR_THROW(-EINVAL, done); LOCK(); t = tor_lookup(td); if (!t) ERR_THROW(-EINVAL, unlock); if (!(t->flags & TOR_WRITE)) ERR_THROW(-EACCES, unlock); c = t->data; assert(c); lock_connection(c); UNLOCK(); if (connection_parse_requests(c, buf, sz)) ERR_THROW(-EINVAL, release); unlock_connection(c); ret = sz; done: return ret; unlock: UNLOCK(); release: unlock_connection(c); goto done; }
int content_write(spdid_t spdid, long connection_id, char *reqs, int sz) { struct connection *c; // printc("HTTP write"); c = cos_map_lookup(&conn_map, connection_id); if (NULL == c) return -EINVAL; if (connection_parse_requests(c, reqs, sz)) return -EINVAL; return sz; }