SO_RCVBUF
- The "SO_" prefix is for "socket option"
- Settings for the per-socket buffers.
- It is the size of the buffer, the kernel allocates to hold the data arriving into the given socket during the time between it arrives over the network and when it is read by the program that owns this socket.
- For TCP:
- If data arrives and you aren't reading it, the buffer will fill up, and the sender will be told to slow down (using TCP window adjustment mechanism).
- For UDP:
- once the buffer is full, new packets will just be discarded.
SO_SNDBUF
- Similary to SO_RCVBUF this is for send buffer.
This is limited at system level by the below file
# cat /proc/sys/net/core/wmem_max
Note:
- In real time, Used TCP local socket for IPC & faced below buffer issue:
- Process A working on the data & send the value to process B, Process B process this data & response the result back to Process A to update his db.
- Usually Process A will do only 1 data, at a time, so never faced any issue.
- Some corner case, process A processing bulk data, and send the data to Process B and not processing the process B response.
- Hence response from process B is got full & process B start discarding the value due to socket full message.
Solution 1:
- Increase the socket buffer size using SO_SNDBUF, but could not increase double the system max size "core/wmem_max".
- Partially issue fixed without increase the system max "core/wmem_max", full complete fix need to increase the system max memory.
Solution 2:
- Instead of process only bulk data, process A can process 200 bulk data & give few second gap to process the Process B response.
- And the process the next set of message, batching the bulk data.
Conclusion:
- Instead of increase the system wide memory, its good to do the batching. Hence batching is selected.
Program:
Makefile:
CC = gcc
SO_FLAGS = -fPIC -shared
exe:libsock.so
gcc select_stream_cli.c -L . -l sock -o cli -lpthread
gcc select_stream_ser.c -L . -l sock -o ser
libsock.so:
$(CC) ../socket_buf_inc.c $(SO_FLAGS) -o ../libsock.so
clean:
rm libsock.so cli ser
socket_buf_inc.h:
#ifndef __SOCKET_BUF_INC__H__
#define __SOCKET_BUF_INC__H__
void socket_non_blocking(int soc_fd);
void soc_get_so_rcv_buf(int sock_fd, char *msg);
void soc_set_so_rcv_buf(int sock_fd, size_t size);
#endif /* __SOCKET_BUF_INC__H__ */
"../socket_buf_inc.c":
/* Increase socket buffer size using SO_RCVBUF & SO_SNDBUF
* Check : http://velrajcoding.blogspot.in
*/
#include <stdio .h>
// Below 2 for getsockopt & setsockopt
#include <sys/types.h>
#include <sys/socket.h>
#include <errno.h> // for errno
#include <unistd.h> // For fcntl
#include <fcntl.h> // For fcntl
#include <string.h> // For strerror
//#define SO_RCV_BUFFER_SIZE 425984
/******************************************************************************
* FUNCTION NAME: socket_non_blocking
*
* DESCRIPTION : Set the socket fd as non blocking socket
*
* RETURNS : None
******************************************************************************/
void socket_non_blocking(int soc_fd)
{
int flags_non_blk = 0;
if ((flags_non_blk = fcntl(soc_fd, F_GETFL)) == -1) {
printf("Failed to get flags, so didn't set the block buffer errno <%d>(%s) \n", errno, strerror(errno));
return;
}
if (fcntl(soc_fd, F_SETFL, (flags_non_blk | O_NONBLOCK)) == -1) {
printf("Failed to set the block buffer errno <%d>(%s) \n", errno, strerror(errno));
}
printf("The socket:%d is set as non-blocking socket \n", soc_fd);
return;
}
/******************************************************************************
* FUNCTION NAME: soc_get_so_rcv_buf
*
* DESCRIPTION : Retrieve the socket receive buffer size
*
* RETURNS : None
******************************************************************************/
void soc_get_so_rcv_buf(int sock_fd, char *msg)
{
unsigned int size = 0;
socklen_t socklen = sizeof(size);
getsockopt(sock_fd, SOL_SOCKET, SO_RCVBUF, &size, &socklen);
printf("Socket receive buffer %s size:%u \n", msg, size);
}
/******************************************************************************
* FUNCTION NAME: soc_get_so_snd_buf
*
* DESCRIPTION : Retrieve the socket receive buffer size
*
* RETURNS : None
******************************************************************************/
void soc_get_so_snd_buf(int sock_fd, char *msg)
{
unsigned int size = 0;
socklen_t socklen = sizeof(size);
getsockopt(sock_fd, SOL_SOCKET, SO_SNDBUF, &size, &socklen);
printf("Socket send buffer %s size:%u \n", msg, size);
return;
}
/******************************************************************************
* FUNCTION NAME: soc_set_so_rcv_buf
*
* DESCRIPTION : Set the socket receive buffer size
*
* RETURNS : None
******************************************************************************/
void soc_set_so_rcv_buf(int sock_fd, size_t size)
{
// unsigned int size = SO_RCV_BUFFER_SIZE;
socklen_t socklen = sizeof(size);
soc_get_so_rcv_buf(sock_fd, "Before set the value");
if (setsockopt(sock_fd, SOL_SOCKET, SO_RCVBUF, &size, socklen) == -1) {
printf("Failed to set the socket receive buffer as %zu, errno <%d>(%s)", size, errno, strerror(errno));
}
soc_get_so_rcv_buf(sock_fd, "After set the value");
return;
}
/******************************************************************************
* FUNCTION NAME: soc_set_so_rcv_buf
*
* DESCRIPTION : Set the socket receive buffer size
*
* RETURNS : None
******************************************************************************/
void soc_set_so_snd_buf(int sock_fd, size_t size)
{
socklen_t socklen = sizeof(size);
soc_get_so_snd_buf(sock_fd, "Before set the value");
if (setsockopt(sock_fd, SOL_SOCKET, SO_SNDBUF, &size, socklen) == -1) {
printf("Failed to set the socket send buffer as %zu, errno <%d>(%s)", size, errno, strerror(errno));
}
soc_get_so_snd_buf(sock_fd, "After set the value");
return;
}
Server program: select_stream_ser.c
/* Increase socket buffer size using SO_RCVBUF & SO_SNDBUF
* Check : http://velrajcoding.blogspot.in
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h> // for bool data type
#include <math.h>
#include <signal.h>
#include <sys/ioctl.h> //* Ioctl & FION
#define ADDRESS "/home/labuser/highPriority" /* addr to connect */
#define ADDRESS_LOW "/home/labuser/lowPriority" /* addr to connect */
#define FALSE 0
#define TRUE 1
#define SO_RCV_BUFFER_SIZE 425984
struct sock_db;
typedef struct sock_db sock_db_t;
typedef void (*fd_callback_t) (int fd, void *data);
struct sock_db{
sock_db_t *next;
int fd;
int sock_domain;
char name[128];
bool isHighPriority;
fd_callback_t read_callback;
};
// Globle Declaratoin
int lock = 0;
int gtotal_db = 0;
sock_db_t *top = NULL;
int gDestroyed = 0;
int max(int firstValue, int secondValue)
{
int result = 0;
if(firstValue > secondValue)
result = firstValue;
else
result = secondValue;
return result;
}
int lock_acquire()
{
lock = 1;
}
int lock_release()
{
lock = 0;
}
int lock_check_and_wait()
{
while(lock)
{
printf("Vel %s inside lock sleep for 200 milli second \n", __FUNCTION__);
usleep(200);
}
}
void insert_node(sock_db_t *node)
{
if(!top)
{
top = node;
top->next = NULL;
}
else
{
node->next = top;
top = node;
}
}
sock_db_t *create_entry(char *name, int sock_domain)
{
sock_db_t *node;
node = (sock_db_t *)calloc(1, sizeof(sock_db_t));
if(node == NULL)
{
printf("No memory to allocate \n");
exit(1);
}
strcpy(node->name, name);
node->next = NULL;
node->sock_domain = sock_domain;
lock_check_and_wait();
lock_acquire();
insert_node(node);
gtotal_db++;
lock_release();
return node;
}
int ipc_init_unix(char *path, fd_callback_t callback)
{
int flags = 1; /*to set to non-blocking*/
int len;
struct sockaddr_un saun, clun;
sock_db_t *sock_entry = NULL;
sock_entry = create_entry("db_un", AF_UNIX);
/*
* get a socket to work with. this socket will
* be in the unix domain, and will be a
* stream socket.
*/
sock_entry->fd = socket(AF_UNIX, SOCK_STREAM, 0);
if ((sock_entry->fd) < 0) {
perror("server: socket");
exit(1);
}
/*Set it to non-blocking fd*/
ioctl(sock_entry->fd, FIONBIO, &flags);
saun.sun_family = AF_UNIX;
strcpy(saun.sun_path, path);
unlink(path);
len = sizeof(saun.sun_family) + strlen(saun.sun_path);
if(!strcmp(path, ADDRESS))
sock_entry->isHighPriority = 1;
else
sock_entry->isHighPriority = 0;
if (bind(sock_entry->fd, (struct sockaddr *) &saun, len) < 0) {
perror("server: bind");
exit(1);
}
soc_get_so_rcv_buf(sock_entry->fd, "Socket");
if (listen(sock_entry->fd, 4) < 0)
{
return -1;
}
sock_entry->read_callback = callback;
return sock_entry->fd;
}
sock_db_t *find_entry(int fd)
{
sock_db_t *sock_entry = top;
while(sock_entry)
{
if(sock_entry->fd == fd)
return sock_entry;
sock_entry = sock_entry->next;
}
return NULL;
}
int destroy(int des_fd)
{
sock_db_t *temp = top, *prev = NULL;
lock_check_and_wait();
lock_acquire();
prev = temp;
// printf("Vel %s %p %p %p \n", __FUNCTION__, top, temp, prev);
while(temp)
{
if(temp->fd == des_fd)
{
if(temp == top)
{
top = top->next;
free(temp);
}
else
{
prev->next = temp->next;
free(temp);
}
gDestroyed = 1;
gtotal_db--;
goto end;
}
prev = temp;
temp = temp->next;
}
end:
lock_release();
}
void client_recv(int cli_fd, void *data)
{
char str[128] = {0};
sock_db_t *sock_entry = NULL;
int nbyteRec = 0;
sock_entry = find_entry(cli_fd);
if(!sock_entry)
{
printf("Error Count not find the fd = %d \n",cli_fd);
return;
}
printf("Sleep for 4 second before process the msg \n");
sleep(4);
memset(str, 0, sizeof(str));
nbyteRec = read(cli_fd, str, sizeof(str));
str[nbyteRec] = '\0';
*(int*)data = nbyteRec;
if(nbyteRec)
printf("Msg Received:: Fd = %d Name= %s, Msg= %s ", cli_fd, sock_entry->name, str);
else if(nbyteRec ==0)
{
printf("Vel %s Received byte is 0. Destory the Fd = %d \n", __FUNCTION__, cli_fd);
destroy(cli_fd);
}
else
perror("Read failure ");
fflush(stdout);
}
void client_accept(int listen_fd, void *data)
{
sock_db_t *server, *cli;
struct sockaddr_un client_addr;
int addrlen = 0, flags = 1, fd = 0;
server = find_entry(listen_fd);
addrlen = sizeof(client_addr);
fd = accept(listen_fd, (struct sockaddr *)&client_addr, &addrlen);
if(fd < 0)
return;
cli = create_entry("db", server->sock_domain);
cli->isHighPriority = server->isHighPriority;
cli->fd = fd;
/*
* Since the send is got failed, so needed to increase only the buffer in sender side,
* Don't need to increase in receiver side. Hence commented below line
*/
//soc_set_so_rcv_buf(cli->fd, SO_RCV_BUFFER_SIZE);
/*Set it to non-blocking fd*/
ioctl(cli->fd, FIONBIO, &flags);
*(int *) data = cli->fd;
printf("Vel %s Find new clinet = %d \n", __FUNCTION__, cli->fd);
cli->read_callback = client_recv;
}
char gFdList[256] = {0};
int fdset_prepare(fd_set *read_fd_set)
{
int maxfd = -1, nOfClient = 0;
sock_db_t *sock_entry = top;
char temp[16];
FD_ZERO(read_fd_set);
memset(gFdList, 0, sizeof(gFdList));
while(sock_entry)
{
if(sock_entry->read_callback)
{
FD_SET(sock_entry->fd, read_fd_set);
maxfd = max(sock_entry->fd, maxfd);
sprintf(temp,"%d, ",sock_entry->fd);
strcat(gFdList, temp);
}
sock_entry = sock_entry->next;
nOfClient++;
}
return maxfd;
}
//#define DEBUG
int fdset_process(fd_set *read_fd_set, int *nready)
{
sock_db_t *db_high = top, *db_low = top;
int countHigh = 0, countLow = 0;
int high_read_cout = 0, low_read_count = 0;
int recv_count = 0, count_not_high = 0, count_not_low = 0;
bool isFlagHighEndDB = FALSE, isFlagLowEndDB = FALSE;
high_read_cout = 6;
low_read_count = 3;
//countHigh = 1;
//countLow = 1;
while((db_high || db_low)&& ((isFlagHighEndDB == FALSE) || (isFlagLowEndDB == FALSE)))
{
#ifdef DEBUG
printf("Vel %s inside while \n", __FUNCTION__);
#endif
while(countHigh < high_read_cout && db_high)
{
// printf("Vel %s inside while fd= %d Lw fd = %d is-Hi = %d \n", __FUNCTION__, db_high->fd,db_low->fd, (int) FD_ISSET(db_high->fd, read_fd_set));
if(FD_ISSET(db_high->fd, read_fd_set) && db_high->read_callback && db_high->isHighPriority)
{
db_high->read_callback(db_high->fd, &recv_count);
if(gDestroyed == 1)
{
printf("Stop processing the Client Since the Database is modified \n");
return 0;
}
if(recv_count <=0)
{
int temp = db_high->fd;
FD_CLR(temp, read_fd_set);
}
(*nready)--;
/* Here using 2 loop for single database. So if there is any change in database(EG: Client disconnect the link)
then 2nd loop will be affected. Used gDestoryed to stop looping.
Need to check this condition in our if we use the 2 while loop. */
countHigh++;
}
else
count_not_high++;
db_high = db_high->next;
if(db_high == NULL)
{
// printf("Vel %s Start again High priority from Top gtotal_db = %d countNot = %d \n", __FUNCTION__, gtotal_db, count_not_high);
if(count_not_high != gtotal_db)
db_high = top;
count_not_high = 0;
isFlagHighEndDB = TRUE;
}
}
//#ifdef DEBUG
#if 0
printf("Vel %s inside while after high prir= %d H= %p L= %p\n", __FUNCTION__, countHigh, db_high, db_low);
#endif
while(countLow < low_read_count && db_low)
{
// printf("Vel %s LFd= %d is -low= %d \n", __FUNCTION__, db_low->fd, (int) FD_ISSET(db_low->fd, read_fd_set));
if(FD_ISSET(db_low->fd, read_fd_set) && db_low->read_callback && (db_low->isHighPriority == 0))
{
db_low->read_callback(db_low->fd, &recv_count);
if(gDestroyed == 1)
{
printf("Stop processing the Client Since the Database is modified \n");
return 0;
}
if(recv_count <=0)
{
int temp = db_low->fd;
FD_CLR(temp, read_fd_set);
}
(*nready)--;
countLow++;
}
else
count_not_low++;
db_low = db_low->next;
// printf("Vel %s Start again low priority from Top gtotal = %d countlow = %d \n", __FUNCTION__, gtotal_db, count_not_low);
if(db_low == NULL)
{
if(count_not_low != gtotal_db)
db_low= top;
count_not_low = 0;
isFlagLowEndDB = TRUE;
}
}
}
// printf("Vel %s End *** \n", __FUNCTION__);
}
int ipc_handle_input(unsigned int wait_sec, unsigned int wait_usec)
{
struct timeval timeout;
int max_fd = 0, nready = 0;
fd_set rd_fds;
timeout.tv_sec = wait_sec;
timeout.tv_usec = wait_usec;
max_fd = fdset_prepare(&rd_fds);
nready = select(max_fd+1, &rd_fds, NULL, NULL, &timeout);
if (nready < 0)
{
printf("Vel Error in reading Select \n");
return 2;
}
else if (nready == 0)
{
printf("Timed out !! Available Client FD list = %s \r\n", gFdList);
timeout.tv_sec = 300;
timeout.tv_usec = 0;
}
else
{
// printf("Vel %s process \n", __FUNCTION__);
fdset_process(&rd_fds, &nready);
}
return 0;
}
main()
{
int sock= 0, sockHigh= 0;
sock = ipc_init_unix(ADDRESS_LOW, client_accept);
sockHigh = ipc_init_unix(ADDRESS, client_accept);
while(1)
{
gDestroyed = 0;
ipc_handle_input(300,0);
}
/*
* We can simply use close() to terminate the
* connection, since we're done with both sides.
*/
close(sock);
close(sockHigh);
exit(0);
}
Client program: select_stream_cli.c
/* Increase socket buffer size using SO_RCVBUF & SO_SNDBUF
* Check : http://velrajcoding.blogspot.in
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h> // for pthread
#include <sys/ioctl.h>
#include <signal.h>
#include <errno.h>
#define NSTRS 3 /* no. of strings */
#define ADDRESS "/home/labuser/highPriority" /* addr to connect */
#define ADDRESS_LOW "/home/labuser/lowPriority" /* addr to connect */
#define SO_SND_BUFFER_SIZE 425984
int connectToIPCconnection(char *path)
{
int s;
struct sockaddr_un sockaddun = {0};
/*
* Get a socket to work with. This socket will
* be in the UNIX domain, and will be a
* stream socket.
*/
if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
perror("client: socket");
exit(1);
}
/*
* Create the address we will be connecting to.
*/
sockaddun.sun_family = AF_UNIX;
strcpy(sockaddun.sun_path, path);
if(connect(s, (struct sockaddr *)&sockaddun, sizeof(struct sockaddr_un)) < 0)
{
printf("Vel Error connectiong \n");
}
// soc_set_so_snd_buf(s, SO_SND_BUFFER_SIZE);
return s;
}
struct sockidstruct
{
int sockId;
char name[128];
};
void *thread_send_high_message(void *sockDetails)
{
int i, iSendBytes = 0;
struct sockidstruct *saunDet = NULL;
char str[128];
saunDet = sockDetails;
/* Send high priority message to server */
for (i = 0; i < 800; i++)
{
// if(i == 40)
// usleep(1);
memset(str, 0, sizeof(str));
snprintf(str, sizeof(str), "HIGH priority Msg from client = \"%s\" Number of message = %d \n", saunDet->name, i+1);
iSendBytes = sendto(saunDet->sockId, str, sizeof(str) /* strlen(str)*/, 0 /*MSG_DONTWAIT */,NULL, 0);
if(iSendBytes > 0)
{
printf("Send High Msg byte = %d Msg count = %d \n", iSendBytes, i+1);
} else {
printf("Error in sending errno %d:%s\n", errno, strerror(errno));
}
}
return NULL;
}
void *thread_send_low_message(void *sockDetails)
{
int i, iSendBytes = 0;
struct sockidstruct *saunDet = NULL;
char str[128];
saunDet = sockDetails;
/* Send Low priority message to server */
for (i = 0; i < 40; i++)
{
/// if(i == 20)
// usleep(1);
memset(str, 0, sizeof(str));
snprintf(str, sizeof(str), "LOW priority Msg from client = \"%s\" Number of message = %d \n", saunDet->name, i+1);
iSendBytes = sendto(saunDet->sockId, str, sizeof(str) /*strlen(str)*/, 0 /*MSG_DONTWAIT */, NULL, 0);
if(iSendBytes > 0 )
printf("Send Low Msg Byte = %d msg count = %d \n", iSendBytes, i+1);
}
return NULL;
}
int main(int argc , char **argv)
{
char c;
int i, sockHigh, sockLow;
pthread_t thread_id_high, thread_id_low;
struct sockidstruct saunIdDet, saunIdDetLow;
/*
* Flags:
* 1 -> For non blocking
* 0 -> For blocking
*/
int flags = 1, HighLowOrBoth = 0;
// printf("vel argc = %d 1= %s 2 = %s \n", argc, argv[0], argv[1]);
if(argc >1 )
{
strcpy(saunIdDet.name, argv[1]);
strcpy(saunIdDetLow.name, argv[1]);
if(argc >2)
{
HighLowOrBoth = atoi(argv[2]);
}
}
sockHigh = connectToIPCconnection(ADDRESS);
sockLow = connectToIPCconnection(ADDRESS_LOW);
/*Set it to non-blocking fd*/
ioctl(sockLow, FIONBIO, &flags);
ioctl(sockHigh, FIONBIO, &flags);
// socket_non_blocking(sockHigh);
// socket_non_blocking(sockLow);
saunIdDet.sockId = sockHigh;
saunIdDetLow.sockId = sockLow;
//sleep(1);
if(HighLowOrBoth == 0)
{
pthread_create(&thread_id_low, NULL, &thread_send_low_message, &saunIdDetLow);
pthread_create(&thread_id_high, NULL, &thread_send_high_message, &saunIdDet);
printf("Vel High & LOW both Message will be send... \n");
}
else if(HighLowOrBoth == 1)
{
pthread_create(&thread_id_high, NULL, &thread_send_high_message, &saunIdDet);
printf("Vel Only High Message will be send");
}
else
{
pthread_create(&thread_id_low, NULL, &thread_send_low_message, &saunIdDetLow);
printf("Vel Only Low Message will be send");
}
pthread_join(thread_id_high, NULL);
// pthread_join(thread_id_low, NULL);
// sleep(20);
/*
* We can simply use close() to terminate the
* connection, since we're done with both sides.
*/
close(sockHigh);
close(sockLow);
exit(0);
}
Output:
Without Increase the buffer:
Server:
set_soc_buffer/tcp$ ./ser
Socket receive buffer Socket size:212992
Socket receive buffer Socket size:212992
Vel client_accept Find new clinet = 5
Vel client_accept Find new clinet = 6
Sleep for 4 second before process the msg
Msg Received:: Fd = 6 Name= db, Msg= LOW priority Msg from client = "" Number of message = 1
Sleep for 4 second before process the msg
^C
Client:
set_soc_buffer/tcp$ ./cli
Vel High & LOW both Message will be send...
Send Low Msg Byte = 128 msg count = 1
Send Low Msg Byte = 128 msg count = 2
Send Low Msg Byte = 128 msg count = 3
Send Low Msg Byte = 128 msg count = 4
Send Low Msg Byte = 128 msg count = 5
Send Low Msg Byte = 128 msg count = 6
Send Low Msg Byte = 128 msg count = 7
Send Low Msg Byte = 128 msg count = 8
Send Low Msg Byte = 128 msg count = 9
Send Low Msg Byte = 128 msg count = 10
Send Low Msg Byte = 128 msg count = 11
Send Low Msg Byte = 128 msg count = 12
Send Low Msg Byte = 128 msg count = 13
Send Low Msg Byte = 128 msg count = 14
Send Low Msg Byte = 128 msg count = 15
Send Low Msg Byte = 128 msg count = 16
Send High Msg byte = 128 Msg count = 1
Send Low Msg Byte = 128 msg count = 17
Send Low Msg Byte = 128 msg count = 18
Send Low Msg Byte = 128 msg count = 19
Send Low Msg Byte = 128 msg count = 20
Send Low Msg Byte = 128 msg count = 21
Send Low Msg Byte = 128 msg count = 22
Send Low Msg Byte = 128 msg count = 23
Send Low Msg Byte = 128 msg count = 24
Send Low Msg Byte = 128 msg count = 25
Send Low Msg Byte = 128 msg count = 26
Send Low Msg Byte = 128 msg count = 27
Send Low Msg Byte = 128 msg count = 28
Send Low Msg Byte = 128 msg count = 29
Send Low Msg Byte = 128 msg count = 30
Send Low Msg Byte = 128 msg count = 31
.
.
.
-----Same mesage just icnremnet upto 276 ----
Send High Msg byte = 128 Msg count = 277
Send High Msg byte = 128 Msg count = 278
Error in sending errno 11:Resource temporarily unavailable
Error in sending errno 11:Resource temporarily unavailable
Error in sending errno 11:Resource temporarily unavailable
Error in sending errno 11:Resource temporarily unavailable
Error in sending errno 11:Resource temporarily unavailable
Error in sending errno 11:Resource temporarily unavailable
Error in sending errno 11:Resource temporarily unavailable
Error in sending errno 11:Resource temporarily unavailable
Error in sending errno 11:Resource temporarily unavailable
Error in sending errno 11:Resource temporarily unavailable
Error in sending errno 11:Resource temporarily unavailable
Error in sending errno 11:Resource temporarily unavailable
Error in sending errno 11:Resource temporarily unavailable
Error in sending errno 11:Resource temporarily unavailable
Error in sending errno 11:Resource temporarily unavailable
Increment the send buffer alone and check:
Server Output:
set_soc_buffer/tcp$ ./ser
Socket receive buffer Socket size:212992
Socket receive buffer Socket size:212992
Socket receive buffer Before set the value size:212992
Socket receive buffer After set the value size:425984
Vel client_accept Find new clinet = 5
Socket receive buffer Before set the value size:212992
Socket receive buffer After set the value size:425984
Vel client_accept Find new clinet = 6
Sleep for 4 second before process the msg
Msg Received:: Fd = 6 Name= db, Msg= LOW priority Msg from client = "" Number of message = 1
Sleep for 4 second before process the msg
Msg Received:: Fd = 6 Name= db, Msg= LOW priority Msg from client = "" Number of message = 2
Sleep for 4 second before process the msg
Msg Received:: Fd = 6 Name= db, Msg= LOW priority Msg from client = "" Number of message = 3
Sleep for 4 second before process the msg
Msg Received:: Fd = 5 Name= db, Msg= HIGH priority Msg from client = "" Number of message = 1
Sleep for 4 second before process the msg
Msg Received:: Fd = 5 Name= db, Msg= HIGH priority Msg from client = "" Number of message = 2
Sleep for 4 second before process the msg
Msg Received:: Fd = 5 Name= db, Msg= HIGH priority Msg from client = "" Number of message = 3
Sleep for 4 second before process the msg
Msg Received:: Fd = 5 Name= db, Msg= HIGH priority Msg from client = "" Number of message = 4
Sleep for 4 second before process the msg
Msg Received:: Fd = 5 Name= db, Msg= HIGH priority Msg from client = "" Number of message = 5
Sleep for 4 second before process the msg
Msg Received:: Fd = 5 Name= db, Msg= HIGH priority Msg from client = "" Number of message = 6
Sleep for 4 second before process the msg
Msg Received:: Fd = 6 Name= db, Msg= LOW priority Msg from client = ""
Client Output:
set_soc_buffer/tcp$ ./cli
Socket send buffer Before set the value size:212992
Socket send buffer After set the value size:425984
Socket send buffer Before set the value size:212992
Socket send buffer After set the value size:425984
Vel High & LOW both Message will be send...
Send Low Msg Byte = 128 msg count = 1
Send Low Msg Byte = 128 msg count = 2
Send Low Msg Byte = 128 msg count = 3
Send Low Msg Byte = 128 msg count = 4
Send Low Msg Byte = 128 msg count = 5
Send Low Msg Byte = 128 msg count = 6
Send Low Msg Byte = 128 msg count = 7
Send Low Msg Byte = 128 msg count = 8
Send Low Msg Byte = 128 msg count = 9
Send Low Msg Byte = 128 msg count = 10
Send Low Msg Byte = 128 msg count = 11
.
.
.
-----Same mesage just icnremnet upto 551 ---- Send High Msg byte = 128 Msg count = 552
Send High Msg byte = 128 Msg count = 553
Send High Msg byte = 128 Msg count = 554
Send High Msg byte = 128 Msg count = 555
Error in sending errno 11:Resource temporarily unavailable
Error in sending errno 11:Resource temporarily unavailable
Error in sending errno 11:Resource temporarily unavailable
Error in sending errno 11:Resource temporarily unavailable
Error in sending errno 11:Resource temporarily unavailable
Error in sending errno 11:Resource temporarily unavailable
Error in sending errno 11:Resource temporarily unavailable
Error in sending errno 11:Resource temporarily unavailable
Error in sending errno 11:Resource temporarily unavailable
Error in sending errno 11:Resource temporarily unavailable
Error in sending errno 11:Resource temporarily unavailable
Error in sending errno 11:Resource temporarily unavailable
Error in sendin
Reference:
https://stackoverflow.com/questions/4257410/what-are-so-sndbuf-and-so-recvbuf