Skip to content

Commit

Permalink
Merge pull request #3 from teonet-co/feature/add-trudp-lib
Browse files Browse the repository at this point in the history
Feature/add trudp lib
  • Loading branch information
angelskieglazki authored Jun 27, 2019
2 parents 8fcaf3e + 59a4fcb commit 596e5f0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
22 changes: 19 additions & 3 deletions libteol0/teonet_l0_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,17 @@ ssize_t _teosockSend(teoLNullConnectData *con, const char* data, size_t length)
if (con->tcp_f) {
return teosockSend(con->fd, data, length);
} else {
return trudpChannelSendData(con->tcd, (void *) data, length);
// return trudpChannelSendData(con->tcd, (void *) data, length);

ssize_t send_size = 0;
for(;;) {
size_t len = length > 512 ? 512 : length;
send_size += trudpChannelSendData(con->tcd, (void *)data, len);
length -= len;
if(!length) break;
data += len;
}
return send_size;
}
}

Expand Down Expand Up @@ -1000,7 +1010,13 @@ static void trudpEventCback(void *tcd_pointer, int event, void *data, size_t dat
char *addr = trudpUdpGetAddr((__CONST_SOCKADDR_ARG)&tcd->remaddr, &port);
if(!(type = trudpPacketGetType(data))) {
teoLNullCPacket *cp = trudpPacketGetData(data);
debug(tru, DEBUG, "send %d bytes, id=%u, to %s:%d, %.3f(%.3f) ms, peer: %s, cmd: %d, data: %s\n",
debug(tru, DEBUG, "send %d bytes, id=%u, to %s:%d, data: %s\n",
(int)data_length,
id,
addr,
port,
(cp->data_length) ? cp->peer_name + cp->peer_name_length : "empty data");
/* debug(tru, DEBUG, "send %d bytes, id=%u, to %s:%d, %.3f(%.3f) ms, peer: %s, cmd: %d, data: %s\n",
(int)data_length,
id,
addr,
Expand All @@ -1010,7 +1026,7 @@ static void trudpEventCback(void *tcd_pointer, int event, void *data, size_t dat
cp->peer_name,
cp->cmd,
(cp->data_length) ? cp->peer_name + cp->peer_name_length : "empty data");
}
*/ }
}
#ifdef DEBUG_MSG
debug(tru, DEBUG, "send %d bytes %s id=%u, to %s:%d\n",
Expand Down
11 changes: 6 additions & 5 deletions main_select_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ void event_cb(void *con, teoLNullEvents event, void *data,
//
// Add current time to the end of message (it should be return
// back by server)
snd = teoLNullSendEcho(con, param->peer_name, param->msg);
/* snd = teoLNullSendEcho(con, param->peer_name, param->msg);
if(snd == -1) perror(strerror(errno));
printf("Send %d bytes packet to L0 server to peer %s, "
"cmd = %d (CMD_L_ECHO), "
"data: %s\n",
(int)snd, param->peer_name, CMD_L_ECHO, param->msg);

*/
// Show empty line
printf("\n");

Expand Down Expand Up @@ -238,7 +238,7 @@ int main(int argc, char** argv) {
exit(EXIT_SUCCESS);
}

const int send_size = 100;
const int send_size = 3000;
char *send_msg = malloc(send_size);
int i = 0;
for (i = 0; i<send_size; ++i)
Expand All @@ -251,7 +251,7 @@ int main(int argc, char** argv) {
param.peer_name = argv[4]; //"teostream";
if(argc > 5) param.msg = argv[5];
else param.msg = send_msg;
param.tcp_f = 1;
param.tcp_f = 0;

// Initialize L0 Client library
teoLNullInit();
Expand All @@ -270,6 +270,7 @@ int main(int argc, char** argv) {
// Event loop
while(teoLNullReadEventLoop(con, timeout) && !quit_flag) {


// Send Echo command every second
if( !(num % (1000 / timeout)) )
teoLNullSendEcho(con, param.peer_name, param.msg);
Expand All @@ -284,7 +285,7 @@ int main(int argc, char** argv) {

//quit_flag = 1;
}

close_con:
// Cleanup L0 Client library
teoLNullCleanup();
free(send_msg);
Expand Down

0 comments on commit 596e5f0

Please sign in to comment.