Mercurial > audlegacy-plugins
comparison src/curl/curl.c @ 430:ed94145472df trunk
[svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
failure on seeking to the end of the file.
author | iabervon |
---|---|
date | Sun, 14 Jan 2007 23:53:59 -0800 |
parents | 37b3f45b3a68 |
children | cc7faecc7619 |
comparison
equal
deleted
inserted
replaced
429:74b23aec578d | 430:ed94145472df |
---|---|
28 typedef struct _CurlHandle CurlHandle; | 28 typedef struct _CurlHandle CurlHandle; |
29 | 29 |
30 struct _CurlHandle { | 30 struct _CurlHandle { |
31 CURL *curl; | 31 CURL *curl; |
32 | 32 |
33 gsize length; // the length of the file | 33 gssize length; // the length of the file |
34 gsize rd_abs; // the absolute position for reading from the stream | 34 gsize rd_abs; // the absolute position for reading from the stream |
35 gsize wr_abs; // the absolute position where the input connection is | 35 gsize wr_abs; // the absolute position where the input connection is |
36 | 36 |
37 gsize buffer_length; | 37 gsize buffer_length; |
38 gchar *buffer; | 38 gchar *buffer; |
44 gboolean cancel; // true if the thread should be cancelled | 44 gboolean cancel; // true if the thread should be cancelled |
45 GThread *thread; // the thread that's reading from the connection | 45 GThread *thread; // the thread that's reading from the connection |
46 }; | 46 }; |
47 | 47 |
48 /* TODO: | 48 /* TODO: |
49 * - Icecast | 49 * - Fix hang if the server closes the connection in the middle |
50 * - Clever buffer stuff when you read a bit of the beginning and a bit of the | 50 * - Clever buffer stuff when you read a bit of the beginning and a bit of the |
51 * end of a file | 51 * end of a file |
52 */ | 52 */ |
53 | 53 |
54 /* The goal here is to have a buffering system which handles the following: | 54 /* The goal here is to have a buffering system which handles the following: |
95 curl_easy_getinfo(handle->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, | 95 curl_easy_getinfo(handle->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, |
96 &value); | 96 &value); |
97 if (retcode == CURLE_OK) | 97 if (retcode == CURLE_OK) |
98 { | 98 { |
99 handle->length = value; | 99 handle->length = value; |
100 if (handle->length == 0) | |
101 handle->length = -2; | |
102 //g_print("Length: %d\n", handle->length); | |
100 } | 103 } |
101 else | 104 else |
102 { | 105 { |
106 handle->length = -2; | |
103 g_print("getinfo gave error\n"); | 107 g_print("getinfo gave error\n"); |
104 } | 108 } |
105 } | 109 } |
106 } | 110 } |
107 | 111 |
138 | 142 |
139 static gpointer | 143 static gpointer |
140 curl_manage_request(gpointer arg) | 144 curl_manage_request(gpointer arg) |
141 { | 145 { |
142 CurlHandle *handle = arg; | 146 CurlHandle *handle = arg; |
147 CURLcode result; | |
143 //g_print("Connect %p\n", handle); | 148 //g_print("Connect %p\n", handle); |
144 | 149 |
145 if (handle->no_data) | 150 if (handle->no_data) |
146 curl_easy_setopt(handle->curl, CURLOPT_NOBODY, 1); | 151 curl_easy_setopt(handle->curl, CURLOPT_NOBODY, 1); |
147 else | 152 else |
151 | 156 |
152 curl_easy_setopt(handle->curl, CURLOPT_NOBODY, 0); | 157 curl_easy_setopt(handle->curl, CURLOPT_NOBODY, 0); |
153 curl_easy_setopt(handle->curl, CURLOPT_HTTPGET, 1); | 158 curl_easy_setopt(handle->curl, CURLOPT_HTTPGET, 1); |
154 } | 159 } |
155 | 160 |
156 curl_easy_perform(handle->curl); | 161 result = curl_easy_perform(handle->curl); |
157 update_length(handle); | 162 if (result == CURLE_OK) |
163 update_length(handle); | |
164 if (result != CURLE_OK && result != CURLE_WRITE_ERROR) | |
165 { | |
166 g_print("Got curl error %d\n", result); | |
167 } | |
158 //g_print("Done %p%s", handle, handle->cancel ? " (aborted)\n" : "\n"); | 168 //g_print("Done %p%s", handle, handle->cancel ? " (aborted)\n" : "\n"); |
159 handle->cancel = 1; | 169 handle->cancel = 1; |
160 return NULL; | 170 return NULL; |
161 } | 171 } |
162 | 172 |
269 check(handle); | 279 check(handle); |
270 | 280 |
271 while (ret < sz) | 281 while (ret < sz) |
272 { | 282 { |
273 size_t available; | 283 size_t available; |
274 while (!(available = buf_available(handle)) && | 284 while (!(available = buf_available(handle)) && !handle->cancel) |
275 (handle->length == -1 || handle->rd_abs < handle->length) && | |
276 !handle->cancel) | |
277 g_usleep(10000); | 285 g_usleep(10000); |
278 if (available > sz - ret) | 286 if (available > sz - ret) |
279 available = sz - ret; | 287 available = sz - ret; |
280 memcpy(ptr + ret, handle->buffer + handle->rd_index, available); | 288 memcpy(ptr + ret, handle->buffer + handle->rd_index, available); |
281 | 289 |
343 { | 351 { |
344 // Wait a bit? | 352 // Wait a bit? |
345 } | 353 } |
346 } | 354 } |
347 | 355 |
348 if (whence == SEEK_END && handle->length == -1) | 356 if (whence == SEEK_END && handle->length < 0) |
349 { | 357 { |
350 //g_print("Tried to seek to the end of a file with unknown length\n"); | 358 //g_print("Tried to seek to the end of a file with unknown length\n"); |
351 // don't know how long it is... | 359 // don't know how long it is... |
352 return -1; | 360 return -1; |
353 } | 361 } |