ipc: simplify IPC creation, make it work on Windows as well.
Summary: Windows names are inside \\.\pipe\ namespace and shouldn't contain "/", actually even on UNIX it is not required to craft the whole path as ecore_ipc/ecore_con will automatically encode based on local/system local, name and port. Reviewers: stephenmhouston, vtorri Differential Revision: https://phab.enlightenment.org/D4755
This commit is contained in:
parent
c6e6047d1a
commit
e27b26ebe1
|
@ -2,8 +2,6 @@
|
|||
#undef ERR
|
||||
#define ERR(...) do { printf(__VA_ARGS__); putc('\n', stdout); } while(0)
|
||||
|
||||
char *e_ipc_socket = NULL;
|
||||
|
||||
#ifdef USE_IPC
|
||||
/* local subsystem functions */
|
||||
static Eina_Bool _e_ipc_cb_client_del(void *data EINA_UNUSED, int type EINA_UNUSED, void *event);
|
||||
|
@ -17,53 +15,19 @@ static Ecore_Ipc_Server *_e_ipc_server = NULL;
|
|||
int
|
||||
e_ipc_init(void)
|
||||
{
|
||||
char buf[4096], buf3[4096];
|
||||
const char *tmp, *user, *base = NULL;
|
||||
int pid, trynum = 0, id1 = 0;
|
||||
|
||||
tmp = eina_environment_tmp_get();
|
||||
if (ecore_file_is_dir(tmp) && ecore_file_can_write(tmp))
|
||||
base = tmp;
|
||||
else
|
||||
ERR("Temp dir could not be accessed");
|
||||
|
||||
#ifdef _WIN32
|
||||
user = getenv("USERNAME");
|
||||
#else
|
||||
user = getenv("USER");
|
||||
#endif
|
||||
|
||||
setenv("EPHOTO_IPC_SOCKET", "", 1);
|
||||
|
||||
pid = (int)getpid();
|
||||
for (trynum = 0; trynum <= 4096; trynum++)
|
||||
{
|
||||
snprintf(buf, sizeof(buf), "%s/e-%s@%x",
|
||||
base, user, id1);
|
||||
if (!mkdir(buf, S_IRWXU))
|
||||
{
|
||||
#ifdef USE_IPC
|
||||
snprintf(buf3, sizeof(buf3), "%s/%i",
|
||||
buf, pid);
|
||||
_e_ipc_server = ecore_ipc_server_add
|
||||
(ECORE_IPC_LOCAL_SYSTEM, buf3, 0, NULL);
|
||||
if (_e_ipc_server)
|
||||
#endif
|
||||
{
|
||||
e_ipc_socket = strdup(ecore_file_file_get(buf));
|
||||
break;
|
||||
}
|
||||
}
|
||||
id1 = rand();
|
||||
}
|
||||
#ifdef USE_IPC
|
||||
int port = getpid();
|
||||
/* NOTE: windows has no getppid(), so use an envvar */
|
||||
char port_str[sizeof("2147483648")] = "";
|
||||
snprintf(port_str, sizeof(port_str), "%d", port);
|
||||
setenv("EPHOTO_IPC_PORT", port_str, 1);
|
||||
_e_ipc_server = ecore_ipc_server_add
|
||||
(ECORE_IPC_LOCAL_SYSTEM, "ephoto", port, NULL);
|
||||
if (!_e_ipc_server)
|
||||
{
|
||||
ERR("Gave up after 4096 sockets in '%s'. All failed", base);
|
||||
ERR("Couldn't create Ephoto IPC server port=%d", port);
|
||||
return 0;
|
||||
}
|
||||
setenv("EPHOTO_IPC_SOCKET", "", 1);
|
||||
setenv("EPHOTO_IPC_SOCKET", buf3, 1);
|
||||
ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DEL,
|
||||
_e_ipc_cb_client_del, NULL);
|
||||
ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DATA,
|
||||
|
@ -82,7 +46,6 @@ e_ipc_shutdown(void)
|
|||
_e_ipc_server = NULL;
|
||||
}
|
||||
#endif
|
||||
free(e_ipc_socket);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -114,19 +114,20 @@ main(int argc,
|
|||
static int
|
||||
_e_ipc_init(void)
|
||||
{
|
||||
char *sdir;
|
||||
|
||||
sdir = getenv("EPHOTO_IPC_SOCKET");
|
||||
if (!sdir)
|
||||
const char *port_str = getenv("EPHOTO_IPC_PORT");
|
||||
int port;
|
||||
if ((!port_str) || ((port = atoi(port_str)) == 0))
|
||||
{
|
||||
printf("The EPHOTO_IPC_SOCKET environment variable is not set. This is\n"
|
||||
"exported by Enlightenment to all processes it launches.\n"
|
||||
"This environment variable must be set and must point to\n"
|
||||
"Enlightenment's IPC socket file (minus port number).\n");
|
||||
printf("Error: could not query Ephoto IPC port=%s\n", port_str);
|
||||
return 0;
|
||||
}
|
||||
_e_ipc_server = ecore_ipc_server_connect
|
||||
(ECORE_IPC_LOCAL_SYSTEM, "ephoto", port, NULL);
|
||||
if (!_e_ipc_server)
|
||||
{
|
||||
printf("Error: could not connect to Ephoto IPC port=%d\n", port);
|
||||
return 0;
|
||||
}
|
||||
_e_ipc_server = ecore_ipc_server_connect(ECORE_IPC_LOCAL_SYSTEM, sdir, 0, NULL);
|
||||
if (!_e_ipc_server) return 0;
|
||||
|
||||
ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_ADD, _e_ipc_cb_server_add, NULL);
|
||||
ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_DEL, _e_ipc_cb_server_del, NULL);
|
||||
|
|
Loading…
Reference in New Issue