Skip to content

Commit a1d830f

Browse files
committed
apple: allow for updated mbedtls library
1 parent 699b808 commit a1d830f

4 files changed

Lines changed: 59 additions & 20 deletions

File tree

griffin/griffin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1637,11 +1637,11 @@ SSL
16371637
#include "../deps/mbedtls/ssl_srv.c"
16381638
#include "../deps/mbedtls/ssl_ticket.c"
16391639
#include "../deps/mbedtls/ssl_tls.c"
1640+
#endif
16401641

16411642
#include "../libretro-common/net/net_socket_ssl_mbed.c"
16421643
#endif
16431644
#endif
1644-
#endif
16451645

16461646
/*============================================================
16471647
PLAYLIST NAME SANITIZATION

libretro-common/net/net_http.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ struct http_t *net_http_new(struct http_connection_t *conn)
838838
state->request.port = conn->port;
839839

840840
state->response.status = -1;
841-
state->response.buflen = 16 * 1024;
841+
state->response.buflen = 64 * 1024; /* Start with larger buffer to reduce reallocations */
842842
state->response.data = (char*)malloc(state->response.buflen);
843843
state->response.headers = string_list_new();
844844

@@ -1391,7 +1391,7 @@ static bool net_http_redirect(struct http_t *state, const char *location)
13911391
state->request_sent = false;
13921392
state->response.part = P_HEADER_TOP;
13931393
state->response.status = -1;
1394-
state->response.buflen = 16 * 1024;
1394+
state->response.buflen = 64 * 1024; /* Start with larger buffer to reduce reallocations */
13951395
state->response.data = (char*)realloc(state->response.data, state->response.buflen);
13961396
state->response.pos = 0;
13971397
state->response.len = 0;

libretro-common/net/net_socket_ssl_mbed.c

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -195,26 +195,61 @@ ssize_t ssl_socket_receive_all_nonblocking(void *state_data,
195195
{
196196
ssize_t ret;
197197
struct ssl_state *state = (struct ssl_state*)state_data;
198-
const uint8_t *data = (const uint8_t*)data_;
199-
/* mbedtls_ssl_read wants non-const data but it only reads it, so this cast is safe */
198+
unsigned char *data = (unsigned char*)data_;
199+
size_t total_read = 0;
200+
int max_iterations = 8; /* Limit iterations to prevent infinite loops */
200201

201202
mbedtls_net_set_nonblock(&state->net_ctx);
202203

203-
if ((ret = mbedtls_ssl_read(&state->ctx, (unsigned char*)data, len)) > 0)
204-
return ret;
205-
206-
if (ret == 0)
204+
/* Keep reading while we get data without blocking, up to max iterations
205+
* This allows us to read multiple TLS records (16KB each) in one call */
206+
while (len > 0 && max_iterations-- > 0)
207207
{
208-
/* Socket closed */
209-
*err = true;
210-
return -1;
211-
}
208+
ret = mbedtls_ssl_read(&state->ctx, data, len);
212209

213-
if (isagain((int)ret) || ret == MBEDTLS_ERR_SSL_WANT_READ)
214-
return 0;
210+
if (ret > 0)
211+
{
212+
total_read += ret;
213+
data += ret;
214+
len -= ret;
215+
216+
/* If we read less than requested, there's likely no more data available
217+
* But check if there's buffered data we can read without blocking */
218+
if ((size_t)ret < len)
219+
{
220+
size_t bytes_avail = mbedtls_ssl_get_bytes_avail(&state->ctx);
221+
if (bytes_avail == 0)
222+
223+
break; /* No more buffered data, don't risk blocking */
224+
}
225+
/* Continue looping to read more records */
226+
}
227+
else if (ret == 0)
228+
{
229+
/* Socket closed */
230+
if (total_read > 0)
231+
return total_read; /* Return what we got before close */
232+
*err = true;
233+
return -1;
234+
}
235+
else if (isagain((int)ret) || ret == MBEDTLS_ERR_SSL_WANT_READ)
236+
{
237+
/* Would block - return what we have so far */
238+
if (total_read > 0)
239+
return total_read;
240+
return 0; /* No data available yet */
241+
}
242+
else
243+
{
244+
/* Error */
245+
if (total_read > 0)
246+
return total_read; /* Return what we got before error */
247+
*err = true;
248+
return -1;
249+
}
250+
}
215251

216-
*err = true;
217-
return -1;
252+
return total_read;
218253
}
219254

220255
int ssl_socket_receive_all_blocking(void *state_data,

pkg/apple/BaseConfig.xcconfig

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ OTHER_CFLAGS = $(inherited) -DHAVE_AL
1212
OTHER_CFLAGS = $(inherited) -DHAVE_AUDIOMIXER
1313
OTHER_CFLAGS = $(inherited) -DHAVE_BSV_MOVIE
1414
OTHER_CFLAGS = $(inherited) -DHAVE_BUILTINGLSLANG
15-
OTHER_CFLAGS = $(inherited) -DHAVE_BUILTINMBEDTLS
15+
// Define HAVE_BUILTINMBEDTLS by default (overridden by deps.xcconfig when present)
16+
MBEDTLS_BUILTIN_FLAG = -DHAVE_BUILTINMBEDTLS
17+
OTHER_CFLAGS = $(inherited) $(MBEDTLS_BUILTIN_FLAG)
1618
OTHER_CFLAGS = $(inherited) -DHAVE_CC_RESAMPLER
1719
OTHER_CFLAGS = $(inherited) -DHAVE_CHD
1820
OTHER_CFLAGS = $(inherited) -DHAVE_CHEATS
@@ -127,10 +129,12 @@ OTHER_CFLAGS_IOS_TVOS_SHARE = $(inherited) -DIOS
127129
OTHER_CFLAGS_IOS_TVOS_SHARE = $(inherited) -DPACKAGE_VERSION=\"$(MARKETING_VERSION)\"
128130
OTHER_CFLAGS_IOS_TVOS_SHARE = $(inherited) -DRARCH_MOBILE
129131

132+
OTHER_CFLAGS_SIMULATORS = $(inherited) -DZSTD_DISABLE_ASM
133+
130134
OTHER_CFLAGS[sdk=iphoneos*] = $(inherited) $(OTHER_CFLAGS_IOS_TVOS_SHARE)
131-
OTHER_CFLAGS[sdk=iphonesimulator*] = $(inherited) $(OTHER_CFLAGS_IOS_TVOS_SHARE)
135+
OTHER_CFLAGS[sdk=iphonesimulator*] = $(inherited) $(OTHER_CFLAGS_IOS_TVOS_SHARE) $(OTHER_CFLAGS_SIMULATORS)
132136
OTHER_CFLAGS[sdk=appletvos*] = $(inherited) $(OTHER_CFLAGS_IOS_TVOS_SHARE)
133-
OTHER_CFLAGS[sdk=appletvsimulator*] = $(inherited) $(OTHER_CFLAGS_IOS_TVOS_SHARE)
137+
OTHER_CFLAGS[sdk=appletvsimulator*] = $(inherited) $(OTHER_CFLAGS_IOS_TVOS_SHARE) $(OTHER_CFLAGS_SIMULATORS)
134138

135139
OTHER_CFLAGS_IOS = $(inherited) -DHAVE_AVF
136140
OTHER_CFLAGS_IOS = $(inherited) -DHAVE_COREMIDI

0 commit comments

Comments
 (0)