ws: make retry logic in ws_get_protocol_catalog() more readable
This commit is contained in:
parent
513410278d
commit
49146ab381
31
src/ws.c
31
src/ws.c
@ -49,22 +49,21 @@ int ws_get_protocol_catalog(WSAPROTOCOL_INFOW** infos_out,
|
|||||||
int count;
|
int count;
|
||||||
WSAPROTOCOL_INFOW* infos;
|
WSAPROTOCOL_INFOW* infos;
|
||||||
|
|
||||||
for (;;) {
|
retry:
|
||||||
infos = malloc(buffer_size);
|
infos = malloc(buffer_size);
|
||||||
if (infos == NULL)
|
if (infos == NULL)
|
||||||
return_set_error(-1, ERROR_NOT_ENOUGH_MEMORY);
|
return_set_error(-1, ERROR_NOT_ENOUGH_MEMORY);
|
||||||
|
|
||||||
count = WSAEnumProtocolsW(NULL, infos, &buffer_size);
|
count = WSAEnumProtocolsW(NULL, infos, &buffer_size);
|
||||||
if (count == SOCKET_ERROR) {
|
if (count == SOCKET_ERROR) {
|
||||||
free(infos);
|
free(infos);
|
||||||
if (WSAGetLastError() == WSAENOBUFS)
|
if (WSAGetLastError() == WSAENOBUFS)
|
||||||
continue; /* Try again with bigger buffer size. */
|
goto retry; /* Try again with bigger buffer size. */
|
||||||
else
|
else
|
||||||
return_map_error(-1);
|
return_map_error(-1);
|
||||||
}
|
|
||||||
|
|
||||||
*infos_out = infos;
|
|
||||||
*infos_count_out = (size_t) count;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*infos_out = infos;
|
||||||
|
*infos_count_out = (size_t) count;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user