Skip to content

Commit

Permalink
tests: net: lib: http_server: Add test function for shutdown
Browse files Browse the repository at this point in the history
This test ensures that the server can be shut down
Fixes zephyrproject-rtos#59688

Signed-off-by: Emna Rekik <emna.rekik007@gmail.com>
  • Loading branch information
Emna-Rekik committed Aug 14, 2023
1 parent 90cd9b5 commit 2de2989
Show file tree
Hide file tree
Showing 7 changed files with 366 additions and 189 deletions.
25 changes: 13 additions & 12 deletions include/zephyr/net/http/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,26 @@

#include <zephyr/posix/poll.h>

#define MAX_CLIENTS 10
#define MAX_CLIENTS CONFIG_NET_HTTP2_MAX_CLIENTS

struct http2_server_config {
int port;
int address_family;
};

struct http2_server_ctx {
int sockfd;
struct pollfd client_fds[MAX_CLIENTS];
int num_clients;
struct http2_client_ctx {
struct pollfd pollfds[1];
enum { AWAITING_PREFACE, READING_SETTINGS, STREAMING, CLOSING} state;
};

struct http2_frame {
uint32_t length;
uint8_t type;
uint8_t flags;
uint32_t stream_identifier;
unsigned char *payload;

struct http2_server_ctx {
int server_fd;
int event_fd;
size_t num_clients;
struct pollfd client_fds[MAX_CLIENTS+2];
struct http2_client_ctx clients[MAX_CLIENTS];
int infinite;
};

/* Initializes the HTTP2 server */
Expand All @@ -38,6 +39,6 @@ int http2_server_init(struct http2_server_ctx *ctx,
int http2_server_start(struct http2_server_ctx *ctx);

/* Stops the HTTP2 server */
int http2_server_stop(void);
int http2_server_stop(struct http2_server_ctx *ctx);

#endif
9 changes: 6 additions & 3 deletions samples/net/sockets/http_server/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ CONFIG_MAIN_STACK_SIZE=1536
CONFIG_NEWLIB_LIBC=y

# Enable console
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
#CONFIG_CONSOLE=y
#CONFIG_UART_CONSOLE=y
# Enable shell
CONFIG_SHELL=y
#CONFIG_SHELL=y

# Eventfd
CONFIG_EVENTFD=y

# Networking config
CONFIG_NETWORKING=y
Expand Down
1 change: 0 additions & 1 deletion samples/net/sockets/http_server/src/headers/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#define MAX_CLIENTS 10
#define BUFFER_SIZE 256
#define MAX_URL_LENGTH 128
#define MAX_FRAME_SIZE 2048
Expand Down
24 changes: 18 additions & 6 deletions samples/net/sockets/http_server/src/headers/server_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,29 @@

#include <zephyr/net/http/parser.h>

struct http2_frame {
uint32_t length;
uint8_t type;
uint8_t flags;
uint32_t stream_identifier;
unsigned char *payload;
};

int on_url(struct http_parser *parser, const char *at, size_t length);
ssize_t sendall(int sock, const void *buf, size_t len);
void close_client_connection(struct http2_server_ctx *ctx, int clientIndex);
int accept_new_client(int server_fd);
void handle_http1_request(struct http2_server_ctx *ctx, int i);
void handle_http2_request(struct http2_server_ctx *ctx, int i, int valread);
void handle_http1_request(struct http2_server_ctx *ctx, int i, int *valread);
void handle_http2_request(struct http2_server_ctx *ctx, int i, int *valread);
int on_header_field(struct http_parser *parser, const char *at, size_t length);
void generate_response_headers_frame(unsigned char *response_headers_frame, int new_stream_id);
void sendData(int socket_fd, const char *payload, size_t length, uint8_t type, uint8_t flags, uint32_t streamId);
void generate_response_headers_frame(
unsigned char *response_headers_frame, int new_stream_id);
void sendData(int socket_fd, const char *payload, size_t length, uint8_t type,
uint8_t flags, uint32_t streamId);
void print_http2_frames(struct http2_frame *frames, unsigned int frame_count);
unsigned int parse_http2_frames(unsigned char *buffer, unsigned long buffer_len, struct http2_frame *frames);
int find_headers_frame_stream_id(struct http2_frame *frames, unsigned int frame_count);
unsigned int parse_http2_frames(unsigned char *buffer, unsigned long buffer_len,
struct http2_frame *frames);
int find_headers_frame_stream_id(
struct http2_frame *frames, unsigned int frame_count);

#endif
Loading

0 comments on commit 2de2989

Please sign in to comment.