Bug Summary

File:build-analysis/../src/clients/lib/xmmsclient/visualization/udp.c
Warning:line 225, column 3
Value stored to 'ret' is never read

Annotated Source Code

1#include <xmmsclientpriv/visualization/common.h>
2
3static double
4udp_timediff (int32_t id, int socket) {
5 int i;
6 double lag;
7 struct timeval time;
8 double diff = 0.0;
9 int diffc = 0;
10 xmmsc_vis_udp_timing_t packet_d;
11 char* packet = packet_init_timing (&packet_d);
12
13 gettimeofday (&time, NULL((void*)0));
14 XMMSC_VIS_UNALIGNED_WRITE (packet_d.__unaligned_id, (int32_t)htonl (id), int32_t)do { int32_t *__d = (packet_d.__unaligned_id); int32_t __s = (
(int32_t)htonl (id)); memcpy (__d, &__s, sizeof (int32_t)
); } while (0)
;
15 XMMSC_VIS_UNALIGNED_WRITE (&packet_d.__unaligned_clientstamp[0],do { int32_t *__d = (&packet_d.__unaligned_clientstamp[0]
); int32_t __s = ((int32_t)htonl (time.tv_sec)); memcpy (__d,
&__s, sizeof (int32_t)); } while (0)
16 (int32_t)htonl (time.tv_sec), int32_t)do { int32_t *__d = (&packet_d.__unaligned_clientstamp[0]
); int32_t __s = ((int32_t)htonl (time.tv_sec)); memcpy (__d,
&__s, sizeof (int32_t)); } while (0)
;
17 XMMSC_VIS_UNALIGNED_WRITE (&packet_d.__unaligned_clientstamp[1],do { int32_t *__d = (&packet_d.__unaligned_clientstamp[1]
); int32_t __s = ((int32_t)htonl (time.tv_usec)); memcpy (__d
, &__s, sizeof (int32_t)); } while (0)
18 (int32_t)htonl (time.tv_usec), int32_t)do { int32_t *__d = (&packet_d.__unaligned_clientstamp[1]
); int32_t __s = ((int32_t)htonl (time.tv_usec)); memcpy (__d
, &__s, sizeof (int32_t)); } while (0)
;
19
20 /* TODO: handle lost packages! */
21 for (i = 0; i < 10; ++i) {
22 send (socket, packet, packet_d.size, 0);
23 }
24 printf ("Syncing ");
25 do {
26 if ((recv (socket, packet, packet_d.size, 0) == packet_d.size) && (*packet_d.__unaligned_type == 'T')) {
27 struct timeval rtv;
28 gettimeofday (&time, NULL((void*)0));
29 XMMSC_VIS_UNALIGNED_READ (rtv.tv_sec, &packet_d.__unaligned_clientstamp[0], int32_t)do { int32_t *__s = (&packet_d.__unaligned_clientstamp[0]
); memcpy (&(rtv.tv_sec), __s, sizeof (int32_t)); } while
(0)
;
30 XMMSC_VIS_UNALIGNED_READ (rtv.tv_usec, &packet_d.__unaligned_clientstamp[1], int32_t)do { int32_t *__s = (&packet_d.__unaligned_clientstamp[1]
); memcpy (&(rtv.tv_usec), __s, sizeof (int32_t)); } while
(0)
;
31 rtv.tv_sec = ntohl (rtv.tv_sec);
32 rtv.tv_usec = ntohl (rtv.tv_usec);
33
34 lag = (tv2ts (&time) - tv2ts (&rtv)) / 2.0;
35 diffc++;
36
37 XMMSC_VIS_UNALIGNED_READ (rtv.tv_sec, &packet_d.__unaligned_serverstamp[0], int32_t)do { int32_t *__s = (&packet_d.__unaligned_serverstamp[0]
); memcpy (&(rtv.tv_sec), __s, sizeof (int32_t)); } while
(0)
;
38 XMMSC_VIS_UNALIGNED_READ (rtv.tv_usec, &packet_d.__unaligned_serverstamp[1], int32_t)do { int32_t *__s = (&packet_d.__unaligned_serverstamp[1]
); memcpy (&(rtv.tv_usec), __s, sizeof (int32_t)); } while
(0)
;
39 rtv.tv_sec = ntohl (rtv.tv_sec);
40 rtv.tv_usec = ntohl (rtv.tv_usec);
41
42 diff += tv2ts (&rtv) - lag;
43 /* debug output
44 printf("server diff: %f \t old timestamp: %f, new timestamp %f\n",
45 net2ts (packet_d.serverstamp), net2ts (packet_d.clientstamp), tv2ts (&time));
46 end of debug */
47 putchar('.');
48 }
49 } while (diffc < 10);
50 free (packet);
51
52 puts (" done.");
53 return diff / (double)diffc;
54}
55
56static bool_Bool
57setup_socket (xmmsc_connection_t *c, xmmsc_vis_udp_t *t, int32_t id, int32_t port) {
58 struct addrinfo hints;
59 struct addrinfo *result, *rp;
60 char *host;
61 char portstr[10];
62 char packet[1 + sizeof(int32_t)];
63 int32_t* packet_id = (int32_t*)&packet[1];
64 sprintf (portstr, "%d", port);
65
66 memset (&hints, 0, sizeof (hints));
67 hints.ai_family = AF_UNSPEC0;
68 hints.ai_socktype = SOCK_DGRAMSOCK_DGRAM;
69 hints.ai_flags = 0;
70 hints.ai_protocol = 0;
71
72 host = xmms_ipc_hostname (c->path);
73 if (!host) {
74 host = strdup ("localhost");
75 }
76
77 if (xmms_getaddrinfo (host, portstr, &hints, &result) != 0) {
78 c->error = strdup("Couldn't setup socket!");
79 free (host);
80 return false0;
81 }
82 free (host);
83
84 for (rp = result; rp != NULL((void*)0); rp = rp->ai_next) {
85 if (!xmms_socket_valid (t->socket[0] = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol))) {
86 continue;
87 }
88 if (connect (t->socket[0], rp->ai_addr, rp->ai_addrlen) != -1) {
89 /* Windows doesn't support MSG_DONTWAIT.
90 Why should it? Ripping off BSD, but without mutilating it? No! */
91 xmms_socket_set_nonblock (t->socket[0]);
92 /* init fallback socket for timing stuff */
93 t->socket[1] = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
94 connect (t->socket[1], rp->ai_addr, rp->ai_addrlen);
95 break;
96 } else {
97 xmms_socket_close (t->socket[0]);
98 }
99 }
100 if (rp == NULL((void*)0)) {
101 c->error = strdup("Could not connect!");
102 return false0;
103 }
104 xmms_freeaddrinfo (result);
105
106 packet[0] = 'H';
107 *packet_id = htonl (id);
108 send (t->socket[0], &packet, sizeof (packet), 0);
109
110 t->timediff = udp_timediff (id, t->socket[1]);
111/* printf ("diff: %f\n", t->timediff); */
112 return true1;
113}
114
115xmmsc_result_t *
116setup_udp_prepare (xmmsc_connection_t *c, int32_t vv)
117{
118 xmmsc_result_t *res;
119 xmmsc_visualization_t *v;
120
121 x_check_conn (c, 0)do { if (!c) { xmmsc_log ("xmmsclient", XMMS_LOG_LEVEL_FAIL, "%s was called %s"
, __FUNCTION__, ("with a NULL connection")); return 0; }; if (
!c->ipc) { xmmsc_log ("xmmsclient", XMMS_LOG_LEVEL_FAIL, "%s was called %s"
, __FUNCTION__, ("with a connection that isn't connected")); return
0; };} while (0)
;
122 v = get_dataset (c, vv);
123
124 res = xmmsc_send_cmd (c, XMMS_IPC_OBJECT_VISUALIZATION,
125 XMMS_IPC_COMMAND_VISUALIZATION_INIT_UDP,
126 XMMSV_LIST_ENTRY_INT (v->id)__xmmsv_identity_xmmsv (xmmsv_new_int (v->id)),
127 XMMSV_LIST_END((void*)0));
128
129 if (res) {
130 xmmsc_result_visc_set (res, v);
131 }
132 return res;
133}
134
135bool_Bool
136setup_udp_handle (xmmsc_result_t *res)
137{
138 bool_Bool ret;
139 xmmsc_vis_udp_t *t;
140 xmmsc_visualization_t *visc;
141
142 visc = xmmsc_result_visc_get (res);
143 if (!visc) {
144 x_api_error_if (1, "non vis result?", -1)if (1) { xmmsc_log ("xmmsclient", XMMS_LOG_LEVEL_FAIL, "%s was called %s"
, __FUNCTION__, ("non vis result?")); return -1; }
;
145 }
146
147 t = &visc->transport.udp;
148
149 if (!xmmsc_result_iserror (res)xmmsv_is_error(xmmsc_result_get_value(res))) {
150 xmmsv_t *val;
151 int port;
152 val = xmmsc_result_get_value (res);
153 xmmsv_get_intxmmsv_get_int32 (val, &port);
154 ret = setup_socket (xmmsc_result_get_connection (res), t, visc->id, port);
155 } else {
156 ret = false0;
157 }
158
159 return ret;
160}
161
162void
163cleanup_udp (xmmsc_vis_udp_t *t)
164{
165 xmms_socket_close (t->socket[0]);
166 xmms_socket_close (t->socket[1]);
167}
168
169
170static int
171wait_for_socket (xmmsc_vis_udp_t *t, unsigned int blocking)
172{
173 int ret;
174 fd_set rfds;
175 struct timeval time;
176 FD_ZERO (&rfds)do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq"
: "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) /
sizeof (__fd_mask)), "1" (&((&rfds)->__fds_bits)[
0]) : "memory"); } while (0)
;
177 FD_SET (t->socket[0], &rfds)((void) (((&rfds)->__fds_bits)[((t->socket[0]) / (8
* (int) sizeof (__fd_mask)))] |= ((__fd_mask) 1 << ((t
->socket[0]) % (8 * (int) sizeof (__fd_mask))))))
;
178 time.tv_sec = blocking / 1000;
179 time.tv_usec = (blocking % 1000) * 1000;
180 ret = select (t->socket[0] + 1, &rfds, NULL((void*)0), NULL((void*)0), &time);
181 return ret;
182}
183
184int
185read_do_udp (xmmsc_vis_udp_t *t, xmmsc_visualization_t *v, short *buffer, int drawtime, unsigned int blocking)
186{
187 int old;
188 int ret;
189 int i, size;
190 xmmsc_vis_udp_data_t packet_d;
191 char* packet = packet_init_data (&packet_d);
192 xmmsc_vischunk_t data;
193
194 if (blocking) {
195 wait_for_socket (t, blocking);
196 }
197
198 ret = recv (t->socket[0], packet, packet_d.size, 0);
199 if ((ret > 0) && (*packet_d.__unaligned_type == 'V')) {
200 uint16_t grace;
201 struct timeval rtv;
202
203 XMMSC_VIS_UNALIGNED_READ (data, packet_d.__unaligned_data, xmmsc_vischunk_t)do { xmmsc_vischunk_t *__s = (packet_d.__unaligned_data); memcpy
(&(data), __s, sizeof (xmmsc_vischunk_t)); } while (0)
;
204
205 /* resync connection */
206 XMMSC_VIS_UNALIGNED_READ (grace, packet_d.__unaligned_grace, uint16_t)do { uint16_t *__s = (packet_d.__unaligned_grace); memcpy (&
(grace), __s, sizeof (uint16_t)); } while (0)
;
207 grace = ntohs (grace);
208 if (grace < 1000) {
209 if (t->grace != 0) {
210 t->grace = 0;
211 /* use second socket here, so vis packets don't get lost */
212 t->timediff = udp_timediff (v->id, t->socket[1]);
213 }
214 } else {
215 t->grace = grace;
216 }
217 /* include the measured time difference */
218
219 rtv.tv_sec = ntohl (data.timestamp[0]);
220 rtv.tv_usec = ntohl (data.timestamp[1]);
221
222 double interim = tv2ts (&rtv);
223 interim -= t->timediff;
224 ts2net (data.timestamp, interim);
225 ret = 1;
Value stored to 'ret' is never read
226 } else {
227 if (ret == 1 && *packet_d.__unaligned_type == 'K') {
228 ret = -1;
229 } else if (ret > -1 || xmms_socket_error_recoverable ()) {
230 ret = 0;
231 } else {
232 ret = -1;
233 }
234 free (packet);
235 return ret;
236 }
237
238 old = check_drawtime (net2ts (data.timestamp), drawtime);
239
240 if (!old) {
241 size = ntohs (data.size);
242 for (i = 0; i < size; ++i) {
243 buffer[i] = (int16_t)ntohs (data.data[i]);
244 }
245 }
246
247 free (packet);
248
249 if (!old) {
250 return size;
251 }
252 return 0;
253}