代码拉取完成,页面将自动刷新
同步操作将从 郭新华/php-cp 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/*
+----------------------------------------------------------------------+
| common con pool |
+----------------------------------------------------------------------+
| This source file is subject to version 2.0 of the Apache license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.apache.org/licenses/LICENSE-2.0.html |
| If you did not receive a copy of the Apache2.0 license and are unable|
| to obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Xinhua Guo <woshiguo35@sina.com>|
+----------------------------------------------------------------------+
*/
#include "php_connect_pool.h"
void *cp_mmap_calloc(int size)
{
void *mem;
int tmpfd = -1;
int flag = MAP_SHARED;
#ifdef MAP_ANONYMOUS
flag |= MAP_ANONYMOUS;
#else
char *mapfile = NULL;
if (mapfile == NULL)
{
mapfile = "/dev/zero";
}
if ((tmpfd = open(mapfile, O_RDWR)) < 0)
{
return NULL;
}
strncpy(object->mapfile, mapfile, SW_SHM_MMAP_FILE_LEN);
object->tmpfd = tmpfd;
#endif
mem = mmap(NULL, size, PROT_READ | PROT_WRITE, flag, tmpfd, 0);
#ifdef MAP_FAILED
if (mem == MAP_FAILED)
#else
if (!mem)
#endif
{
cpLog("mmap fail. Error: %s[%d]", strerror(errno), errno);
return NULL;
}
else
{
bzero(mem, size);
return mem;
}
}
int cp_create_mmap_dir()
{
umask(0);
if (access(CP_FILE_DIR, F_OK) == -1)
{
int ret = mkdir(CP_FILE_DIR, 0777);
if (ret == -1)
{
php_printf("mkdir fail. Error: %s[%d]", strerror(errno), errno);
return -1;
}
}
return 0;
};
int cp_create_mmap_file(cpShareMemory *object)
{
umask(0);
char tmp[100] = {0};
strncpy(tmp, CP_SERVER_MMAP_FILE, strlen(CP_SERVER_MMAP_FILE));
int fd = open(object->mmap_name, O_RDWR | O_CREAT, 0777);
if (fd == -1)
{
php_printf("open fail. Error: %s[%d],%s", strerror(errno), errno, object->mmap_name);
return -1;
}
ftruncate(fd, object->size); //extend 黑洞
close(fd);
return 0;
};
void* cp_mmap_calloc_with_file(cpShareMemory *object)
{
int fd = open(object->mmap_name, O_RDWR);
if (fd == -1)
{
cpLog("open fail. Error: %s[%d]", strerror(errno), errno);
return NULL;
}
void *mem = mmap(NULL, object->size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
#ifdef MAP_FAILED
if (mem == MAP_FAILED)
#else
if (!mem)
#endif
{
cpLog("mmap fail. Error: %s[%d]", strerror(errno), errno);
return NULL;
}
else
{
// bzero(mem, object->size);
object->mem = mem;
return mem;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。