source: fact/FADctrl/FADBoard.cc@ 10273

Last change on this file since 10273 was 10263, checked in by ogrimm, 14 years ago
Limited DIM slow-control update rate
File size: 18.9 KB
Line 
1/********************************************************************\
2
3 Class interfacing to FAD board
4
5\********************************************************************/
6
7#include "FADBoard.h"
8using namespace std;
9
10//
11// Constructor
12//
13FADBoard::FADBoard(string Server, unsigned short ServerPort, class FAD *Parent, unsigned int Num) {
14
15 int Ret;
16
17 // Initialization
18 m = Parent;
19 Active = false;
20 Continue = true;
21 CommOK = false;
22 ACalib.Time = -1;
23 Status.Update.tv_sec = -1;
24 Port = ServerPort;
25
26 Name = new char [Server.size()+1]; // Name in permanent memory for DIM service
27 strcpy(Name, Server.c_str());
28
29 // Initialise mutex for synchronization
30 pthread_mutexattr_t Attr;
31
32 if ((Ret = pthread_mutexattr_settype(&Attr, PTHREAD_MUTEX_ERRORCHECK)) != 0) {
33 m->Message(m->ERROR, "pthread_mutex_settype() failed (%s)", strerror(Ret));
34 }
35 if ((Ret = pthread_mutex_init(&Mutex, &Attr)) != 0) {
36 m->Message(m->FATAL, "pthread_mutex_init() failed (%s)", strerror(Ret));
37 }
38
39 // Initialise condition variable for synchronization
40 if ((Ret = pthread_cond_init(&CondVar, NULL)) != 0) {
41 m->Message(m->FATAL, "pthread_cond_init() failed (%s)", strerror(Ret));
42 }
43
44 // Construct DIM service name prefix
45 stringstream ID;
46 ID << SERVER_NAME"/Board" << setfill('0') << setw(2) << Num << "/";
47
48 DIM_Name = new DimService((ID.str()+"Server").c_str(), Name);
49 DIM_Status = new DimService((ID.str()+"Status").c_str(), (char *) "");
50 DIM_ID = new DimService((ID.str()+"BoardID").c_str(), (char *) "S", NULL, 0);
51 DIM_Temp = new DimService((ID.str()+"Temperature").c_str(), (char *) "F", NULL, 0);
52 DIM_DAC = new DimService((ID.str()+"DAC").c_str(), (char *) "S", NULL, 0);
53 DIM_ROI = new DimService((ID.str()+"ROI").c_str(), (char *) "S", NULL, 0);
54
55 // Create thread that connects and receives data
56 SetStatus("Trying to connect");
57
58 if ((Ret = pthread_create(&Thread, NULL, (void * (*)(void *)) LaunchThread,(void *) this)) != 0) {
59 m->Message(m->FATAL, "pthread_create() failed in FADBoard() (%s)", strerror(Ret));
60 }
61
62 // Start thread to connect to other sockets
63 DimThread::start();
64}
65
66//
67// Destructor
68//
69FADBoard::~FADBoard() {
70
71 int Ret;
72
73 // Cancel thread (if it did not quit already) and wait for it to quit
74 if ((Ret = pthread_cancel(Thread)) != 0 && Ret != ESRCH) {
75 m->Message(m->ERROR, "pthread_cancel() failed in ~FADBoard() (%s)", strerror(Ret));
76 }
77 if ((Ret = pthread_join(Thread, NULL)) != 0) {
78 m->Message(m->ERROR, "pthread_join() failed in ~FADBoard (%s)", strerror(Ret));
79 }
80
81 delete DIM_Name;
82 delete DIM_Status;
83 delete DIM_ID;
84 delete DIM_Temp;
85 delete DIM_DAC;
86 delete DIM_ROI;
87 delete[] Name;
88
89 // Delete condition variable
90 if ((Ret = pthread_cond_destroy(&CondVar)) != 0) {
91 m->Message(m->ERROR, "pthread_cond_destroy() failed in ~FADBoard (%s)", strerror(Ret));
92 }
93
94 // Delete mutex
95 if ((Ret = pthread_mutex_destroy(&Mutex)) != 0) {
96 m->Message(m->ERROR, "pthread_mutex_destroy() failed in ~FADBoard (%s)", strerror(Ret));
97 }
98}
99
100
101//
102// Send data to board
103//
104void FADBoard::Send(const void *Data, size_t Bytes) {
105
106 // Do not send if not active or communication problem
107 if (!Active || !CommOK) return;
108
109 // Write data
110 ssize_t Result = write(Socket, Data, Bytes);
111
112 // Check result
113 if (Result == -1) m->PrintMessage("Error: Could not write to socket (%s)\n", strerror(errno));
114 else if ((size_t) Result < Bytes) m->PrintMessage("Error: Could only write %d bytes out of %d to socket\n", Result, Bytes);
115}
116
117void FADBoard::Send(unsigned short Data) {
118
119 unsigned short Buffer = htons(Data);
120
121 Send(&Buffer, sizeof(unsigned short));
122}
123
124
125//
126// Get board status (mutex protected to avoid concurrent access in ReadLoop)
127//
128struct FADBoard::BoardStatus FADBoard::GetStatus() {
129
130 int Ret;
131 struct BoardStatus S;
132
133 // Lock
134 if ((Ret = pthread_mutex_lock(&Mutex)) != 0) {
135 m->Message(m->FATAL, "pthread_mutex_lock() failed in ReadLoop() (%s)", strerror(Ret));
136 }
137
138 S = Status;
139
140 // Unlock
141 if ((Ret = pthread_mutex_unlock(&Mutex)) != 0) {
142 m->Message(m->FATAL, "pthread_mutex_unlock() failed in Unlock() (%s)", strerror(Ret));
143 }
144
145 return S;
146}
147
148
149//
150// Perform amplitude calibration in steps
151//
152// The steps are intended to assure that up to date data is available
153void FADBoard::AmplitudeCalibration() {
154
155 vector<unsigned short> ROICmd;
156 unsigned short DACCmd[] = {htons(CMD_Write | (BADDR_DAC + 1)), 0, htons(CMD_Write | (BADDR_DAC + 2)), 0, htons(CMD_Write | (BADDR_DAC + 3)), 0};
157 string Message = string("ACALIBDONE")+Name;
158
159 switch (State) {
160 // ====== Part A: Check if amplitude calibration should start and initialise =====
161 case standbye:
162 if (m->Mode != m->acalib) break;
163
164 // Invalidate current calibration
165 ACalib.Time = -1;
166 Count = 0;
167
168 // Save initial board status, set all ROIs to 1024 and set DAC values
169 InitialStatus = GetStatus();
170
171 for (unsigned int i=0; i<NChips*NChannels; i++) {
172 ROICmd.push_back(htons(CMD_Write | (BADDR_ROI + i)));
173 ROICmd.push_back(htons(NBins));
174 }
175 Send(&ROICmd[0], ROICmd.size()*sizeof(unsigned short));
176
177 DACCmd[1] = htons(0);
178 DACCmd[3] = htons(0);
179 DACCmd[5] = htons(0);
180 Send(DACCmd, sizeof(DACCmd));
181
182 // Clear sum vector and set state to accumulate
183 memset(Sum, 0, sizeof(Sum));
184 State = baseline;
185 break;
186
187 // ====== Part B: Baseline calibration =====
188 case baseline:
189 // Check for stopping
190 if (m->Mode != m->acalib) {
191 State = cleanup;
192 break;
193 }
194
195 // Average
196 for (unsigned int Chip=0; Chip<NChips; Chip++) {
197 for (unsigned int Chan=0; Chan<NChannels; Chan++) {
198 for (int i=0; i<Status.ROI[Chip][Chan]; i++) {
199 Sum[Chip][Chan][(i+Status.TriggerCell[Chip]) % NBins] += Data[Chip][Chan][i];
200 }
201 }
202 }
203 Count++;
204
205 // Determine baseline if integration finished
206 if (Count < m->NumEventsRequested) break;
207
208 for (unsigned int i=0; i<NChips; i++) {
209 for (unsigned int j=0; j<NChannels; j++) {
210 for (unsigned int k=0; k<NBins; k++) {
211 ACalib.Baseline[i][j][k] = Sum[i][j][k] / m->NumEventsRequested;
212 }
213 }
214 }
215
216 // Set new DAC values and start accumulation
217 DACCmd[1] = htons(50000);
218 DACCmd[3] = htons(50000);
219 DACCmd[5] = htons(50000);
220 Send(DACCmd, sizeof(DACCmd));
221
222 // Clear sum vector and set state to accumulate
223 memset(Sum, 0, sizeof(Sum));
224 Count = 0;
225 State = gain;
226 break;
227
228 // ====== Part C: Gain calibration =====
229 case gain:
230 // Check for stopping
231 if (m->Mode != m->acalib) {
232 State = cleanup;
233 break;
234 }
235
236 // Average
237 for (unsigned int Chip=0; Chip<NChips; Chip++) {
238 for (unsigned int Chan=0; Chan<NChannels; Chan++) {
239 for (int i=0; i<Status.ROI[Chip][Chan]; i++) {
240 Sum[Chip][Chan][(i+Status.TriggerCell[Chip]) % NBins] += Data[Chip][Chan][i];
241 }
242 }
243 }
244 Count++;
245
246 // Determine gain if integration finished
247 if (Count < m->NumEventsRequested) break;
248
249 for (unsigned int i=0; i<NChips; i++) {
250 for (unsigned int j=0; j<NChannels; j++) {
251 for (unsigned int k=0; k<NBins; k++) {
252 ACalib.Gain[i][j][k] = (Sum[i][j][k] / m->NumEventsRequested) - ACalib.Baseline[i][j][k];
253 }
254 }
255 }
256
257 // Set new DAC values and start accumulation
258 DACCmd[1] = htons(0);
259 DACCmd[3] = htons(0);
260 DACCmd[5] = htons(0);
261 Send(DACCmd, sizeof(DACCmd));
262
263 // Clear sum vector and set state to accumulate
264 memset(Sum, 0, sizeof(Sum));
265 Count = 0;
266 State = secondary;
267 break;
268
269 // ====== Part D: Secondary calibration =====
270 case secondary:
271 // Check for stopping
272 if (m->Mode != m->acalib) {
273 State = cleanup;
274 break;
275 }
276
277 // Average
278 for (unsigned int Chip=0; Chip<NChips; Chip++) {
279 for (unsigned int Chan=0; Chan<NChannels; Chan++) {
280 for (int i=0; i<Status.ROI[Chip][Chan]; i++) {
281 Sum[Chip][Chan][i] = Data[Chip][Chan][i] - ACalib.Baseline[Chip][Chan][(i-Status.TriggerCell[Chip]) % NBins];
282 }
283 }
284 }
285 Count++;
286
287 // Determine secondary baseline if integration finished
288 if (Count < m->NumEventsRequested) break;
289
290 for (unsigned int i=0; i<NChips; i++) {
291 for (unsigned int j=0; j<NChannels; j++) {
292 for (unsigned int k=0; k<NBins; k++) {
293 ACalib.Secondary[i][j][k] = Sum[i][j][k] / (double) m->NumEventsRequested;
294 }
295 }
296 }
297
298 // Store calibration time and temperature
299 ACalib.DNA = Status.DNA;
300 ACalib.Frequency = Status.Frequency;
301 ACalib.Time = time(NULL);
302 ACalib.Temp = 0;
303 for (unsigned int i=0; i<NTemp; i++) ACalib.Temp += Status.Temp[i] / NTemp;
304
305 // Inform event thread that calibration is finished for this board
306 if (write(m->Pipe[1], Message.data(), Message.size()) == -1) {
307 m->Message(m->ERROR, "write() to Pipe[1] failed in class FADBoard::AmplitudeCalibration (%s)", strerror(errno));
308 }
309
310 State = cleanup;
311 break;
312
313 // ====== Part E: Write back original ROI and DAC settings =====
314 case cleanup:
315 // ROI values
316 ROICmd.clear();
317 for (unsigned int i=0; i<NChips*NChannels; i++) {
318 ROICmd.push_back(htons(CMD_Write | (BADDR_ROI + i)));
319 ROICmd.push_back(htons(InitialStatus.ROI[i/NChannels][i%NChannels]));
320 }
321 Send(&ROICmd[0], ROICmd.size()*sizeof(unsigned short));
322
323 // DAC values
324 DACCmd[1] = htons(InitialStatus.DAC[1]);
325 DACCmd[3] = htons(InitialStatus.DAC[2]);
326 DACCmd[5] = htons(InitialStatus.DAC[3]);
327 Send(DACCmd, sizeof(DACCmd));
328
329 State = wait;
330 break;
331
332 // ====== Wait for Mode not being idle =====
333 case wait:
334 if (m->Mode == m->idle) State = standbye;
335 break;
336 }
337}
338
339//
340// Connect to board and read data
341//
342void FADBoard::ReadLoop() {
343
344 char Buffer[READ_BUFFER_SIZE];
345 unsigned int Pos = 0, Temp;
346 const PEVNT_HEADER *Header = (PEVNT_HEADER *) Buffer;
347 ssize_t Result;
348 struct sockaddr_in SocketAddress;
349 struct BoardStatus PrevStatus;
350 time_t LastUpdate = 0;
351 int Ret;
352
353 // Resolve hostname
354 struct hostent *Host = gethostbyname(Name);
355 if (Host == 0) {
356 SetStatus("Could not resolve host name '%s'", Name);
357 return;
358 }
359
360 SocketAddress.sin_family = PF_INET;
361 SocketAddress.sin_port = htons(Port);
362 SocketAddress.sin_addr = *(struct in_addr*) Host->h_addr;
363
364 // Open socket descriptor
365 if ((Socket = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
366 m->Message(m->ERROR, "Could not open socket for %s (%s)\n", Name, strerror(errno));
367 return;
368 }
369
370 // Connect to server
371 if (connect(Socket, (struct sockaddr *) &SocketAddress, sizeof(SocketAddress)) == -1) {
372 SetStatus("Could not connect to port %hu (%s)", Port, strerror(errno));
373 }
374 else {
375 CommOK = true;
376 Active = true;
377 SetStatus("Connected");
378 }
379
380 memset(&PrevStatus, 0, sizeof(PrevStatus));
381
382 // Leave loop if program termination requested or board communication not OK
383 while (!m->ExitRequest && CommOK) {
384 // Read data from socket
385 Result = read(Socket, Buffer + Pos, sizeof(Buffer)-Pos);
386
387 // Check result of read
388 if (Result == -1) {
389 m->Message(m->ERROR, "Could not read from socket for %s, exiting read loop (%s)\n", Name, strerror(errno));
390 CommOK = false;
391 break;
392 }
393 else if (Result == 0) {
394 SetStatus("Server not existing anymore, exiting read loop");
395 CommOK = false;
396 break;
397 }
398
399 // If not active, discard incoming data
400 if (!Active) continue;
401
402 // Advance write pointer
403 Pos += Result;
404
405 // Check if internal buffer full
406 if (Pos == sizeof(Buffer)) {
407 SetStatus("Internal buffer full, deleting all data in buffer");
408 Pos = 0;
409 continue;
410 }
411
412 // Check if buffer starts with start_package_flag, remove data if not
413 Temp = 0;
414 while (ntohs(*((unsigned short *) (Buffer+Temp))) != 0xfb01 && Temp<Pos) Temp++;
415 if (Temp != 0) {
416 memmove(Buffer, Buffer+Temp, Pos-Temp);
417 Pos -= Temp;
418 SetStatus("Removed %d bytes because of start_package_flag not found", Temp);
419 continue;
420 }
421
422 // Wait until the buffer contains at least enough bytes to potentially hold a PEVNT_HEADER
423 if (Pos < sizeof(PEVNT_HEADER)) continue;
424
425 unsigned int Length = ntohs(Header->package_length)*2*sizeof(char);
426 if (Pos < Length) continue;
427
428 // Extract data if event end package flag correct
429 if (ntohs(*(unsigned short *) (Buffer+Length-sizeof(unsigned short))) == 0x04FE) {
430
431 // Prepare pointers to channel data (channels stored in order 0,9,18,27 - 1,10,19,28 - ... - 8,17,26,35)
432 PCHANNEL *Channel[NChips*NChannels], *Pnt=(PCHANNEL *) (Header+1);
433 for(unsigned int i=0; i<NChips*NChannels; i++) {
434 Channel[i] = Pnt;
435 Pnt = (PCHANNEL *) ((short *) (Channel[i] + 1) + ntohs(Channel[i]->roi));
436 }
437
438 PrevStatus = Status;
439
440 // Wait until event thread processed the previous data and lock to avoid concurrent access in GetStatus()
441 Lock();
442 while (!Continue) {
443 if ((Ret = pthread_cond_wait(&CondVar, &Mutex)) != 0) {
444 m->Message(m->ERROR, "pthread_cond_wait() failed (%s)", strerror(Ret));
445 }
446 }
447 gettimeofday(&Status.Update, NULL);
448
449 // Extract board and trigger information
450 Status.BoardID = ntohs(Header->board_id);
451 Status.FirmwareRevision = ntohs(Header->version_no);
452 Status.BoardTime = ntohl(Header->time);
453 Status.EventCounter = ntohl(Header->fad_evt_counter);
454 Status.TriggerID = ntohl(Header->trigger_id);
455 Status.TriggerType = ntohs(Header->trigger_type);
456 Status.TriggerCRC = ntohs(Header->trigger_crc);
457 Status.DNA = Header->DNA;
458
459 // Extract frequency related information
460 Status.Frequency = ntohl(Header->REFCLK_frequency)/1.0e3*2.048;
461 Status.PhaseShift = Header->adc_clock_phase_shift;
462 for (unsigned int i=0; i<NChips; i++) {
463 if ((ntohs(Header->PLLLCK)>>12 & (1<<i)) != 0) Status.Lock[i] = true;
464 else Status.Lock[i] = false;
465 }
466
467 // Extract Firmware status info
468 Status.denable = (bool) ( ntohs(Header->PLLLCK) & (1<<11) );
469 Status.dwrite = (bool) ( ntohs(Header->PLLLCK) & (1<<10) );
470 Status.DCM_lock = (bool) ( ntohs(Header->PLLLCK) & (1<<9) );
471 Status.DCM_ready = (bool) ( ntohs(Header->PLLLCK) & (1<<8) );
472 Status.spi_clk = (bool) ( ntohs(Header->PLLLCK) & (1<<7) );
473
474 // Extract temperatures (MSB indicates if temperature is positive or negative)
475 for (unsigned int i=0; i<NTemp; i++) {
476 if ((ntohs(Header->drs_temperature[i]) & 0x8000) == 0) Status.Temp[i] = float(ntohs(Header->drs_temperature[i]) >> 3)/16;
477 else Status.Temp[i] = float(0xE000 | (ntohs(Header->drs_temperature[i])) >> 3)/16;
478 }
479
480 // Extract DAC channels
481 for (unsigned int i=0; i<NDAC; i++) Status.DAC[i] = ntohs(Header->dac[i]);
482
483 short Buf;
484 for (unsigned int Chip=0; Chip<NChips; Chip++) {
485 // Extract trigger cells
486 Status.TriggerCell[Chip] = (int) ntohs(Channel[Chip]->start_cell);
487
488 for (unsigned int Chan=0; Chan<NChannels; Chan++) {
489 // Extract ROI
490 Status.ROI[Chip][Chan] = ntohs(Channel[Chip+NChips*Chan]->roi);
491
492 // Extract ADC data (stored in 12 bit signed twis complement with out-of-range-bit and leading zeroes)
493 for (int i=0; i<Status.ROI[Chip][Chan]; i++) {
494 Buf = ntohs(Channel[Chip+NChips*Chan]->adc_data[i]);
495 (Buf <<= 4) >>= 4; //delete the sign-bit by shifting left and shift back
496 Data[Chip][Chan][i] = Buf;
497 }
498 }
499 }
500
501 // Prepare predicate for condition variable
502 Continue = false;
503 Unlock();
504
505 // Amplitude calibration (will check if Mode is acalib)
506 AmplitudeCalibration();
507
508 // Update DIM services if necessary
509 if (time(NULL) - LastUpdate > m->EventUpdateDelay) {
510 LastUpdate = time(NULL);
511
512 if (memcmp(PrevStatus.Temp, Status.Temp, sizeof(Status.Temp)) != 0) {
513 DIM_Temp->updateService(Status.Temp, sizeof(Status.Temp));
514 }
515 if (memcmp(PrevStatus.DAC, Status.DAC, sizeof(Status.DAC)) != 0) {
516 DIM_DAC->updateService(Status.DAC, sizeof(Status.DAC));
517 }
518 if (memcmp(PrevStatus.ROI, Status.ROI, sizeof(Status.ROI)) != 0) {
519 DIM_ROI->updateService(Status.ROI, sizeof(Status.ROI));
520 }
521 if (PrevStatus.BoardID != Status.BoardID) {
522 DIM_ID->updateService(&Status.BoardID, sizeof(Status.BoardID));
523 }
524 }
525
526 // Inform event thread of new data
527 string Message = string("EVENT")+Name;
528 if (write(m->Pipe[1], Message.data(), Message.size()) == -1) {
529 m->Message(m->ERROR, "write() to Pipe[1] failed in class FADBoard (%s)", strerror(errno));
530 m->ExitRequest = true;
531 }
532 }
533 else SetStatus("End package flag incorrect, removing corrupt event");
534
535 // Remove event data from internal buffer
536 memmove(Buffer, Buffer+Length, Pos-Length);
537 Pos = Pos-Length;
538 } // while()
539
540 // Set inactive and close socket descriptor
541 Active = false;
542
543 if (close(Socket) == -1) {
544 m->Message(m->ERROR, "Could not close socket descriptor for board %s (%s)", Name, strerror(errno));
545 }
546
547}
548
549//
550// Launch read thread inside class
551//
552void FADBoard::LaunchThread(class FADBoard *m) {
553
554 m->ReadLoop();
555}
556
557
558//
559// Set status message
560//
561void FADBoard::SetStatus(const char *Format, ...) {
562
563 int Ret;
564
565 // Assemble message
566 va_list ArgumentPointer;
567 va_start(ArgumentPointer, Format);
568 Lock();
569 Ret = vsnprintf(Status.Message, sizeof(Status.Message), Format, ArgumentPointer);
570 Unlock();
571 va_end(ArgumentPointer);
572
573 if (Ret == -1) m->Message(m->FATAL, "snprintf() in FADBoard::SetStatus() failed (%s)", strerror(errno));
574
575 // Update status service
576 DIM_Status->updateService(Status.Message);
577}
578
579
580//
581// Lock and unlock mutex
582//
583void FADBoard::Lock() {
584
585 int Ret;
586
587 if ((Ret = pthread_mutex_lock(&Mutex)) != 0) {
588 m->Message(m->FATAL, "pthread_mutex_lock() failed in class FADBoard (%s)", strerror(Ret));
589 }
590}
591
592void FADBoard::Unlock() {
593
594 int Ret;
595
596 if ((Ret = pthread_mutex_unlock(&Mutex)) != 0) {
597 m->Message(m->FATAL, "pthread_mutex_unlock() failed in class FADBoard (%s)", strerror(Ret));
598 }
599}
600
601
602//
603// Open other sockets
604//
605// Error reporting is limited as this function is expected to be removed when firmware allows single socket
606//
607void FADBoard::threadHandler() {
608
609 int List[] = {5001, 5002, 5003, 5004, 5005, 5006, 5007};
610 int Socket[sizeof(List)/sizeof(int)], MaxSocketNum, Ret;
611 fd_set DescriptorList;
612 char Buffer[1000000];
613
614 // Resolve hostname
615 struct hostent *Host = gethostbyname(Name);
616 if (Host == 0) return;
617
618 // Connect to server
619 struct sockaddr_in SocketAddress;
620 SocketAddress.sin_family = PF_INET;
621 SocketAddress.sin_addr = *(struct in_addr*) Host->h_addr;
622
623 for (unsigned int i=0; i<sizeof(List)/sizeof(int); i++) {
624 // Open socket descriptor
625 if ((Socket[i] = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
626 m->Message(m->ERROR, "OtherSockets: Could not open socket for port %d (%s)\n", List[i], strerror(errno));
627 return;
628 }
629 MaxSocketNum = *max_element(Socket, Socket+sizeof(List)/sizeof(int));
630
631 // Connect to server
632 SocketAddress.sin_port = htons((unsigned short) List[i]);
633 if (connect(Socket[i], (struct sockaddr *) &SocketAddress, sizeof(SocketAddress)) == -1) return;
634 }
635
636 while(true) {
637 // Wait for data from sockets
638 FD_ZERO(&DescriptorList);
639 for (unsigned int i=0; i<sizeof(List)/sizeof(int); i++) FD_SET(Socket[i], &DescriptorList);
640 if (select(MaxSocketNum+1, &DescriptorList, NULL, NULL, NULL) == -1) {
641 m->Message(m->ERROR, "OtherSockets: Error with select() (%s)\n", strerror(errno));
642 break;
643 }
644
645 // Data from socket
646 for (unsigned int i=0; i<sizeof(List)/sizeof(int); i++) if (FD_ISSET(Socket[i], &DescriptorList)) {
647 Ret = read(Socket[i], Buffer, sizeof(Buffer));
648 if (Ret == -1) m->Message(m->ERROR, "OtherSockets: Error reading from port %d (%s)\n", List[i], strerror(errno));
649 }
650 }
651
652 // Close all sockets
653 for (unsigned int i=0; i<sizeof(List)/sizeof(int); i++) {
654 if ((Socket[i] != -1) && (close(Socket[i]) == -1)) {
655 m->Message(m->ERROR, "OtherSockets: Could not close socket of port %d (%s)", List[i], strerror(errno));
656 }
657 }
658}
Note: See TracBrowser for help on using the repository browser.