Mercurial > audlegacy
comparison audacious/controlsocket.c @ 2224:4446a9e7bdee trunk
[svn] - memory_pool_alloc_object()
- memory_pool_strdup()
- controlsocket now uses a memory pool for packet data
author | nenolod |
---|---|
date | Fri, 29 Dec 2006 21:01:49 -0800 |
parents | 63af5b9c5026 |
children | 894f7aa46f83 |
comparison
equal
deleted
inserted
replaced
2223:e0d7335f56c3 | 2224:4446a9e7bdee |
---|---|
1 /* BMP - Cross-platform multimedia player | 1 /* Audacious |
2 * Copyright (C) 2005-2007 Audacious development team. | |
3 * | |
4 * BMP - Cross-platform multimedia player | |
2 * Copyright (C) 2003-2004 BMP development team. | 5 * Copyright (C) 2003-2004 BMP development team. |
3 * | 6 * |
4 * Based on XMMS: | 7 * Based on XMMS: |
5 * Copyright (C) 1998-2003 XMMS development team. | 8 * Copyright (C) 1998-2003 XMMS development team. |
6 * | 9 * |
49 #include "playback.h" | 52 #include "playback.h" |
50 #include "playlist.h" | 53 #include "playlist.h" |
51 #include "ui_playlist.h" | 54 #include "ui_playlist.h" |
52 #include "prefswin.h" | 55 #include "prefswin.h" |
53 #include "libaudacious/beepctrl.h" | 56 #include "libaudacious/beepctrl.h" |
57 #include "memorypool.h" | |
54 | 58 |
55 #define CTRLSOCKET_BACKLOG 100 | 59 #define CTRLSOCKET_BACKLOG 100 |
56 #define CTRLSOCKET_TIMEOUT 100000 | 60 #define CTRLSOCKET_TIMEOUT 100000 |
57 | 61 |
58 | 62 |
69 | 73 |
70 static gboolean started = FALSE; | 74 static gboolean started = FALSE; |
71 static gboolean going = TRUE; | 75 static gboolean going = TRUE; |
72 static GCond *start_cond = NULL; | 76 static GCond *start_cond = NULL; |
73 static GMutex *status_mutex = NULL; | 77 static GMutex *status_mutex = NULL; |
74 | 78 static MemoryPool *cs_pool = NULL; |
75 | 79 |
76 static void | 80 static void |
77 ctrlsocket_start_thread(void) | 81 ctrlsocket_start_thread(void) |
78 { | 82 { |
79 start_cond = g_cond_new(); | 83 start_cond = g_cond_new(); |
84 } | 88 } |
85 | 89 |
86 gboolean | 90 gboolean |
87 ctrlsocket_setup(void) | 91 ctrlsocket_setup(void) |
88 { | 92 { |
93 cs_pool = memory_pool_new(); | |
94 | |
89 if (strcmp(cfg.session_uri_base, "")) | 95 if (strcmp(cfg.session_uri_base, "")) |
90 audacious_set_session_uri(cfg.session_uri_base); | 96 audacious_set_session_uri(cfg.session_uri_base); |
91 else | 97 else |
92 return ctrlsocket_setup_unix(); | 98 return ctrlsocket_setup_unix(); |
93 | 99 |
138 break; | 144 break; |
139 } | 145 } |
140 | 146 |
141 listen(fd, CTRLSOCKET_BACKLOG); | 147 listen(fd, CTRLSOCKET_BACKLOG); |
142 | 148 |
143 socket_name = g_strdup(saddr.sun_path); | 149 socket_name = memory_pool_strdup(cs_pool, saddr.sun_path); |
144 ctrl_fd = fd; | 150 ctrl_fd = fd; |
145 session_id = i; | 151 session_id = i; |
146 going = TRUE; | 152 going = TRUE; |
147 | 153 |
148 ctrlsocket_start_thread(); | 154 ctrlsocket_start_thread(); |
211 } | 217 } |
212 | 218 |
213 void | 219 void |
214 ctrlsocket_cleanup(void) | 220 ctrlsocket_cleanup(void) |
215 { | 221 { |
216 if (ctrl_fd) { | 222 if (ctrl_fd) |
223 { | |
217 g_mutex_lock(status_mutex); | 224 g_mutex_lock(status_mutex); |
218 going = FALSE; | 225 going = FALSE; |
219 g_cond_signal(start_cond); | 226 g_cond_signal(start_cond); |
220 g_mutex_unlock(status_mutex); | 227 g_mutex_unlock(status_mutex); |
221 | 228 |
227 ctrl_fd = 0; | 234 ctrl_fd = 0; |
228 | 235 |
229 if (socket_name != NULL) | 236 if (socket_name != NULL) |
230 { | 237 { |
231 unlink(socket_name); | 238 unlink(socket_name); |
232 g_free(socket_name); | 239 memory_pool_release(cs_pool, socket_name); |
233 } | 240 } |
234 | 241 |
235 g_cond_free(start_cond); | 242 g_cond_free(start_cond); |
236 g_mutex_free(status_mutex); | 243 g_mutex_free(status_mutex); |
237 g_mutex_free(packet_list_mutex); | 244 g_mutex_free(packet_list_mutex); |
238 } | 245 } |
246 | |
247 memory_pool_destroy(cs_pool); | |
239 } | 248 } |
240 | 249 |
241 void | 250 void |
242 ctrlsocket_start(void) | 251 ctrlsocket_start(void) |
243 { | 252 { |
292 ctrl_ack_packet(PacketNode * pkt) | 301 ctrl_ack_packet(PacketNode * pkt) |
293 { | 302 { |
294 ctrl_write_packet(pkt->fd, NULL, 0); | 303 ctrl_write_packet(pkt->fd, NULL, 0); |
295 close(pkt->fd); | 304 close(pkt->fd); |
296 if (pkt->data) | 305 if (pkt->data) |
297 g_free(pkt->data); | 306 memory_pool_release(cs_pool, pkt->data); |
298 g_free(pkt); | 307 memory_pool_release(cs_pool, pkt); |
299 } | 308 } |
300 | 309 |
301 static gboolean | 310 static gboolean |
302 ctrlsocket_is_going(void) | 311 ctrlsocket_is_going(void) |
303 { | 312 { |
337 if (select(ctrl_fd + 1, &set, NULL, NULL, &tv) <= 0) | 346 if (select(ctrl_fd + 1, &set, NULL, NULL, &tv) <= 0) |
338 continue; | 347 continue; |
339 if ((fd = accept(ctrl_fd, (struct sockaddr *) &saddr, &len)) == -1) | 348 if ((fd = accept(ctrl_fd, (struct sockaddr *) &saddr, &len)) == -1) |
340 continue; | 349 continue; |
341 | 350 |
342 pkt = g_new0(PacketNode, 1); | 351 pkt = memory_pool_alloc_object(cs_pool, PacketNode); |
343 if ((size_t)read(fd, &pkt->hdr, sizeof(ClientPktHeader)) | 352 if ((size_t)read(fd, &pkt->hdr, sizeof(ClientPktHeader)) |
344 < sizeof(ClientPktHeader)) { | 353 < sizeof(ClientPktHeader)) { |
345 g_free(pkt); | 354 memory_pool_release(cs_pool, pkt); |
346 continue; | 355 continue; |
347 } | 356 } |
348 | 357 |
349 if (pkt->hdr.data_length) { | 358 if (pkt->hdr.data_length) { |
350 size_t data_length = pkt->hdr.data_length; | 359 size_t data_length = pkt->hdr.data_length; |
351 pkt->data = g_malloc0(data_length); | 360 pkt->data = memory_pool_allocate(cs_pool, data_length); |
352 if ((size_t)read(fd, pkt->data, data_length) < data_length) { | 361 if ((size_t)read(fd, pkt->data, data_length) < data_length) { |
353 g_free(pkt->data); | 362 memory_pool_release(cs_pool, pkt->data); |
354 g_free(pkt); | 363 memory_pool_release(cs_pool, pkt); |
355 g_warning("ctrlsocket_func(): Incomplete data packet dropped"); | 364 g_warning("ctrlsocket_func(): Incomplete data packet dropped"); |
356 continue; | 365 continue; |
357 } | 366 } |
358 } | 367 } |
359 | 368 |
487 guint32 *dataptr = pkt->data; | 496 guint32 *dataptr = pkt->data; |
488 while ((len = *dataptr) > 0) { | 497 while ((len = *dataptr) > 0) { |
489 gchar *filename; | 498 gchar *filename; |
490 | 499 |
491 dataptr++; | 500 dataptr++; |
492 filename = g_malloc0(len); | 501 filename = memory_pool_allocate(cs_pool, len); |
493 memcpy(filename, dataptr, len); | 502 memcpy(filename, dataptr, len); |
494 | 503 |
495 GDK_THREADS_ENTER(); | 504 GDK_THREADS_ENTER(); |
496 playlist_add_url(playlist_get_active(), filename); | 505 playlist_add_url(playlist_get_active(), filename); |
497 GDK_THREADS_LEAVE(); | 506 GDK_THREADS_LEAVE(); |
498 | 507 |
499 g_free(filename); | 508 memory_pool_release(cs_pool, filename); |
500 dataptr += (len + 3) / 4; | 509 dataptr += (len + 3) / 4; |
501 } | 510 } |
502 } | 511 } |
503 ctrl_ack_packet(pkt); | 512 ctrl_ack_packet(pkt); |
504 break; | 513 break; |
774 } | 783 } |
775 next = g_list_next(pkt_list); | 784 next = g_list_next(pkt_list); |
776 packet_list = g_list_remove_link(packet_list, pkt_list); | 785 packet_list = g_list_remove_link(packet_list, pkt_list); |
777 g_list_free_1(pkt_list); | 786 g_list_free_1(pkt_list); |
778 if (pkt->data) | 787 if (pkt->data) |
779 g_free(pkt->data); | 788 memory_pool_release(cs_pool, pkt->data); |
780 g_free(pkt); | 789 memory_pool_release(cs_pool, pkt); |
781 } | 790 } |
782 g_mutex_unlock(packet_list_mutex); | 791 g_mutex_unlock(packet_list_mutex); |
783 } | 792 } |