Changeset 13899
- Timestamp:
- Jun 19, 2007, 4:37:43 PM (19 years ago)
- Location:
- trunk/Ohana/src
- Files:
-
- 4 edited
-
kapa2/src/CheckPipe.c (modified) (1 diff)
-
kapa2/src/Layout.c (modified) (1 diff)
-
libkapa/include/kapa.h (modified) (1 diff)
-
libkapa/src/KapaOpen.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/kapa2/src/CheckPipe.c
r13479 r13899 7 7 8 8 // we can supply a port here, with only small changes 9 void InitPipe () { 10 InitSocket = KapaServerInit (&Address); 9 void InitPipe (char *namedSocket) { 10 11 if (namedSocket == NULL) { 12 InitSocket = KapaServerInit (&Address); 13 } else { 14 sock = KapaWaitNamedSocket (namedSocket); 15 } 11 16 return; 12 17 } -
trunk/Ohana/src/kapa2/src/Layout.c
r13479 r13899 6 6 int N; 7 7 Section *section; 8 char *namedSocket; 9 10 if ((N = get_argument (argc, argv, "-socket"))) { 11 remove_argument (N, &argc, argv); 12 namedSocket = argv[N]; 13 remove_argument (N, &argc, argv); 14 } 8 15 9 InitPipe(); 16 // if we specify a named socket, wait until we are contacted 17 // otherwise, open an INET sock and check occasionally for requests 18 InitPipe (namedSocket); 10 19 11 20 ACTIVE_CURSOR = FALSE; -
trunk/Ohana/src/libkapa/include/kapa.h
r13479 r13899 227 227 int KapaDefineValidIP (char *ipstring); 228 228 int KapaClientSocket (char *hostname); 229 int KapaOpenNamedSocket (char *kapa_exec, char *name); 230 int KapaWaitNamedSocket (char *sockpath); 229 231 230 232 /* define Kapa names for shared functions */ -
trunk/Ohana/src/libkapa/src/KapaOpen.c
r13479 r13899 243 243 return (sock); 244 244 } 245 246 /* start socketed connection (UNIX Socket) */ 247 int KapaOpenNamedSocket (char *kapa_exec, char *name) { 248 249 int InitSocket, status; 250 struct sockaddr_un Address; 251 socklen_t AddressLength; 252 char temp[128], socket_name[64]; 253 int Ntry, fd; 254 255 sprintf (socket_name, "/tmp/Kapa.XXXXXX"); 256 if ((fd = mkstemp (socket_name)) == -1) { 257 fprintf (stderr, "error starting kapa\n"); 258 return (-1); 259 } 260 close (fd); 261 unlink (socket_name); 262 263 strcpy (Address.sun_path, socket_name); 264 Address.sun_family = AF_UNIX; 265 InitSocket = socket (AF_UNIX, SOCK_STREAM, 0); 266 status = bind (InitSocket, (struct sockaddr *) &Address, sizeof (Address)); 267 status = listen (InitSocket, 1); 268 269 if (name == NULL) { 270 sprintf (temp, "%s -socket %s &", kapa_exec, socket_name); 271 } else { 272 sprintf (temp, "%s -socket %s -name %s &", kapa_exec, socket_name, name); 273 } 274 system (temp); 275 276 AddressLength = sizeof (Address); 277 fcntl (InitSocket, F_SETFL, O_NONBLOCK); 278 279 # define NTRY 500 280 Ntry = 0; 281 while (Ntry < NTRY) { 282 fd = accept (InitSocket, (struct sockaddr *)&Address, &AddressLength); 283 if (fd != -1) break; 284 if (errno != EAGAIN) break; 285 usleep (10000); 286 Ntry ++; 287 } 288 289 if (fd < 0) return (-1); 290 291 // the client uses a BLOCKing socket by default 292 fcntl (fd, F_SETFL, !O_NONBLOCK); 293 return (fd); 294 } 295 296 // wait for the initiating process to connect to the socket 297 int KapaWaitNamedSocket (char *sockpath) { 298 299 int sock, status; 300 struct sockaddr_un Address; 301 302 strcpy (Address.sun_path, sockpath); 303 Address.sun_family = AF_UNIX; 304 sock = socket (AF_UNIX, SOCK_STREAM, 0); 305 status = connect (sock, (struct sockaddr *) &Address, sizeof (Address)); 306 if (status < 0) { 307 fprintf (stderr, "unsuccessful connection: %d\n", status); 308 exit (0); 309 } 310 311 // the server uses an unblocked socket 312 fcntl (sock, F_SETFL, O_NONBLOCK); 313 unlink (sockpath); 314 return (sock); 315 }
Note:
See TracChangeset
for help on using the changeset viewer.
