improve tcp_send/tcp_recv args

This commit is contained in:
lixianjing 2023-08-28 11:59:57 +08:00
parent 8b174373fe
commit 8b71f8b947
3 changed files with 9 additions and 6 deletions

View File

@ -1,4 +1,4 @@
#include "tkc/platform.h" #include "tkc.h"
#include "streams/inet/iostream_tcp.h" #include "streams/inet/iostream_tcp.h"
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
@ -6,13 +6,14 @@ int main(int argc, char* argv[]) {
int32_t lsock = 0; int32_t lsock = 0;
tk_iostream_t* io = NULL; tk_iostream_t* io = NULL;
const char* response = "200 OK\n"; const char* response = "200 OK\n";
int port = argc > 1 ? tk_atoi(argv[1]) : 8080;
tk_socket_init(); tk_socket_init();
platform_prepare(); platform_prepare();
lsock = tk_tcp_listen(8080); lsock = tk_tcp_listen(port);
return_value_if_fail(lsock > 0, 0); return_value_if_fail(lsock > 0, 0);
log_debug("listen at 8080...\n"); log_debug("listen at %d...\n", port);
while (1) { while (1) {
int32_t sock = 0; int32_t sock = 0;
sock = tk_tcp_accept(lsock); sock = tk_tcp_accept(lsock);

View File

@ -1,4 +1,4 @@
#include "tkc/platform.h" #include "tkc.h"
#include "streams/inet/iostream_tcp.h" #include "streams/inet/iostream_tcp.h"
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
@ -6,10 +6,12 @@ int main(int argc, char* argv[]) {
int32_t sock = 0; int32_t sock = 0;
tk_iostream_t* io = NULL; tk_iostream_t* io = NULL;
const char* request = "GET / HTTP/1.1\r\nHost: localhost\r\n"; const char* request = "GET / HTTP/1.1\r\nHost: localhost\r\n";
const char* host = argc > 1 ? argv[1] : "localhost";
int port = argc > 2 ? tk_atoi(argv[2]) : 8080;
tk_socket_init(); tk_socket_init();
platform_prepare(); platform_prepare();
sock = tk_tcp_connect("localhost", 8080); sock = tk_tcp_connect(host, port);
return_value_if_fail(sock > 0, 0); return_value_if_fail(sock > 0, 0);
io = tk_iostream_tcp_create(sock); io = tk_iostream_tcp_create(sock);

View File

@ -16,4 +16,4 @@ done
cp -rvf ../tkc/src/fscript_ext/*.* src/fscript_ext cp -rvf ../tkc/src/fscript_ext/*.* src/fscript_ext
git checkout scripts/compile_config.py