network

low level network subjects
Log | Files | Refs | Submodules | README | git clone https://git.ne02ptzero.me/git/network

commit 8ce937806f36f98e02eeec2a5c028d6087664728
parent 13cbda83f09f8e79a07dc096a1922868bfce6462
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Fri, 17 Mar 2017 17:53:30 +0100

Add(Better functions)

Diffstat:
Minc/package.h | 1+
Msrc/client_test.c | 18+++++++++++++++---
Msrc/read_package.c | 1+
3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/inc/package.h b/inc/package.h @@ -158,6 +158,7 @@ typedef struct resp_cat_s { } SF_PACKED resp_cat_t; void *write_package(package_t *pkg, size_t *size); +package_t *read_pkg(void *data); void *pkg_build_auth(size_t *size, int major_version, int minor_version); #endif /* PACKAGE_H */ diff --git a/src/client_test.c b/src/client_test.c @@ -22,17 +22,28 @@ TEST(connect_1) { return TEST_SUCCESS; } -TEST(pkg_auth_1) { +TEST(pkg_auth_1_write) { size_t size; void *ret; TEST_ASSERT(sockfd, "Server is not responding"); - ret = pkg_build_auth(&size, 0, 1); + ret = pkg_build_auth(&size, 1, 0); TEST_ASSERT(write(sockfd, ret, size) != 0, "Cannot send package to the server"); return TEST_SUCCESS; } +TEST(pkg_auth_1_read) { + void *ret; + package_t *pkg; + + ret = malloc(2048); + read(sockfd, ret, 2048); + pkg = read_pkg(ret); + TEST_ASSERT(pkg, "Can't read package"); + return TEST_SUCCESS; +} + TEST(cleanup) { TEST_ASSERT(close(sockfd) != -1, "Cannot close socket"); return TEST_SUCCESS; @@ -40,7 +51,8 @@ TEST(cleanup) { void begin_client_test(void) { reg_test("connect", connect_1); - reg_test("auth", pkg_auth_1); + reg_test("auth", pkg_auth_1_write); + reg_test("auth", pkg_auth_1_read); reg_test("clean", cleanup); test_all(); test_free(); diff --git a/src/read_package.c b/src/read_package.c @@ -4,6 +4,7 @@ static size_t read_header(package_t *pkg, void *data) { size_t count = 0; read_member(pkg->type); + printf("%d\n", pkg->type); read_member(pkg->size); read_member(pkg->next_pkg_len);