Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
kehengzhong authored Jul 24, 2024
1 parent d24e7e6 commit 87d96e0
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions sample/echosrv/echosrv.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003-2020 Ke Hengzhong <[email protected]>
* Copyright (c) 2003-2024 Ke Hengzhong <[email protected]>
* All rights reserved.
*/

Expand Down Expand Up @@ -45,21 +45,29 @@ int main (int argc, char ** argv)
signal(SIGTERM, signal_handler); /* catch kill signal */
signal(SIGINT, signal_handler); /* catch SIGINT signal */

gpcore = pcore = epcore_new(65536, 1);
if (argc > 1 && argv[1])
listenport = (int)strtol(argv[1], NULL, 10);
if (listenport < 10 || listenport > 65535)
listenport = 8080;

gpcore = pcore = epcore_new(65536);

/* do some initialization */
mlisten = eptcp_mlisten(pcore, NULL, listenport, NULL, echo_pump, pcore);
mlisten = eptcp_mlisten(pcore, NULL, listenport,
NULL, /* socket option */
NULL, /* given listen-device parameter */
echo_pump, pcore);
if (!mlisten) goto exit;

printf("EchoSrv TCP Port: %d being listened\n\n", listenport);

iotimer_start(pcore, 90*1000, 1001, NULL, echo_pump, pcore);
iotimer_start(pcore, 90*1000, 1001, NULL, echo_pump, pcore, 0);

/* start 2 worker threads */
epcore_start_worker(pcore, 2);
//epcore_start_worker(pcore, 2);

/* start 1 epump threads */
epcore_start_epump(pcore, 1);
/* start 2 epump threads */
epcore_start_epump(pcore, 2);

/* main thread executing the epump_main_proc as an epump thread */
epump_main_start(pcore, 0);
Expand Down Expand Up @@ -91,7 +99,11 @@ int echo_pump (void * vpcore, void * vobj, int event, int fdtype)
return -1;

while (1) {
pdev = eptcp_accept(iodev_epcore(vobj), vobj, NULL, &ret, echo_pump, pcore, BIND_ONE_EPUMP);
pdev = eptcp_accept(iodev_epcore(vobj), vobj,
NULL, /* socket option */
NULL, /* accepted device parameter */
echo_pump, pcore, BIND_ONE_EPUMP,
0, &ret);
if (!pdev) break;

printf("\nThreadID=%lu, ListenFD=%d EPumpID=%lu WorkerID=%lu "
Expand Down Expand Up @@ -136,8 +148,8 @@ int echo_pump (void * vpcore, void * vobj, int event, int fdtype)
printf("\nThreadID=%lu IOTimerID=%lu EPumpID=%lu timeout, curtick=%lu\n",
get_threadid(), iotimer_id(vobj),
epumpid(iotimer_epump(vobj)), time(0));
epcore_print(pcore);
iotimer_start(pcore, 90*1000, 1001, NULL, echo_pump, pcore);
epcore_print(pcore, NULL, stdout);
iotimer_start(pcore, 90*1000, 1001, NULL, echo_pump, pcore, 0);
}
break;

Expand Down

0 comments on commit 87d96e0

Please sign in to comment.