Skip to content

Commit

Permalink
修复Windows编译的问题。
Browse files Browse the repository at this point in the history
将Windows CI单独拿出来。在Windows环境下编译需要在cmake的时候增加-DWIN32=ON参数。
  • Loading branch information
zxm256 authored Apr 20, 2024
1 parent 6f87088 commit 350e91a
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 5 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/cmake-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: CMake-windows

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release

jobs:
build:

runs-on: windows-latest

steps:
- uses: actions/checkout@v3

- name: Configure build for x86
uses: ilammy/msvc-dev-cmd@v1
with:
arch: amd64_x86

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}\build -G "NMake Makefiles" -DWIN32=ON;

- name: Build
working-directory: ${{github.workspace}}\build
# Build your program with the given configuration
run: nmake

- name: Test
working-directory: ${{github.workspace}}\build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest --rerun-failed --output-on-failure -C ${{env.BUILD_TYPE}}
2 changes: 1 addition & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
strategy:
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
os: [ ubuntu-latest, macos-latest ]
runs-on: ${{ matrix.os }}

steps:
Expand Down
9 changes: 8 additions & 1 deletion src/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -2320,7 +2320,13 @@ void tls_cleanup(TLS_CONNECT *conn)
int tls_set_socket(TLS_CONNECT *conn, tls_socket_t sock)
{
int flags;

#ifdef WIN32
if( ioctlsocket(sock, FIONBIO, &flags) != 0) {
error_puts("socket in non-blocking mode");
//nginx will pass a socket in non-blocking mode
//return -1;
}
#else
if ((flags = fcntl(sock, F_GETFL)) == -1) {
error_print();
perror("fcntl error");
Expand All @@ -2331,6 +2337,7 @@ int tls_set_socket(TLS_CONNECT *conn, tls_socket_t sock)
//nginx will pass a socket in non-blocking mode
//return -1;
}
#endif
conn->sock = sock;
return 1;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/sm9test.c
Original file line number Diff line number Diff line change
Expand Up @@ -757,8 +757,8 @@ int test_sm9_z256_exchange()
uint8_t idA[5] = {0x41, 0x6C, 0x69, 0x63, 0x65};
uint8_t idB[3] = {0x42, 0x6F, 0x62};
size_t klen = 0x10;
uint8_t skA[200] = {}, skB[200] = {};

uint8_t skA[200];
uint8_t skB[200];
sm9_z256_from_hex(msk.ke, hex_kex);
sm9_z256_point_mul_generator(&(msk.Ppube), msk.ke);
if (sm9_exch_master_key_extract_key(&msk, (char *)idA, sizeof(idA), &keyA) < 0) goto err; ++j;
Expand Down
9 changes: 8 additions & 1 deletion tools/tlcp_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,21 @@ int tlcp_client_main(int argc, char *argv[])
FD_ZERO(&fds);
FD_SET(conn.sock, &fds);
if (read_stdin)
#ifdef WIN32
FD_SET(_fileno, &fds);
#else
FD_SET(STDIN_FILENO, &fds);

#endif
if (select(conn.sock + 1, &fds, NULL, NULL, NULL) < 0) {
fprintf(stderr, "%s: select error\n", prog);
goto end;
}

#ifdef WIN32
if (read_stdin && FD_ISSET(_fileno, &fds)) {
#else
if (read_stdin && FD_ISSET(STDIN_FILENO, &fds)) {
#endif

if (fgets(buf, sizeof(buf), stdin)) {
if (tls_send(&conn, (uint8_t *)buf, strlen(buf), &len) != 1) {
Expand Down

0 comments on commit 350e91a

Please sign in to comment.