mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
add lua like path search for skynet module
path/?.so;another_path/?.so
This commit is contained in:
@@ -20,28 +20,40 @@ static struct modules * M = NULL;
|
|||||||
|
|
||||||
static void *
|
static void *
|
||||||
_try_open(struct modules *m, const char * name) {
|
_try_open(struct modules *m, const char * name) {
|
||||||
|
const char *l;
|
||||||
const char * path = m->path;
|
const char * path = m->path;
|
||||||
size_t path_size = strlen(path);
|
size_t path_size = strlen(path);
|
||||||
size_t name_size = strlen(name);
|
size_t name_size = strlen(name);
|
||||||
|
|
||||||
int sz = path_size + name_size;
|
int sz = path_size + name_size;
|
||||||
|
//search path
|
||||||
|
void * dl = NULL;
|
||||||
char tmp[sz];
|
char tmp[sz];
|
||||||
int i;
|
do
|
||||||
for (i=0;path[i]!='?' && path[i]!='\0';i++) {
|
{
|
||||||
tmp[i] = path[i];
|
memset(tmp,0,sz);
|
||||||
}
|
while (*path == ';') path++;
|
||||||
memcpy(tmp+i,name,name_size);
|
if (*path == '\0') break;
|
||||||
if (path[i] == '?') {
|
l = strchr(path, ';');
|
||||||
strcpy(tmp+i+name_size,path+i+1);
|
if (l == NULL) l = path + strlen(path);
|
||||||
} else {
|
int len = l - path;
|
||||||
fprintf(stderr,"Invalid C service path\n");
|
int i;
|
||||||
exit(1);
|
for (i=0;path[i]!='?' && i < len ;i++) {
|
||||||
}
|
tmp[i] = path[i];
|
||||||
|
}
|
||||||
void * dl = dlopen(tmp, RTLD_NOW | RTLD_GLOBAL);
|
memcpy(tmp+i,name,name_size);
|
||||||
|
if (path[i] == '?') {
|
||||||
|
strncpy(tmp+i+name_size,path+i+1,len - i - 1);
|
||||||
|
} else {
|
||||||
|
fprintf(stderr,"Invalid C service path\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
dl = dlopen(tmp, RTLD_NOW | RTLD_GLOBAL);
|
||||||
|
path = l;
|
||||||
|
}while(dl == NULL);
|
||||||
|
|
||||||
if (dl == NULL) {
|
if (dl == NULL) {
|
||||||
fprintf(stderr, "try open %s failed : %s\n",tmp,dlerror());
|
fprintf(stderr, "try open %s failed : %s\n",name,dlerror());
|
||||||
}
|
}
|
||||||
|
|
||||||
return dl;
|
return dl;
|
||||||
|
|||||||
Reference in New Issue
Block a user