Mercurial
diff seobeo/s_linux_network.c @ 67:6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Wed, 24 Dec 2025 09:15:55 -0800 |
| parents | a0f0ad5e42eb |
| children | 75de5903355c |
line wrap: on
line diff
--- a/seobeo/s_linux_network.c Wed Dec 24 06:34:19 2025 -0800 +++ b/seobeo/s_linux_network.c Wed Dec 24 09:15:55 2025 -0800 @@ -105,30 +105,17 @@ p_handle->socket = socket_fd; p_handle->type = SEOBEO_STREAM_TYPE_CLIENT; + + p_handle->ssl_ctx = NULL; + p_handle->ssl = NULL; + if (use_tls) { - printf("USE SSL\n\n"); - Seobeo_Web_SSL_Init(); - p_handle->ssl_ctx = SSL_CTX_new(TLS_client_method()); - SSL_CTX_set_default_verify_paths(p_handle->ssl_ctx); - - p_handle->ssl = SSL_new(p_handle->ssl_ctx); - SSL_set_fd(p_handle->ssl, p_handle->socket); - - SSL_set_tlsext_host_name(p_handle->ssl, host); - // Blocking for TSL handshake - fcntl(socket_fd, F_SETFL, 0); - - if (SSL_connect(p_handle->ssl) != 1) + if (Seobeo_SSL_Setup_Client(p_handle, host, socket_fd) != 0) { - fprintf(stderr, "SSL_connect failed\n"); - ERR_print_errors_fp(stderr); + free(p_handle); return NULL; } - }else - { - p_handle->ssl_ctx = NULL; - p_handle->ssl = NULL; } p_handle->connected = true; @@ -212,18 +199,7 @@ if (p_handle->host) Dowa_Free(p_handle->host); if (p_handle->port) Dowa_Free(p_handle->port); - if (p_handle->ssl) - { - SSL_shutdown(p_handle->ssl); - SSL_free(p_handle->ssl); - p_handle->ssl = NULL; - } - - if (p_handle->ssl_ctx) - { - SSL_CTX_free(p_handle->ssl_ctx); - p_handle->ssl_ctx = NULL; - } + Seobeo_SSL_Cleanup(p_handle); if (p_handle->socket) { printf("Closing: %d", p_handle->socket); @@ -248,18 +224,9 @@ { if (p_handle->ssl) { - int n = SSL_write(p_handle->ssl, p_handle->write_buffer + sent, total - sent); - if (n < 0) - { - int err = SSL_get_error(p_handle->ssl, n); - if (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE) - { - // caller must wait for socket readiness and retry - return 0; - } - ERR_print_errors_fp(stderr); - return -1; - } + int n = Seobeo_SSL_Write(p_handle, p_handle->write_buffer + sent, total - sent); + if (n < 0) return -1; + if (n == 0) return 0; // would block sent += (uint32)n; }else { @@ -364,22 +331,9 @@ if (p_handle->ssl) { - read_size = (int32)SSL_read(p_handle->ssl, p_handle->read_buffer, - free_space); - if (read_size <= 0) - { - int err = SSL_get_error(p_handle->ssl, read_size); - switch (err) - { - case SSL_ERROR_WANT_READ: - case SSL_ERROR_WANT_WRITE: - return 0; - case SSL_ERROR_ZERO_RETURN: - default: - // TODO: Handle these errors - return -2; - } - } + read_size = Seobeo_SSL_Read(p_handle, p_handle->read_buffer + p_handle->read_buffer_len, free_space); + if (read_size < 0) return read_size; // -1 for error, -2 for closed + if (read_size == 0) return 0; // would block }else { read_size = (int32)read(p_handle->socket,