@@ -15,9 +15,7 @@ CurlContext::CurlContext(CURL* c, IPluginContext* plugin) {
15
15
CurlContext::~CurlContext () {
16
16
curl_easy_cleanup (curl);
17
17
if (headers != NULL )
18
- curl_slist_free_all (headers);
19
- if (post )
20
- free (post );
18
+ curl_slist_free_all (headers);
21
19
}
22
20
23
21
void CurlContext::AddHeader (const char * string) {
@@ -26,37 +24,35 @@ void CurlContext::AddHeader(const char* string) {
26
24
headers = new_headers;
27
25
}
28
26
29
- // called right before the main thread adds job to the queue
27
+ // called right before event thread adds job to the queue
30
28
void CurlContext::OnCurlStarted () {
31
29
in_event_thread = true ;
32
30
// compress post if available
33
- if (post )
34
- {
31
+ if (post ) {
35
32
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
+ }
50
45
}
51
46
52
47
curl_easy_setopt (curl, CURLOPT_POSTFIELDSIZE, postLength);
53
48
curl_easy_setopt (curl, CURLOPT_POSTFIELDS, post );
54
49
}
55
50
}
56
51
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 () {
59
54
in_event_thread = false ;
55
+
60
56
IPluginFunction* func = GetSourcepawnFunction (sourcepawn_plugin_context, sourcepawn_callback);
61
57
// the plugin that called us disappeared, delete ourselves
62
58
if (func == NULL ) {
@@ -85,7 +81,15 @@ void CurlContext::OnCurlCompleted() {
85
81
func->PushCell (sourcepawn_userdata);
86
82
func->Execute (NULL );
87
83
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
+ }
89
93
}
90
94
91
95
// //////////////
0 commit comments