socket: automatically detect and use latest bsdsockets version (fix #551)

This commit is contained in:
fincs 2023-10-27 23:46:40 +02:00
parent 9439b39631
commit 1bb5a21453
No known key found for this signature in database
GPG Key ID: 62C7609ADA219C60
2 changed files with 23 additions and 5 deletions

View File

@ -10,8 +10,6 @@ typedef enum {
/// Configuration structure for socketInitalize /// Configuration structure for socketInitalize
typedef struct { typedef struct {
u32 bsdsockets_version; ///< Observed 1 on 2.0 LibAppletWeb, 2 on 3.0.
u32 tcp_tx_buf_size; ///< Size of the TCP transfer (send) buffer (initial or fixed). u32 tcp_tx_buf_size; ///< Size of the TCP transfer (send) buffer (initial or fixed).
u32 tcp_rx_buf_size; ///< Size of the TCP receive buffer (initial or fixed). u32 tcp_rx_buf_size; ///< Size of the TCP receive buffer (initial or fixed).
u32 tcp_tx_buf_max_size; ///< Maximum size of the TCP transfer (send) buffer. If it is 0, the size of the buffer is fixed to its initial value. u32 tcp_tx_buf_max_size; ///< Maximum size of the TCP transfer (send) buffer. If it is 0, the size of the buffer is fixed to its initial value.

View File

@ -62,8 +62,6 @@ static const devoptab_t g_socketDevoptab = {
}; };
static const SocketInitConfig g_defaultSocketInitConfig = { static const SocketInitConfig g_defaultSocketInitConfig = {
.bsdsockets_version = 1,
.tcp_tx_buf_size = 0x8000, .tcp_tx_buf_size = 0x8000,
.tcp_rx_buf_size = 0x10000, .tcp_rx_buf_size = 0x10000,
.tcp_tx_buf_max_size = 0x40000, .tcp_tx_buf_max_size = 0x40000,
@ -82,13 +80,35 @@ const SocketInitConfig *socketGetDefaultInitConfig(void) {
return &g_defaultSocketInitConfig; return &g_defaultSocketInitConfig;
} }
static u32 socketSelectVersion(void) {
if (hosversionBefore(3,0,0)) {
return 1;
} else if (hosversionBefore(4,0,0)) {
return 2;
} else if (hosversionBefore(5,0,0)) {
return 3;
} else if (hosversionBefore(6,0,0)) {
return 4;
} else if (hosversionBefore(8,0,0)) {
return 5;
} else if (hosversionBefore(9,0,0)) {
return 6;
} else if (hosversionBefore(13,0,0)) {
return 7;
} else if (hosversionBefore(16,0,0)) {
return 8;
} else /* latest known version */ {
return 9;
}
}
Result socketInitialize(const SocketInitConfig *config) { Result socketInitialize(const SocketInitConfig *config) {
Result ret = 0; Result ret = 0;
if (!config) if (!config)
config = &g_defaultSocketInitConfig; config = &g_defaultSocketInitConfig;
BsdInitConfig bcfg = { BsdInitConfig bcfg = {
.version = config->bsdsockets_version, .version = socketSelectVersion(),
.tcp_tx_buf_size = config->tcp_tx_buf_size, .tcp_tx_buf_size = config->tcp_tx_buf_size,
.tcp_rx_buf_size = config->tcp_rx_buf_size, .tcp_rx_buf_size = config->tcp_rx_buf_size,