unsigned getBufferSize(int bufOptName,
int socket) {
unsigned curSize;
SOCKLEN_T sizeSize = sizeof curSize;
if (getsockopt(socket, SOL_SOCKET, bufOptName,
(char*)&curSize, &sizeSize) < 0) {
socketErr("getBufferSize() error: ");
return 0;
}
return curSize;
}
< 소켓 버퍼 사이즈 늘리기 설정 >
#ifndef SOCKLEN_T
#define SOCKLEN_T socklen_t
#endif
unsigned increaseBufferTo( int bufOptName,
int socket, unsigned requestedSize) {
// First, get the current buffer size. If it's already at least
// as big as what we're requesting, do nothing.
unsigned curSize = getBufferSize(bufOptName, socket);
// Next, try to increase the buffer to the requested size,
// or to some smaller size, if that's not possible:
while (requestedSize > curSize) {
SOCKLEN_T sizeSize = sizeof requestedSize;
if (setsockopt(socket, SOL_SOCKET, bufOptName,
(char*)&requestedSize, sizeSize) >= 0) {
// success
return requestedSize;
}
requestedSize = (requestedSize+curSize)/2;
}
return getBufferSize( bufOptName, socket);
}
< 함수 사용 >
// 송신버퍼 사이즈 늘리기
unsigned increaseSendBufferTo(int socket, unsigned requestedSize) {
return increaseBufferTo( SO_SNDBUF, socket, requestedSize);
}
// 수신버퍼 사이즈 늘리기
unsigned increaseReceiveBufferTo( int socket, unsigned requestedSize) {
return increaseBufferTo( SO_RCVBUF, socket, requestedSize);
}
< 함수 사용 >
int ret, size = 1024*1024;
if ((ret=increaseSendBufferTo(fsock, size)) != size)
printf("%s failed to increase send buffer size (size:%d, ret:%d)\r\n", __FUNCTION__, size, ret);
*** 버퍼 사이즈를 원하는 만큼 늘릴 수 없으면 윈도우 레지스트리 설정을 추가/수정해야한다.
[HKEY_LOCAL_MACHINE \SYSTEM \CurrentControlSet \Services \Afd \Parameters]
DefaultReceiveWindow = 16384
DefaultSendWindow = 16384
DefaultReceiveWindow = 16384
DefaultSendWindow = 16384
* 리부팅할 필요없고 위 레지스트리 값만 넣어주면된다.
댓글 없음:
댓글 쓰기