File Conn.c changed (mode: 100644) (index 4caddbb..513507e) |
... |
... |
static void Conn_recv_cb_i(const unsigned int slot) |
1193 |
1193 |
else if (Conn_data_cb) |
else if (Conn_data_cb) |
1194 |
1194 |
Conn_data_cb(&Conns[slot]); |
Conn_data_cb(&Conns[slot]); |
1195 |
1195 |
} else if (n == 0) { |
} else if (n == 0) { |
1196 |
|
Log(10, "\tRemote closed sending side (slot=%u, id=%llu)\n", |
|
1197 |
|
slot, Conns[slot].id); |
|
|
1196 |
|
Log(10, "\tRemote closed sending side.\n"); |
1198 |
1197 |
Conns[slot].error_state = CONN_ERROR_HANGUP; |
Conns[slot].error_state = CONN_ERROR_HANGUP; |
|
1198 |
|
/* TODO: Maybe we should just cut INPUT and do not hangup */ |
1199 |
1199 |
} else { |
} else { |
1200 |
1200 |
Log(4, "\tError in recv (slot=%u, id=%llu) [%s]\n", |
Log(4, "\tError in recv (slot=%u, id=%llu) [%s]\n", |
1201 |
1201 |
slot, Conns[slot].id, strerror(errno)); |
slot, Conns[slot].id, strerror(errno)); |
|
... |
... |
static void Conn_poll_cb(const unsigned int slot, int revents) |
1236 |
1236 |
|
|
1237 |
1237 |
/* First, test we have a new connection */ |
/* First, test we have a new connection */ |
1238 |
1238 |
if ((revents & CONN_POLLOUT) |
if ((revents & CONN_POLLOUT) |
1239 |
|
&& (Conn_ignore(slot) == 0)) { |
|
1240 |
|
/* We just established a connection */ |
|
1241 |
|
if (Conns[slot].state == CONN_STATE_CONNECT_b) { |
|
1242 |
|
/* |
|
1243 |
|
* We do not need POLLOUT now - it was used only for |
|
1244 |
|
* connect completion. |
|
1245 |
|
*/ |
|
|
1239 |
|
&& (Conn_ignore(slot) == 0) |
|
1240 |
|
&& (Conns[slot].state == CONN_STATE_CONNECT_b)) { |
|
1241 |
|
Log(12, "\tWe just established a connection.\n"); |
|
1242 |
|
|
|
1243 |
|
if (Conn_oqlen(&Conns[slot]) == 0) { |
|
1244 |
|
/* Nothing to send */ |
1246 |
1245 |
revents &= ~CONN_POLLOUT; |
revents &= ~CONN_POLLOUT; |
1247 |
1246 |
Conns[slot].events &= ~CONN_POLLOUT; |
Conns[slot].events &= ~CONN_POLLOUT; |
1248 |
1247 |
Conn_engine_chg_obj(&Conns[slot]); |
Conn_engine_chg_obj(&Conns[slot]); |
|
1248 |
|
} |
1249 |
1249 |
|
|
1250 |
|
Conns[slot].state = CONN_STATE_OPEN; |
|
|
1250 |
|
Conns[slot].state = CONN_STATE_OPEN; |
1251 |
1251 |
|
|
1252 |
|
Conns[slot].flags |= CONN_ADDR_LOCAL_DIRTY; |
|
|
1252 |
|
Conns[slot].flags |= CONN_ADDR_LOCAL_DIRTY; |
1253 |
1253 |
|
|
1254 |
|
Conns[slot].time_open = Conn_now; |
|
|
1254 |
|
Conns[slot].time_open = Conn_now; |
1255 |
1255 |
|
|
1256 |
|
if (Conns[slot].cb_connected != NULL) |
|
1257 |
|
Conns[slot].cb_connected(&Conns[slot]); |
|
1258 |
|
else if (Conn_connected_cb) |
|
1259 |
|
Conn_connected_cb(&Conns[slot]); |
|
1260 |
|
} |
|
|
1256 |
|
if (Conns[slot].cb_connected != NULL) |
|
1257 |
|
Conns[slot].cb_connected(&Conns[slot]); |
|
1258 |
|
else if (Conn_connected_cb) |
|
1259 |
|
Conn_connected_cb(&Conns[slot]); |
1261 |
1260 |
} |
} |
1262 |
1261 |
|
|
1263 |
|
/* Second, test for error or input */ |
|
|
1262 |
|
/* Second, test for hangup or input */ |
1264 |
1263 |
if ((revents & CONN_POLLIN) |
if ((revents & CONN_POLLIN) |
1265 |
1264 |
&& (Conn_ignore(slot) == 0)) { |
&& (Conn_ignore(slot) == 0)) { |
|
1265 |
|
Log(12, "\tWe have input...\n"); |
1266 |
1266 |
if (Conns[slot].type == CONN_TYPE_MASTER) { |
if (Conns[slot].type == CONN_TYPE_MASTER) { |
1267 |
1267 |
/* C pointer can change under us in Conn_accept->Conn_grow */ |
/* C pointer can change under us in Conn_accept->Conn_grow */ |
1268 |
1268 |
Conn_accept(slot); |
Conn_accept(slot); |
|
... |
... |
static void Conn_poll_cb(const unsigned int slot, int revents) |
1278 |
1278 |
|
|
1279 |
1279 |
if ((revents & CONN_POLLOUT) |
if ((revents & CONN_POLLOUT) |
1280 |
1280 |
&& (Conn_ignore(slot) == 0)) { |
&& (Conn_ignore(slot) == 0)) { |
1281 |
|
/* We can send data */ |
|
|
1281 |
|
Log(12, "\tWe can send data...\n"); |
1282 |
1282 |
if (Conns[slot].state == CONN_STATE_OPEN) { |
if (Conns[slot].state == CONN_STATE_OPEN) { |
1283 |
1283 |
if (Conns[slot].cb_send) |
if (Conns[slot].cb_send) |
1284 |
1284 |
Conns[slot].cb_send(&Conns[slot]); |
Conns[slot].cb_send(&Conns[slot]); |
|
... |
... |
static void Conn_poll_cb(const unsigned int slot, int revents) |
1287 |
1287 |
else |
else |
1288 |
1288 |
Conn_send_cb_i(slot); |
Conn_send_cb_i(slot); |
1289 |
1289 |
|
|
1290 |
|
if (Conns[slot].obuf_head == Conns[slot].obuf_tail) { |
|
|
1290 |
|
if (Conn_oqlen(&Conns[slot]) == 0) { |
1291 |
1291 |
if (Conns[slot].flags & CONN_FLAGS_CLOSE_AFTER_SEND) { |
if (Conns[slot].flags & CONN_FLAGS_CLOSE_AFTER_SEND) { |
1292 |
1292 |
Conns[slot].state = CONN_STATE_ERROR; |
Conns[slot].state = CONN_STATE_ERROR; |
1293 |
1293 |
Conns[slot].error_state = CONN_ERROR_USERREQ; |
Conns[slot].error_state = CONN_ERROR_USERREQ; |
|
... |
... |
int Conn_poll(const int timeout) |
1374 |
1374 |
|
|
1375 |
1375 |
/* Closing connection if it is in error state */ |
/* Closing connection if it is in error state */ |
1376 |
1376 |
if (Conns[slot].error_state > 0) { |
if (Conns[slot].error_state > 0) { |
1377 |
|
Log(11, "\tSlot=%u in error [%s], exchange with pos %u.\n", |
|
|
1377 |
|
Log(11, "\tSlot=%u in error [%s], exchange with slot %u.\n", |
1378 |
1378 |
slot, Conn_errno(&Conns[slot]), last); |
slot, Conn_errno(&Conns[slot]), last); |
1379 |
1379 |
Conn_move_slot(slot, last); |
Conn_move_slot(slot, last); |
1380 |
1380 |
Conn_free_intern(last); |
Conn_free_intern(last); |
|
... |
... |
int Conn_poll(const int timeout) |
1418 |
1418 |
|
|
1419 |
1419 |
/* |
/* |
1420 |
1420 |
* Returns the lifetime of a connection |
* Returns the lifetime of a connection |
|
1421 |
|
* TODO: To be moved in 'core'? |
1421 |
1422 |
*/ |
*/ |
1422 |
1423 |
unsigned long long Conn_lifetime(struct Conn *C) |
unsigned long long Conn_lifetime(struct Conn *C) |
1423 |
1424 |
{ |
{ |