View | Details | Raw Unified | Return to bug 237508
Collapse All | Expand All

(-)b/event.h (-1 / +1 lines)
Lines 42-48 typedef int event_module_add_t(struct event *); Link Here
42
typedef	int	event_module_del_t(struct event *, int flags);
42
typedef	int	event_module_del_t(struct event *, int flags);
43
typedef int	event_module_init_t(void);
43
typedef int	event_module_init_t(void);
44
typedef void	event_module_fini_t(void);
44
typedef void	event_module_fini_t(void);
45
typedef int	event_module_process_t(u_long);
45
typedef int	event_module_process_t(struct timeval *);
46
struct event_module {
46
struct event_module {
47
	event_module_add_t	*add;
47
	event_module_add_t	*add;
48
	event_module_del_t	*del;
48
	event_module_del_t	*del;
(-)b/kqueue.c (-18 / +6 lines)
Lines 178-204 kqueue_set(struct event *ev, short filter, u_short flags, u_int fflags) Link Here
178
}
178
}
179
179
180
static int
180
static int
181
kqueue_process(u_long timer)
181
kqueue_process(struct timeval *tv)
182
{
182
{
183
	struct event *ev;
183
	struct event *ev;
184
	int events, n, i;
184
	int events, n, i;
185
	struct timespec ts, *tp;
185
	struct timespec ts;
186
186
187
	n = (int) nchanges;
187
	n = (int) nchanges;
188
	nchanges = 0;
188
	nchanges = 0;
189
189
190
	if (timer == 0) {
190
	TIMEVAL_TO_TIMESPEC(tv, &ts);
191
		tp = NULL;
192
	} else {
193
		ts.tv_sec = timer / 1000;
194
		ts.tv_nsec = (timer % 1000) * 1000000;
195
		tp = &ts;
196
	}
197
191
198
	DPRINTF(E_DEBUG, L_GENERAL, "kevent timer: %lu, changes: %d\n",
192
	DPRINTF(E_DEBUG, L_GENERAL, "kevent timer: %lu.%06lu, changes: %d\n",
199
	    timer, n);
193
	    ts.tv_sec, ts.tv_nsec, n);
200
194
201
	events = kevent(kq, change_list, n, event_list, MAXEVENTS, tp);
195
	events = kevent(kq, change_list, n, event_list, MAXEVENTS, &ts);
202
196
203
	if (events == -1) {
197
	if (events == -1) {
204
		if (errno == EINTR)
198
		if (errno == EINTR)
Lines 208-219 kqueue_process(u_long timer) Link Here
208
202
209
	DPRINTF(E_DEBUG, L_GENERAL, "kevent events: %d\n", events);
203
	DPRINTF(E_DEBUG, L_GENERAL, "kevent events: %d\n", events);
210
204
211
	if (events == 0) {
212
		if (timer != 0)
213
			return (0);
214
		DPRINTF(E_FATAL, L_GENERAL, "kevent() returned no events. EXITING\n");
215
	}
216
217
	for (i = 0; i < events; i++) {
205
	for (i = 0; i < events; i++) {
218
		if (event_list[i].flags & EV_ERROR) {
206
		if (event_list[i].flags & EV_ERROR) {
219
			DPRINTF(E_ERROR, L_GENERAL,
207
			DPRINTF(E_ERROR, L_GENERAL,
(-)b/minidlna.c (-21 / +22 lines)
Lines 1109-1115 main(int argc, char **argv) Link Here
1109
	struct upnphttp * next;
1109
	struct upnphttp * next;
1110
	struct timeval tv, timeofday, lastnotifytime = {0, 0};
1110
	struct timeval tv, timeofday, lastnotifytime = {0, 0};
1111
	time_t lastupdatetime = 0, lastdbtime = 0;
1111
	time_t lastupdatetime = 0, lastdbtime = 0;
1112
	u_long timeout;	/* in milliseconds */
1113
	int last_changecnt = 0;
1112
	int last_changecnt = 0;
1114
	pid_t scanner_pid = 0;
1113
	pid_t scanner_pid = 0;
1115
	struct event ssdpev, httpev, monev;
1114
	struct event ssdpev, httpev, monev;
Lines 1181-1186 main(int argc, char **argv) Link Here
1181
	httpev = (struct event ){ .fd = shttpl, .rdwr = EVENT_READ, .process = ProcessListen };
1180
	httpev = (struct event ){ .fd = shttpl, .rdwr = EVENT_READ, .process = ProcessListen };
1182
	event_module.add(&httpev);
1181
	event_module.add(&httpev);
1183
1182
1183
	if (gettimeofday(&timeofday, 0) < 0)
1184
		DPRINTF(E_FATAL, L_GENERAL, "gettimeofday(): %s\n", strerror(errno));
1185
1184
#ifdef TIVO_SUPPORT
1186
#ifdef TIVO_SUPPORT
1185
	if (GETFLAG(TIVO_MASK))
1187
	if (GETFLAG(TIVO_MASK))
1186
	{
1188
	{
Lines 1205-1222 main(int argc, char **argv) Link Here
1205
			tivo_bcast.sin_family = AF_INET;
1207
			tivo_bcast.sin_family = AF_INET;
1206
			tivo_bcast.sin_addr.s_addr = htonl(getBcastAddress());
1208
			tivo_bcast.sin_addr.s_addr = htonl(getBcastAddress());
1207
			tivo_bcast.sin_port = htons(2190);
1209
			tivo_bcast.sin_port = htons(2190);
1210
			lastbeacontime = timeofday;
1208
		}
1211
		}
1209
	}
1212
	}
1210
#endif
1213
#endif
1211
1214
1212
	reload_ifaces(0);
1215
	reload_ifaces(0);	/* sends SSDP notifies */
1213
	lastnotifytime.tv_sec = time(NULL) + runtime_vars.notify_interval;
1216
	lastnotifytime = timeofday;
1214
1217
1215
	/* main loop */
1218
	/* main loop */
1216
	while (!quitting)
1219
	while (!quitting)
1217
	{
1220
	{
1218
		if (gettimeofday(&timeofday, 0) < 0)
1219
			DPRINTF(E_FATAL, L_GENERAL, "gettimeofday(): %s\n", strerror(errno));
1220
		/* Check if we need to send SSDP NOTIFY messages and do it if
1221
		/* Check if we need to send SSDP NOTIFY messages and do it if
1221
		 * needed */
1222
		 * needed */
1222
		tv = lastnotifytime;
1223
		tv = lastnotifytime;
Lines 1230-1270 main(int argc, char **argv) Link Here
1230
					runtime_vars.port, runtime_vars.notify_interval);
1231
					runtime_vars.port, runtime_vars.notify_interval);
1231
			}
1232
			}
1232
			lastnotifytime = timeofday;
1233
			lastnotifytime = timeofday;
1233
			timeout = runtime_vars.notify_interval * 1000;
1234
			tv.tv_sec = runtime_vars.notify_interval;
1235
			tv.tv_usec = 0;
1234
		}
1236
		}
1235
		else
1237
		else
1236
		{
1238
		{
1237
			timevalsub(&tv, &timeofday);
1239
			timevalsub(&tv, &timeofday);
1238
			timeout = tv.tv_sec * 1000 + tv.tv_usec / 1000;
1239
		}
1240
		}
1240
#ifdef TIVO_SUPPORT
1241
#ifdef TIVO_SUPPORT
1241
		if (sbeacon >= 0)
1242
		if (sbeacon >= 0)
1242
		{
1243
		{
1243
			u_long beacontimeout;
1244
			struct timeval beacontv;
1244
1245
1245
			tv = lastbeacontime;
1246
			beacontv = lastbeacontime;
1246
			tv.tv_sec += beacon_interval;
1247
			beacontv.tv_sec += beacon_interval;
1247
			if (timevalcmp(&timeofday, &tv, >=))
1248
			if (timevalcmp(&timeofday, &beacontv, >=))
1248
			{
1249
			{
1249
				sendBeaconMessage(sbeacon, &tivo_bcast, sizeof(struct sockaddr_in), 1);
1250
				sendBeaconMessage(sbeacon, &tivo_bcast, sizeof(struct sockaddr_in), 1);
1250
				lastbeacontime = timeofday;
1251
				lastbeacontime = timeofday;
1251
				beacontimeout = beacon_interval * 1000;
1252
				if (timeout > beacon_interval * 1000)
1253
					timeout = beacon_interval * 1000;
1254
				/* Beacons should be sent every 5 seconds or
1252
				/* Beacons should be sent every 5 seconds or
1255
				 * so for the first minute, then every minute
1253
				 * so for the first minute, then every minute
1256
				 * or so thereafter. */
1254
				 * or so thereafter. */
1257
				if (beacon_interval == 5 && (timeofday.tv_sec - startup_time) > 60)
1255
				if (beacon_interval == 5 && (timeofday.tv_sec - startup_time) > 60)
1258
					beacon_interval = 60;
1256
					beacon_interval = 60;
1257
				beacontv.tv_sec = beacon_interval;
1258
				beacontv.tv_usec = 0;
1259
			}
1259
			}
1260
			else
1260
			else
1261
			{
1261
			{
1262
				timevalsub(&tv, &timeofday);
1262
				timevalsub(&beacontv, &timeofday);
1263
				beacontimeout = tv.tv_sec * 1000 +
1264
				    tv.tv_usec / 1000;
1265
			}
1263
			}
1266
			if (timeout > beacontimeout)
1264
			if (timevalcmp(&tv, &beacontv, >))
1267
				timeout = beacontimeout;
1265
				tv = beacontv;
1268
		}
1266
		}
1269
#endif
1267
#endif
1270
1268
Lines 1279-1291 main(int argc, char **argv) Link Here
1279
#endif
1277
#endif
1280
			} else
1278
			} else
1281
				/* Keep checking for the scanner every sec. */
1279
				/* Keep checking for the scanner every sec. */
1282
				timeout = 1000;
1280
				tv.tv_sec = 1;
1283
		}
1281
		}
