示例#1
0
文件: init.c 项目: kklt92/libnfs
struct rpc_context *rpc_init_context(void)
{
	struct rpc_context *rpc;
	static uint32_t salt = 0;
	unsigned int i;

	rpc = malloc(sizeof(struct rpc_context));
	if (rpc == NULL) {
		return NULL;
	}
	memset(rpc, 0, sizeof(struct rpc_context));

	rpc->magic = RPC_CONTEXT_MAGIC;

	/* Allow NFS_MAX_XFER_SIZE of data (for writes) and some */
	rpc->encodebuflen = NFS_MAX_XFER_SIZE + 4096;
	rpc->encodebuf = malloc(rpc->encodebuflen);
	if (rpc->encodebuf == NULL) {
		free(rpc);
		return NULL;
	}

	rpc->inbuflen = 2 * (NFS_MAX_XFER_SIZE + 4096);
	rpc->inbuf = malloc(rpc->inbuflen);
	if (rpc->inbuf == NULL) {
		free(rpc);
		return NULL;
	}

 	rpc->auth = authunix_create_default();
	if (rpc->auth == NULL) {
		free(rpc->encodebuf);
		free(rpc);
		return NULL;
	}
	rpc->xid = salt + time(NULL) + (getpid() << 16);
	salt += 0x01000000;
	rpc->fd = -1;
	rpc->tcp_syncnt = RPC_PARAM_UNDEFINED;
#if defined(WIN32) || defined(ANDROID)
	rpc->uid = 65534;
	rpc->gid = 65534;
#else
	rpc->uid = getuid();
	rpc->gid = getgid();
#endif
	rpc_reset_queue(&rpc->outqueue);
	for (i = 0; i < HASHES; i++)
		rpc_reset_queue(&rpc->waitpdu[i]);

	return rpc;
}
示例#2
0
文件: init.c 项目: keeely/libnfs
struct rpc_context *rpc_init_context(void)
{
	struct rpc_context *rpc;
	static uint32_t salt = 0;
	unsigned int i;

	rpc = malloc(sizeof(struct rpc_context));
	if (rpc == NULL) {
		return NULL;
	}
	memset(rpc, 0, sizeof(struct rpc_context));

	rpc->magic = RPC_CONTEXT_MAGIC;

 	rpc->auth = authunix_create_default();
	if (rpc->auth == NULL) {
		free(rpc);
		return NULL;
	}
	rpc->xid = salt + time(NULL) + (getpid() << 16);
	salt += 0x01000000;
	rpc->fd = -1;
	rpc->tcp_syncnt = RPC_PARAM_UNDEFINED;
	rpc->pagecache_ttl = NFS_PAGECACHE_DEFAULT_TTL;
#if defined(WIN32) || defined(ANDROID)
	rpc->uid = 0;
	rpc->gid = 0;
#else
	rpc->uid = getuid();
	rpc->gid = getgid();
#endif
	rpc_reset_queue(&rpc->outqueue);
	for (i = 0; i < HASHES; i++)
		rpc_reset_queue(&rpc->waitpdu[i]);

	/* Default is no timeout */
	rpc->timeout = -1;

	return rpc;
}
示例#3
0
文件: init.c 项目: keeely/libnfs
struct rpc_context *rpc_init_server_context(int s)
{
	struct rpc_context *rpc;

	rpc = malloc(sizeof(struct rpc_context));
	if (rpc == NULL) {
		return NULL;
	}
	memset(rpc, 0, sizeof(struct rpc_context));

	rpc->magic = RPC_CONTEXT_MAGIC;

	rpc->is_server_context = 1;
	rpc->fd = s;
	rpc->is_connected = 1;
        rpc->is_udp = rpc_is_udp_socket(rpc);
	rpc_reset_queue(&rpc->outqueue);

	return rpc;
}