Skip to content

Commit

Permalink
ci: fix windows build problem
Browse files Browse the repository at this point in the history
  • Loading branch information
scokmen committed Jul 2, 2024
1 parent b1057ad commit 91a02cb
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 24 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ add_library(snail STATIC
src/core/sn_logger.c
src/core/http/sn_http_code.h
src/core/http/sn_http_code.c
src/internal/unix/sn_attr.h
src/internal/win/sn_attr.h
)

target_include_directories(snail
INTERFACE "${LIBRARY_PATH}"
PRIVATE "${LIBRARY_PATH}/core"
PRIVATE "${LIBRARY_PATH}/core/http")
PRIVATE "${LIBRARY_PATH}/internal")

target_link_libraries(snail pico uv)
########################################################################
Expand Down
6 changes: 3 additions & 3 deletions src/core/http/sn_sock_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ static void on_after_work_callback(uv_work_t *req, int status) {
write_response(loop_data);
}

// TODO: Implement a optimized header-length checker.
static sn_http_code_t check_fail_fast_err(sock_http_data *http_data, int minor_version) {
size_t total_header_size = 0;
if (minor_version != 0 && minor_version != 1) {
Expand All @@ -146,7 +147,6 @@ static sn_http_code_t check_fail_fast_err(sock_http_data *http_data, int minor_v
return HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE;
}
}
sn_log_err("HED: %zu\n", total_header_size);
return -1;
}

Expand Down Expand Up @@ -237,12 +237,12 @@ static void on_read_callback(uv_stream_t *stream, ssize_t buf_size, const uv_buf
return;
}

free(buf->base);

if (req_size == -2) {
free(buf->base);
return;
}

free(buf->base);
uv_read_stop(stream);
fail_fast_code = check_fail_fast_err(http_data, minor_version);

Expand Down
30 changes: 30 additions & 0 deletions src/internal/unix/sn_attr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef SNAIL_SN_ATTR_H
#define SNAIL_SN_ATTR_H

#ifdef __has_attribute
# if __has_attribute (nonstring)
# define SN_BUFFER __attribute__ ((nonstring))
# else
# define SN_BUFFER
# endif
# if __has_attribute (unused)
# define SN_UNUSED __attribute__ ((unused))
# else
# define SN_UNUSED
# endif
# if __has_attribute (always_inline)
# define SN_INLINE __attribute__ ((always_inline))
# else
# define SN_INLINE
# endif
# if __has_attribute (format)
# define SN_FORMAT(FROM) __attribute__ ((format (printf, (FROM), (FROM + 1))))
# endif
#else
# define SN_BUFFER
# define SN_UNUSED
# define SN_INLINE
# define SN_FORMAT
#endif

#endif //SNAIL_SN_ATTR_H
9 changes: 9 additions & 0 deletions src/internal/win/sn_attr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef SNAIL_SN_ATTR_H
#define SNAIL_SN_ATTR_H

#define SN_BUFFER
#define SN_UNUSED
#define SN_INLINE
#define SN_FORMAT

#endif //SNAIL_SN_ATTR_H
23 changes: 4 additions & 19 deletions src/snail.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
#ifndef SNAIL_SNAIL_H
#define SNAIL_SNAIL_H

#if defined __has_attribute
# if __has_attribute (nonstring)
# define SN_BUFFER __attribute__ ((nonstring))
# else
# define SN_BUFFER
# endif
# if __has_attribute (unused)
# define SN_UNUSED __attribute__ ((unused))
# else
# define SN_UNUSED
# endif
# if __has_attribute (always_inline)
# define SN_INLINE __attribute__ ((always_inline))
# else
# define SN_INLINE
# endif
# if __has_attribute (format)
# define SN_FORMAT(FROM) __attribute__ ((format (printf, (FROM), (FROM + 1))))
# endif
#if defined(__GCC__) || defined(__clang__)
#include "internal/unix/sn_attr.h"
#else
#include "internal/unix/sn_attr.h"
#endif

int sn_listen(int port);
Expand Down
6 changes: 5 additions & 1 deletion test/runner/test_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
#include <stdio.h>
#include <stdbool.h>

#if defined __has_attribute
#if (defined(__GCC__) || defined(__clang__)) && defined(__has_attribute)
# if __has_attribute (format)
# define TR_FORMAT(FROM) __attribute__ ((format (printf, (FROM), (FROM + 1))))
# else
# define TR_FORMAT
# endif
#else
# define TR_FORMAT
#endif

#define MAX_CASE_IN_SUIT (32)
Expand Down

0 comments on commit 91a02cb

Please sign in to comment.