我有一个关于套接字的问题。我从客户端发送N个大小的数据到服务器,N个大小小于100字节。所以我认为我的数据不应该分割成多个tcp数据包。在我看来,客户端发送数据应该完成一次,服务器可以一次接收数据。但是结果并不令人满意。实际情况是服务器需要调用读取数据。我不明白。如下代码:
epoll_server.cpp(仅接收数据。)
#include <sys/socket.h>
#include <stdio.h>
#include <string.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/epoll.h>
#include <fcntl.h>
#include <netdb.h>
#define BUFSIZE 1024
#define INITSIZE 1024
#define MAXEVENTCOUNT 10240
// add non-blocking to sockfd
int make_socket_non_blocking(int fd)
{
// get initial flag
int src_flags;
src_flags= fcntl(fd, F_GETFL,0);
if(src_flags == -1)
{
perror("fcntl get error.");
return-1;
}
// add non-blocking
int new_flags = src_flags | O_NONBLOCK;
int ret_value;
ret_value = fcntl(fd, F_SETFL, new_flags);
if(ret_value == -1)
{ …Run Code Online (Sandbox Code Playgroud) 我正在阅读mongodb源代码.我有一个关于memory-map-file的问题.在DurableMappedFile类中有_view_write和_view_private._view_write用于保存映射的指针._view_private还保存映射的指针,但映射的指针是MAP_PRIVATE类型.MAP_PRIVATE是写时复制.我不知道什么场合会使用MAP_PRIVATE的指针.注意:DurableMappedFile类在durable_mapped_file.h/cpp.MongoDB中定义,源代码版本为2.6.12.