wininet: Don't use blocking_mode_t in netconn.c.
This commit is contained in:
parent
6fe5546210
commit
9d7d27ea7f
|
@ -380,6 +380,12 @@ static WCHAR *get_host_header( http_request_t *req )
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
BLOCKING_ALLOW,
|
||||||
|
BLOCKING_DISALLOW,
|
||||||
|
BLOCKING_WAITALL
|
||||||
|
} blocking_mode_t;
|
||||||
|
|
||||||
struct data_stream_vtbl_t {
|
struct data_stream_vtbl_t {
|
||||||
DWORD (*get_avail_data)(data_stream_t*,http_request_t*);
|
DWORD (*get_avail_data)(data_stream_t*,http_request_t*);
|
||||||
BOOL (*end_of_data)(data_stream_t*,http_request_t*);
|
BOOL (*end_of_data)(data_stream_t*,http_request_t*);
|
||||||
|
|
|
@ -415,12 +415,6 @@ VOID INTERNET_SendCallback(object_header_t *hdr, DWORD_PTR dwContext,
|
||||||
DWORD dwStatusInfoLength) DECLSPEC_HIDDEN;
|
DWORD dwStatusInfoLength) DECLSPEC_HIDDEN;
|
||||||
BOOL INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto, WCHAR *foundProxy, DWORD *foundProxyLen) DECLSPEC_HIDDEN;
|
BOOL INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto, WCHAR *foundProxy, DWORD *foundProxyLen) DECLSPEC_HIDDEN;
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
BLOCKING_ALLOW,
|
|
||||||
BLOCKING_DISALLOW,
|
|
||||||
BLOCKING_WAITALL
|
|
||||||
} blocking_mode_t;
|
|
||||||
|
|
||||||
DWORD create_netconn(BOOL,server_t*,DWORD,BOOL,DWORD,netconn_t**) DECLSPEC_HIDDEN;
|
DWORD create_netconn(BOOL,server_t*,DWORD,BOOL,DWORD,netconn_t**) DECLSPEC_HIDDEN;
|
||||||
void free_netconn(netconn_t*) DECLSPEC_HIDDEN;
|
void free_netconn(netconn_t*) DECLSPEC_HIDDEN;
|
||||||
void NETCON_unload(void) DECLSPEC_HIDDEN;
|
void NETCON_unload(void) DECLSPEC_HIDDEN;
|
||||||
|
|
|
@ -280,9 +280,9 @@ void init_winsock(void)
|
||||||
InitOnceExecuteOnce(&init_once, winsock_startup, NULL, NULL);
|
InitOnceExecuteOnce(&init_once, winsock_startup, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_socket_blocking(int socket, blocking_mode_t mode)
|
static void set_socket_blocking(int socket, BOOL is_blocking)
|
||||||
{
|
{
|
||||||
ULONG arg = mode == BLOCKING_DISALLOW;
|
ULONG arg = !is_blocking;
|
||||||
ioctlsocket(socket, FIONBIO, &arg);
|
ioctlsocket(socket, FIONBIO, &arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,7 +297,7 @@ static DWORD create_netconn_socket(server_t *server, netconn_t *netconn, DWORD t
|
||||||
assert(server->addr_len);
|
assert(server->addr_len);
|
||||||
result = netconn->socket = socket(server->addr.ss_family, SOCK_STREAM, 0);
|
result = netconn->socket = socket(server->addr.ss_family, SOCK_STREAM, 0);
|
||||||
if(result != -1) {
|
if(result != -1) {
|
||||||
set_socket_blocking(netconn->socket, BLOCKING_DISALLOW);
|
set_socket_blocking(netconn->socket, FALSE);
|
||||||
result = connect(netconn->socket, (struct sockaddr*)&server->addr, server->addr_len);
|
result = connect(netconn->socket, (struct sockaddr*)&server->addr, server->addr_len);
|
||||||
if(result == -1)
|
if(result == -1)
|
||||||
{
|
{
|
||||||
|
@ -326,7 +326,7 @@ static DWORD create_netconn_socket(server_t *server, netconn_t *netconn, DWORD t
|
||||||
netconn->socket = -1;
|
netconn->socket = -1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
set_socket_blocking(netconn->socket, BLOCKING_ALLOW);
|
set_socket_blocking(netconn->socket, TRUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(result == -1)
|
if(result == -1)
|
||||||
|
@ -688,22 +688,17 @@ DWORD NETCON_send(netconn_t *connection, const void *msg, size_t len, int flags,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL read_ssl_chunk(netconn_t *conn, void *buf, SIZE_T buf_size, blocking_mode_t mode, SIZE_T *ret_size, BOOL *eof)
|
static BOOL read_ssl_chunk(netconn_t *conn, void *buf, SIZE_T buf_size, BOOL blocking, SIZE_T *ret_size, BOOL *eof)
|
||||||
{
|
{
|
||||||
const SIZE_T ssl_buf_size = conn->ssl_sizes.cbHeader+conn->ssl_sizes.cbMaximumMessage+conn->ssl_sizes.cbTrailer;
|
const SIZE_T ssl_buf_size = conn->ssl_sizes.cbHeader+conn->ssl_sizes.cbMaximumMessage+conn->ssl_sizes.cbTrailer;
|
||||||
SecBuffer bufs[4];
|
SecBuffer bufs[4];
|
||||||
SecBufferDesc buf_desc = {SECBUFFER_VERSION, sizeof(bufs)/sizeof(*bufs), bufs};
|
SecBufferDesc buf_desc = {SECBUFFER_VERSION, sizeof(bufs)/sizeof(*bufs), bufs};
|
||||||
SSIZE_T size, buf_len = 0;
|
SSIZE_T size, buf_len = 0;
|
||||||
blocking_mode_t tmp_mode;
|
|
||||||
int i;
|
int i;
|
||||||
SECURITY_STATUS res;
|
SECURITY_STATUS res;
|
||||||
|
|
||||||
assert(conn->extra_len < ssl_buf_size);
|
assert(conn->extra_len < ssl_buf_size);
|
||||||
|
|
||||||
/* BLOCKING_WAITALL is handled by caller */
|
|
||||||
if(mode == BLOCKING_WAITALL)
|
|
||||||
mode = BLOCKING_ALLOW;
|
|
||||||
|
|
||||||
if(conn->extra_len) {
|
if(conn->extra_len) {
|
||||||
memcpy(conn->ssl_buf, conn->extra_buf, conn->extra_len);
|
memcpy(conn->ssl_buf, conn->extra_buf, conn->extra_len);
|
||||||
buf_len = conn->extra_len;
|
buf_len = conn->extra_len;
|
||||||
|
@ -712,8 +707,7 @@ static BOOL read_ssl_chunk(netconn_t *conn, void *buf, SIZE_T buf_size, blocking
|
||||||
conn->extra_buf = NULL;
|
conn->extra_buf = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp_mode = buf_len ? BLOCKING_DISALLOW : mode;
|
set_socket_blocking(conn->socket, blocking && !buf_len);
|
||||||
set_socket_blocking(conn->socket, tmp_mode);
|
|
||||||
size = sock_recv(conn->socket, conn->ssl_buf+buf_len, ssl_buf_size-buf_len, 0);
|
size = sock_recv(conn->socket, conn->ssl_buf+buf_len, ssl_buf_size-buf_len, 0);
|
||||||
if(size < 0) {
|
if(size < 0) {
|
||||||
if(!buf_len) {
|
if(!buf_len) {
|
||||||
|
@ -728,11 +722,10 @@ static BOOL read_ssl_chunk(netconn_t *conn, void *buf, SIZE_T buf_size, blocking
|
||||||
buf_len += size;
|
buf_len += size;
|
||||||
}
|
}
|
||||||
|
|
||||||
*ret_size = buf_len;
|
|
||||||
|
|
||||||
if(!buf_len) {
|
if(!buf_len) {
|
||||||
TRACE("EOF\n");
|
TRACE("EOF\n");
|
||||||
*eof = TRUE;
|
*eof = TRUE;
|
||||||
|
*ret_size = 0;
|
||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -755,7 +748,7 @@ static BOOL read_ssl_chunk(netconn_t *conn, void *buf, SIZE_T buf_size, blocking
|
||||||
case SEC_E_INCOMPLETE_MESSAGE:
|
case SEC_E_INCOMPLETE_MESSAGE:
|
||||||
assert(buf_len < ssl_buf_size);
|
assert(buf_len < ssl_buf_size);
|
||||||
|
|
||||||
set_socket_blocking(conn->socket, mode);
|
set_socket_blocking(conn->socket, blocking);
|
||||||
size = sock_recv(conn->socket, conn->ssl_buf+buf_len, ssl_buf_size-buf_len, 0);
|
size = sock_recv(conn->socket, conn->ssl_buf+buf_len, ssl_buf_size-buf_len, 0);
|
||||||
if(size < 1) {
|
if(size < 1) {
|
||||||
if(size < 0 && WSAGetLastError() == WSAEWOULDBLOCK) {
|
if(size < 0 && WSAGetLastError() == WSAEWOULDBLOCK) {
|
||||||
|
@ -826,9 +819,9 @@ DWORD NETCON_recv(netconn_t *connection, void *buf, size_t len, BOOL blocking, i
|
||||||
|
|
||||||
if (!connection->secure)
|
if (!connection->secure)
|
||||||
{
|
{
|
||||||
set_socket_blocking(connection->socket, blocking ? BLOCKING_ALLOW : BLOCKING_DISALLOW);
|
set_socket_blocking(connection->socket, blocking);
|
||||||
*recvd = sock_recv(connection->socket, buf, len, 0);
|
*recvd = sock_recv(connection->socket, buf, len, 0);
|
||||||
return *recvd == -1 ? WSAGetLastError() : ERROR_SUCCESS;
|
return *recvd == -1 ? WSAGetLastError() : ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -852,7 +845,7 @@ DWORD NETCON_recv(netconn_t *connection, void *buf, size_t len, BOOL blocking, i
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
res = read_ssl_chunk(connection, (BYTE*)buf+size, len-size, blocking ? BLOCKING_ALLOW : BLOCKING_DISALLOW, &size, &eof);
|
res = read_ssl_chunk(connection, (BYTE*)buf, len, blocking, &size, &eof);
|
||||||
if(res != ERROR_SUCCESS) {
|
if(res != ERROR_SUCCESS) {
|
||||||
if(res == WSAEWOULDBLOCK) {
|
if(res == WSAEWOULDBLOCK) {
|
||||||
if(size)
|
if(size)
|
||||||
|
@ -901,9 +894,9 @@ BOOL NETCON_is_alive(netconn_t *netconn)
|
||||||
int len;
|
int len;
|
||||||
char b;
|
char b;
|
||||||
|
|
||||||
set_socket_blocking(netconn->socket, BLOCKING_DISALLOW);
|
set_socket_blocking(netconn->socket, FALSE);
|
||||||
len = sock_recv(netconn->socket, &b, 1, MSG_PEEK);
|
len = sock_recv(netconn->socket, &b, 1, MSG_PEEK);
|
||||||
set_socket_blocking(netconn->socket, BLOCKING_ALLOW);
|
set_socket_blocking(netconn->socket, TRUE);
|
||||||
|
|
||||||
return len == 1 || (len == -1 && WSAGetLastError() == WSAEWOULDBLOCK);
|
return len == 1 || (len == -1 && WSAGetLastError() == WSAEWOULDBLOCK);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue