summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton <anton@picapica>2016-09-23 19:01:43 +0400
committerAnton <anton@picapica>2016-09-23 19:01:43 +0400
commit637eb86df1027d0e47bd7a801f7f9c5324bb6b01 (patch)
treed95df2223775b89ee7f5ea8acc85e74b109610ef
parentd73440f78e5cd662b8938fe730ba9c4176b91e85 (diff)
downloadpica-pica-637eb86df1027d0e47bd7a801f7f9c5324bb6b01.tar.gz
pica-pica-637eb86df1027d0e47bd7a801f7f9c5324bb6b01.zip
added timeout handling to process_c2c(); removed unused obsolete functions
-rw-r--r--PICA_client.c137
-rw-r--r--PICA_client.h4
2 files changed, 7 insertions, 134 deletions
diff --git a/PICA_client.c b/PICA_client.c
index 679c8d2..54047e6 100644
--- a/PICA_client.c
+++ b/PICA_client.c
@@ -1838,6 +1838,11 @@ static int process_c2c(struct PICA_c2c *c2c, fd_set *rfds, fd_set *wfds)
break;
}
+ if (c2c->state != PICA_C2C_STATE_ACTIVE && (time(0) - c2c->timestamp) > PICA_C2C_ACTIVATE_TIMEOUT)
+ {
+ ret = PICA_ERRTIMEDOUT;
+ }
+
if (ret != PICA_OK)
{
if (c2c->state > PICA_C2C_STATE_NEW && c2c->state < PICA_C2C_STATE_ACTIVE)
@@ -2001,138 +2006,6 @@ int PICA_event_loop(struct PICA_c2n **connections, struct PICA_listener **listen
return PICA_OK;
}
-int PICA_read(struct PICA_c2n *ci, int timeout)
-{
- fd_set fds;
- struct timeval tv = {0, 1000};
- struct PICA_c2c *ipt, *kill_ptr = 0;
- int ret, nfds;
-
-//puts("PICA_read<<");//debug
-
- tv.tv_usec = timeout;
-
- FD_ZERO(&fds);
-
- nfds = ci->sck_comm;
- FD_SET(ci->sck_comm, &fds);
-
- ipt = ci->chan_list_head;
-
- while(ipt)
- {
- if (ipt->state == PICA_C2C_STATE_ACTIVE)
- {
- FD_SET(ipt->sck_data, &fds);
-
- if (ipt->sck_data > nfds)
- nfds = ipt->sck_data;
- }
-
- if (ipt->state != PICA_C2C_STATE_ACTIVE && (time(0) - ipt->timestamp) > PICA_CHAN_ACTIVATE_TIMEOUT)
- {
- kill_ptr = ipt;
- }
-
- ipt = ipt->next;
-
- if (kill_ptr)
- {
- PICA_close_c2c(kill_ptr);
- kill_ptr = 0;
- }
- }
-
-//#warning "make sockets non-blocking!!!!"
-
- ret = select(nfds + 1, &fds, 0, 0, &tv);
-
- if (ret > 0)
- {
-
- if (FD_ISSET(ci->sck_comm, &fds))
- {
- ret = PICA_read_c2n(ci);
- if (ret != PICA_OK)
- return ret;
- }
-
- ipt = ci->chan_list_head;
- while(ipt)
- {
- if (ipt->state == PICA_C2C_STATE_ACTIVE && FD_ISSET(ipt->sck_data, &fds))
- {
- if (PICA_OK != (ret = PICA_read_c2c(ipt)) )
- {
- puts("PICA_read_c2c() failed");//debug
- callbacks.c2c_closed_cb(ipt->peer_id, ret);
- kill_ptr = ipt;
- }
-
- }
-
- ipt = ipt->next;
-
- if (kill_ptr)
- {
- PICA_close_c2c(kill_ptr);
- kill_ptr = 0;
- }
- }
-
- }
-//puts("PICA_read>>");//debug
-
- return PICA_OK;
-}
-
-int PICA_write(struct PICA_c2n *ci)
-{
- struct PICA_c2c *ipt, *kill_ptr = 0;
- int ret = PICA_OK;
-
-//puts("PICA_write>>");//debug
-
- if (ci->write_pos)
- ret = PICA_write_c2n(ci);
-
- if (PICA_OK != ret)
- return ret;
-
- ipt = ci->chan_list_head;
-
- while(ipt)
- {
- if (ipt->write_pos)
- {
- if (PICA_OK != (ret = PICA_write_c2c(ipt)))
- {
- fprintf(stderr, "PICA_write_c2c() failed, ret = %i\n", ret); //debug
- callbacks.c2c_closed_cb(ipt->peer_id, ret);
- kill_ptr = ipt;
- }
- }
- else if (ipt->sendfilestate == PICA_CHANSENDFILESTATE_SENDING)
- {
- if (PICA_OK != (ret = PICA_send_file_fragment(ipt)))
- {
- callbacks.c2c_closed_cb(ipt->peer_id, ret);
- kill_ptr = ipt;
- }
- }
- ipt = ipt->next;
-
- if (kill_ptr)
- {
- PICA_close_c2c(kill_ptr);
- kill_ptr = 0;
- }
- }
-
-//puts("PICA_write<<");//debug
- return PICA_OK;
-}
-
int PICA_write_socket(SOCKET s, unsigned char *buf, unsigned int *ppos)
{
int ret;
diff --git a/PICA_client.h b/PICA_client.h
index 2fad713..cefa9c3 100644
--- a/PICA_client.h
+++ b/PICA_client.h
@@ -89,6 +89,7 @@ typedef unsigned __int64 uint64_t;
#define PICA_ERRINVPKEYPASSPHRASE -22
#define PICA_ERRINVPKEYFILE -23
+#define PICA_ERRTIMEDOUT -24
//#define PICA_CHNMSGBUFLEN 104
@@ -108,7 +109,7 @@ typedef unsigned __int64 uint64_t;
#define PICA_CHANRECVFILESTATE_PAUSED 25
#define PICA_CHANRECVFILESTATE_WAITACCEPT 26
-#define PICA_CHAN_ACTIVATE_TIMEOUT 30
+#define PICA_C2C_ACTIVATE_TIMEOUT 30
#define PICA_c2c_INCOMING 0
@@ -320,7 +321,6 @@ int PICA_write(struct PICA_c2n *ci);
int PICA_event_loop(struct PICA_c2n **connections, struct PICA_listener **listeners, int timeout);
int PICA_send_msg(struct PICA_c2c *chn, char *buf, unsigned int len);
-int PICA_read_msg(struct PICA_c2c *chn, char *buf, unsigned int *n);
//filename - ASCII or UTF-8 encoded string
int PICA_send_file(struct PICA_c2c *chn, const char *filepath);