2021SC@SDUSC
目录
searpc_server_register_marshal
server遗留问题
searpc_server_call_function
char*
searpc_server_call_function (const char *svc_name,
gchar *func, gsize len, gsize *ret_len)
{
SearpcService *service;
json_t *array;
char* ret;
json_error_t jerror;
GError *error = NULL;
#ifdef __linux__
struct timeval start, end, intv;
if (slow_log_fp) {
gettimeofday(&start, NULL);
}
#endif
service = g_hash_table_lookup (service_table, svc_name);
if (!service) {
char buf[256];
snprintf (buf, 255, "cannot find service %s.", svc_name);
return error_to_json (501, buf, ret_len);
}
array = json_loadb (func, len, 0 ,&jerror);
if (!array) {
char buf[512];
setjetoge(&jerror,&error);
snprintf (buf, 511, "failed to load RPC call: %s\n", error->message);
json_decref (array);
g_error_free(error);
return error_to_json (511, buf, ret_len);
}
const char *fname = json_string_value (json_array_get(array, 0));
FuncItem *fitem = g_hash_table_lookup(service->func_table, fname);
if (!fitem) {
char buf[256];
snprintf (buf, 255, "cannot find function %s.", fname);
json_decref (array);
return error_to_json (500, buf, ret_len);
}
ret = fitem->marshal->mfunc (fitem->func, array, ret_len);
#ifdef __linux__
if (slow_log_fp) {
gettimeofday(&end, NULL);
timersub(&e