1284
1282
1285
		event_module.process(timeout);
1283
		event_module.process(&tv);
1286
		if (quitting)
1284
		if (quitting)
1287
			goto shutdown;
1285
			goto shutdown;
1288
1286
1287
		if (gettimeofday(&timeofday, 0) < 0)
1288
			DPRINTF(E_FATAL, L_GENERAL, "gettimeofday(): %s\n", strerror(errno));
1289
1289
		upnpevents_gc();
1290
		upnpevents_gc();
1290
1291
1291
		/* increment SystemUpdateID if the content database has changed,
1292
		/* increment SystemUpdateID if the content database has changed,
(-)b/select.c (-7 / +2 lines)
Lines 142-150 select_del(struct event *ev, int flags) Link Here
142
}
142
}
143
143
144
static int
144
static int
145
select_process(u_long msec)
145
select_process(struct timeval *tv)
146
{
146
{
147
	struct timeval tv, *tp;
148
	struct event *ev;
147
	struct event *ev;
149
	int ready, i;
148
	int ready, i;
150
149
Lines 155-168 select_process(u_long msec) Link Here
155
				max_fd = events[i]->fd;
154
				max_fd = events[i]->fd;
156
		}
155
		}
157
156
158
	tv.tv_sec = (long) (msec / 1000);
159
	tv.tv_usec = (long) ((msec % 1000) * 1000);
160
	tp = &tv;
161
162
	work_read_fd_set = master_read_fd_set;
157
	work_read_fd_set = master_read_fd_set;
163
	work_write_fd_set = master_write_fd_set;
158
	work_write_fd_set = master_write_fd_set;
164
159
165
	ready = select(max_fd + 1, &work_read_fd_set, &work_write_fd_set, NULL, tp);
160
	ready = select(max_fd + 1, &work_read_fd_set, &work_write_fd_set, NULL, tv);
166
161
167
	if (ready == -1) {
162
	if (ready == -1) {
168
		if (errno == EINTR)
163
		if (errno == EINTR)

Return to bug 237508