MCPcopy Create free account
hub / github.com/NVIDIA/cuda-samples / ipcOpenSocket

Function ipcOpenSocket

Common/helper_multiprocess.cpp:218–256  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

216}
217
218int ipcOpenSocket(ipcHandle *&handle) {
219 int sock = 0;
220 struct sockaddr_un cliaddr;
221
222 handle = new ipcHandle;
223 memset(handle, 0, sizeof(*handle));
224
225 if ((sock = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) {
226 perror("IPC failure:Socket creation error");
227 return -1;
228 }
229
230 memset(&cliaddr, 0, sizeof(cliaddr));
231 cliaddr.sun_family = AF_UNIX;
232 char temp[sizeof(cliaddr.sun_path)];
233
234 // Create unique name for the socket with path if SOCK_FOLDER is set.
235 int written = snprintf(temp, sizeof(temp), "%s/%u", getSocketFolder().c_str(),
236 getpid());
237 if (written < 0 || (size_t)written >= sizeof(temp)) {
238 perror("IPC failure: Cannot bind provided name to socket. Name too large");
239 close(sock);
240 delete handle;
241 handle = NULL;
242 return -1;
243 }
244
245 strcpy(cliaddr.sun_path, temp);
246 if (bind(sock, (struct sockaddr *)&cliaddr, sizeof(cliaddr)) < 0) {
247 perror("IPC failure: Binding socket failed");
248 return -1;
249 }
250
251 handle->socket = sock;
252 handle->socketName = new char[strlen(temp) + 1];
253 strcpy(handle->socketName, temp);
254
255 return 0;
256}
257
258int ipcCloseSocket(ipcHandle *handle) {
259 if (!handle) {

Callers 1

childProcessFunction · 0.85

Calls 1

getSocketFolderFunction · 0.85

Tested by

no test coverage detected