ReactOS 0.4.16-dev-2528-g7139e57
handle.c File Reference
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "ws2tcpip.h"
#include "winhttp.h"
#include "wine/debug.h"
#include "winhttp_private.h"
Include dependency graph for handle.c:

Go to the source code of this file.

Macros

#define HANDLE_CHUNK_SIZE   0x10
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (winhttp)
 
struct object_headeraddref_object (struct object_header *hdr)
 
struct object_headergrab_object (HINTERNET hinternet)
 
void release_object (struct object_header *hdr)
 
HINTERNET alloc_handle (struct object_header *hdr)
 
BOOL free_handle (HINTERNET hinternet)
 

Variables

static CRITICAL_SECTION handle_cs = { &handle_cs_debug, -1, 0, 0, 0, 0 }
 
static CRITICAL_SECTION_DEBUG handle_cs_debug
 
static struct object_header ** handles
 
static ULONG_PTR next_handle
 
static ULONG_PTR max_handles
 

Macro Definition Documentation

◆ HANDLE_CHUNK_SIZE

#define HANDLE_CHUNK_SIZE   0x10

Definition at line 33 of file handle.c.

Function Documentation

◆ addref_object()

struct object_header * addref_object ( struct object_header hdr)

Definition at line 48 of file handle.c.

49{
50 ULONG refs = InterlockedIncrement( &hdr->refs );
51 TRACE( "%p -> refcount = %lu\n", hdr, refs );
52 return hdr;
53}
#define InterlockedIncrement
Definition: armddk.h:53
char hdr[14]
Definition: iptest.cpp:33
#define TRACE(s)
Definition: solgame.cpp:4
uint32_t ULONG
Definition: typedefs.h:59

Referenced by alloc_handle(), grab_object(), queue_task(), WinHttpConnect(), and WinHttpOpenRequest().

◆ alloc_handle()

HINTERNET alloc_handle ( struct object_header hdr)

Definition at line 86 of file handle.c.

87{
88 struct object_header **p;
90
91 hdr->handle = NULL;
92
94 if (!max_handles)
95 {
97 if (!(p = calloc( 1, sizeof(*p) * num ))) goto end;
98 handles = p;
100 }
102 {
103 size_t new_size, old_size = max_handles * sizeof(*handles);
104 num = max_handles * 2;
105 new_size = num * sizeof(*handles);
106 if (!(p = realloc( handles, new_size ))) goto end;
107 memset( (char *)p + old_size, 0, new_size - old_size );
108 handles = p;
110 }
112 if (handles[handle]) ERR("handle isn't free but should be\n");
113
115 hdr->handle = (HINTERNET)(handle + 1);
117
118end:
120 return hdr->handle;
121}
#define ERR(fmt,...)
Definition: precomp.h:57
#define realloc
Definition: debug_ros.c:6
#define NULL
Definition: types.h:112
static CRITICAL_SECTION handle_cs
Definition: handle.c:38
#define HANDLE_CHUNK_SIZE
Definition: handle.c:33
static struct object_header ** handles
Definition: handle.c:44
static ULONG_PTR max_handles
Definition: handle.c:46
struct object_header * addref_object(struct object_header *hdr)
Definition: handle.c:48
static ULONG_PTR next_handle
Definition: handle.c:45
size_t const old_size
Definition: expand.cpp:65
size_t const new_size
Definition: expand.cpp:66
GLuint GLuint end
Definition: gl.h:1545
GLfloat GLfloat p
Definition: glext.h:8902
GLuint GLuint num
Definition: glext.h:9618
#define calloc
Definition: rosglue.h:14
#define memset(x, y, z)
Definition: compat.h:39
HINTERNET handle
uint32_t ULONG_PTR
Definition: typedefs.h:65
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
LPVOID HINTERNET
Definition: winhttp.h:37

◆ free_handle()

BOOL free_handle ( HINTERNET  hinternet)

Definition at line 123 of file handle.c.

124{
125 BOOL ret = FALSE;
126 ULONG_PTR handle = (ULONG_PTR)hinternet;
127 struct object_header *hdr = NULL;
128
130
131 if ((handle > 0) && (handle <= max_handles))
132 {
133 handle--;
134 if (handles[handle])
135 {
136 hdr = handles[handle];
137 TRACE( "destroying handle %Ix for object %p\n", handle + 1, hdr );
139 ret = TRUE;
140 }
141 }
142
144
145 if (hdr)
146 {
147 if (hdr->vtbl->handle_closing)
148 hdr->vtbl->handle_closing( hdr );
150 }
151
155
156 return ret;
157}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
void release_object(struct object_header *hdr)
Definition: handle.c:71
return ret
Definition: mutex.c:146
#define ULONG_PTR
Definition: config.h:101
unsigned int BOOL
Definition: ntddk_ex.h:94

Referenced by pqInsert(), and WinHttpCloseHandle().

◆ grab_object()

◆ release_object()

void release_object ( struct object_header hdr)

Definition at line 71 of file handle.c.

72{
73 ULONG refs = InterlockedDecrement( &hdr->refs );
74 TRACE( "object %p refcount = %lu\n", hdr, refs );
75 if (!refs)
76 {
78
80
81 TRACE( "destroying object %p\n", hdr );
82 hdr->vtbl->destroy( hdr );
83 }
84}
#define InterlockedDecrement
Definition: armddk.h:52
static void close_connection(void)
Definition: http.c:5576
Definition: tftpd.h:86
#define WINHTTP_HANDLE_TYPE_REQUEST
Definition: winhttp.h:503
#define WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING
Definition: winhttp.h:454

Referenced by connect_destroy(), free_handle(), queue_task(), request_destroy(), task_callback(), WinHttpAddRequestHeaders(), WinHttpCloseHandle(), WinHttpConnect(), WinHttpGetProxyForUrl(), WinHttpOpen(), WinHttpOpenRequest(), WinHttpQueryAuthSchemes(), WinHttpQueryDataAvailable(), WinHttpQueryHeaders(), WinHttpQueryOption(), WinHttpReadData(), WinHttpReceiveResponse(), WinHttpSendRequest(), WinHttpSetCredentials(), WinHttpSetOption(), WinHttpSetStatusCallback(), WinHttpSetTimeouts(), WinHttpWebSocketClose(), WinHttpWebSocketCompleteUpgrade(), WinHttpWebSocketQueryCloseStatus(), WinHttpWebSocketReceive(), WinHttpWebSocketSend(), WinHttpWebSocketShutdown(), and WinHttpWriteData().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( winhttp  )

Variable Documentation

◆ handle_cs

static CRITICAL_SECTION handle_cs = { &handle_cs_debug, -1, 0, 0, 0, 0 }
static

Definition at line 35 of file handle.c.

◆ handle_cs_debug

CRITICAL_SECTION_DEBUG handle_cs_debug
static
Initial value:
=
{
0, 0, &handle_cs,
0, 0, { (ULONG_PTR)(__FILE__ ": handle_cs") }
}
static CRITICAL_SECTION_DEBUG handle_cs_debug
Definition: handle.c:39

Definition at line 36 of file handle.c.

◆ handles

struct object_header** handles
static

Definition at line 44 of file handle.c.

Referenced by alloc_handle(), free_handle(), and grab_object().

◆ max_handles

ULONG_PTR max_handles
static

Definition at line 46 of file handle.c.

Referenced by alloc_handle(), free_handle(), and grab_object().

◆ next_handle

ULONG_PTR next_handle
static

Definition at line 45 of file handle.c.

Referenced by alloc_handle(), and free_handle().