ws: make retry logic in ws_get_protocol_catalog() more readable

This commit is contained in:
Bert Belder 2018-06-04 23:06:37 -07:00
parent 513410278d
commit 49146ab381
No known key found for this signature in database
GPG Key ID: 7A77887B2E2ED461

View File

@ -49,22 +49,21 @@ int ws_get_protocol_catalog(WSAPROTOCOL_INFOW** infos_out,
int count;
WSAPROTOCOL_INFOW* infos;
for (;;) {
infos = malloc(buffer_size);
if (infos == NULL)
return_set_error(-1, ERROR_NOT_ENOUGH_MEMORY);
retry:
infos = malloc(buffer_size);
if (infos == NULL)
return_set_error(-1, ERROR_NOT_ENOUGH_MEMORY);
count = WSAEnumProtocolsW(NULL, infos, &buffer_size);
if (count == SOCKET_ERROR) {
free(infos);
if (WSAGetLastError() == WSAENOBUFS)
continue; /* Try again with bigger buffer size. */
else
return_map_error(-1);
}
*infos_out = infos;
*infos_count_out = (size_t) count;
return 0;
count = WSAEnumProtocolsW(NULL, infos, &buffer_size);
if (count == SOCKET_ERROR) {
free(infos);
if (WSAGetLastError() == WSAENOBUFS)
goto retry; /* Try again with bigger buffer size. */
else
return_map_error(-1);
}
*infos_out = infos;
*infos_count_out = (size_t) count;
return 0;
}