manual testing
This commit is contained in:
parent
1424925cbf
commit
c52712471f
|
@ -14,15 +14,11 @@ jobs:
|
|||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y libbsd-dev cmake build-essential
|
||||
sudo apt-get install -y libbsd-dev build-essential
|
||||
|
||||
- name: Build and test
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
./tests
|
||||
make tests
|
||||
|
||||
docs:
|
||||
runs-on: ubuntu-latest
|
||||
|
|
|
@ -8,3 +8,4 @@ test
|
|||
tcptest
|
||||
testrunner
|
||||
.idea
|
||||
netmanual
|
||||
|
|
5
Makefile
5
Makefile
|
@ -1,4 +1,4 @@
|
|||
.PHONY : clean tests all
|
||||
.PHONY : clean tests all manual
|
||||
|
||||
CFLAGS = -std=c99 -Iinclude -pedantic
|
||||
WARNINGS= -Wall -Wextra
|
||||
|
@ -30,6 +30,7 @@ clean:
|
|||
rm -f $(TARGET)
|
||||
rm -f testrunner
|
||||
rm -f tcptest
|
||||
rm -f netmanual
|
||||
rm -f compile_commands.json
|
||||
|
||||
tests:
|
||||
|
@ -37,3 +38,5 @@ tests:
|
|||
cc $(CFLAGS) -o tcptest tests/tcptest.c src/*.c
|
||||
./run_tests.sh
|
||||
|
||||
manual:
|
||||
cc $(CFLAGS) -o netmanual tests/netmanual.c src/*.c
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
|
@ -115,13 +116,26 @@ void handler_tcp_echo(Server *s) {
|
|||
printf("Received connection from %s\n", buf);
|
||||
|
||||
// Start child process
|
||||
if (!fork()) {
|
||||
close(s->fd); // Child doesn't need the initial socket
|
||||
if (send(new_fd, "Hello, world!", 13, 0) == -1) {
|
||||
fprintf(stderr, "Failed to send hello world\n");
|
||||
}
|
||||
close(new_fd);
|
||||
_exit(0);
|
||||
if (!fork()) {
|
||||
close(s->fd); // Child doesn't need the initial socket
|
||||
|
||||
char recv_buf[256];
|
||||
int r = recv(new_fd, recv_buf, 256, 0);
|
||||
if (r == -1) {
|
||||
fprintf(stderr, "Failed to recv. Errno: %d\n", errno);
|
||||
goto CHILD_END;
|
||||
} else if (r == 0) {
|
||||
fprintf(stderr, "Client closed connection\n");
|
||||
goto CHILD_END;
|
||||
}
|
||||
|
||||
if (send(new_fd, recv_buf, strlen(recv_buf), 0) == -1) {
|
||||
fprintf(stderr, "Failed to send echo\n");
|
||||
}
|
||||
|
||||
CHILD_END:
|
||||
close(new_fd);
|
||||
_exit(0);
|
||||
}
|
||||
// End child process
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "lfnetwork.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
Server *server = new_server(SERVERTYPE_TCP, "18632", handler_tcp_echo);
|
||||
serve(server, DEFAULT_BACKLOG);
|
||||
delete_server(server);
|
||||
}
|
Loading…
Reference in New Issue