MCPcopy Create free account
hub / github.com/Kitware/VTK / SelectSockets

Method SelectSockets

Common/System/vtkSocketCollection.cxx:27–85  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

25
26//------------------------------------------------------------------------------
27int vtkSocketCollection::SelectSockets(unsigned long msec /*=0*/)
28{
29 // clear last selected socket.
30 this->SelectedSocket = nullptr;
31
32 int max = this->GetNumberOfItems();
33 if (max <= 0)
34 {
35 vtkErrorMacro("No sockets to select.");
36 return -1;
37 }
38
39 int* socket_indices = new int[max];
40 int* sockets_to_select = new int[max];
41 int no_of_sockets = 0;
42
43 vtkCollectionIterator* iter = this->NewIterator();
44
45 int index = 0;
46 for (iter->InitTraversal(); !iter->IsDoneWithTraversal(); iter->GoToNextItem(), index++)
47 {
48 vtkSocket* soc = vtkSocket::SafeDownCast(iter->GetCurrentObject());
49 if (!soc->GetConnected())
50 {
51 // skip not-connected sockets.
52 continue;
53 }
54 int sockfd = soc->GetSocketDescriptor();
55 sockets_to_select[no_of_sockets] = sockfd;
56 socket_indices[no_of_sockets] = index;
57 no_of_sockets++;
58 }
59
60 if (no_of_sockets == 0)
61 {
62 vtkErrorMacro("No alive sockets!");
63 delete[] sockets_to_select;
64 delete[] socket_indices;
65 return -1;
66 }
67 int res = vtkSocket::SelectSockets(sockets_to_select, no_of_sockets, msec, &index);
68 int actual_index = -1;
69 if (index != -1)
70 {
71 actual_index = socket_indices[index];
72 }
73
74 iter->Delete();
75 delete[] sockets_to_select;
76 delete[] socket_indices;
77
78 if (res <= 0 || index == -1)
79 {
80 return res;
81 }
82
83 this->SelectedSocket = vtkSocket::SafeDownCast(this->GetItemAsObject(actual_index));
84 return 1;

Callers

nothing calls this directly

Calls 8

GetCurrentObjectMethod · 0.80
GetItemAsObjectMethod · 0.80
DeleteMethod · 0.65
GetNumberOfItemsMethod · 0.45
NewIteratorMethod · 0.45
InitTraversalMethod · 0.45
IsDoneWithTraversalMethod · 0.45
GoToNextItemMethod · 0.45

Tested by

no test coverage detected