@@ -15,9 +15,7 @@ CurlContext::CurlContext(CURL* c, IPluginContext* plugin) {
1515CurlContext::~CurlContext () {
1616 curl_easy_cleanup (curl);
1717 if (headers != NULL )
18- curl_slist_free_all (headers);
19- if (post )
20- free (post );
18+ curl_slist_free_all (headers);
2119}
2220
2321void CurlContext::AddHeader (const char * string) {
@@ -26,37 +24,35 @@ void CurlContext::AddHeader(const char* string) {
2624 headers = new_headers;
2725}
2826
29- // called right before the main thread adds job to the queue
27+ // called right before event thread adds job to the queue
3028void CurlContext::OnCurlStarted () {
3129 in_event_thread = true ;
3230 // compress post if available
33- if (post )
34- {
31+ if (post ) {
3532 char * compressBuffer = (char *)malloc (compressBound (postLength));
36- // TODO check malloc?
37- uLongf compressLength;
38- int result = compress2 ((Bytef*)compressBuffer, &compressLength, (Bytef*)post , postLength, Z_BEST_SPEED);
39- if (result == Z_OK)
40- {
41- free (post );
42- post = compressBuffer;
43- postLength = compressLength;
44- AddHeader (" Content-Encoding: gzip" );
45- }
46- else
47- {
48- // compression failed
49- free (compressBuffer);
33+ if (compressBuffer != NULL ) {
34+ uLongf compressLength;
35+ int result = compress2 ((Bytef*)compressBuffer, &compressLength, (Bytef*)post , postLength, Z_BEST_SPEED);
36+ if (result == Z_OK) {
37+ free (post );
38+ post = compressBuffer;
39+ postLength = compressLength;
40+ AddHeader (" Content-Encoding: gzip" );
41+ } else {
42+ // compression failed
43+ free (compressBuffer);
44+ }
5045 }
5146
5247 curl_easy_setopt (curl, CURLOPT_POSTFIELDSIZE, postLength);
5348 curl_easy_setopt (curl, CURLOPT_POSTFIELDS, post );
5449 }
5550}
5651
57- // called when the main thread loops through finished jobs
58- void CurlContext::OnCurlCompleted () {
52+ // called when the game thread loops through finished jobs
53+ void CurlContext::OnCurlCompletedGameThread () {
5954 in_event_thread = false ;
55+
6056 IPluginFunction* func = GetSourcepawnFunction (sourcepawn_plugin_context, sourcepawn_callback);
6157 // the plugin that called us disappeared, delete ourselves
6258 if (func == NULL ) {
@@ -85,7 +81,15 @@ void CurlContext::OnCurlCompleted() {
8581 func->PushCell (sourcepawn_userdata);
8682 func->Execute (NULL );
8783
88- // printf("Finished Code %i size %i\n%.*s\n", curlcode, buffer.size(), 256, &buffer[0]);
84+ // printf("Finished Code %i size %i\n%.*s\n", curlcode, buffer.size(), 256, &buffer[0]);
85+ }
86+
87+ // called when event thread finishes a curl job
88+ void CurlContext::OnCurlCompleted () {
89+ if (post ) {
90+ free (post );
91+ post = NULL ;
92+ }
8993}
9094
9195// //////////////
0 commit comments