Project

General

Profile

Actions

Support #2935

closed

ksocket_sendmsg EINTR error

Added by eric zhang almost 9 years ago. Updated about 7 years ago.

Status:
Closed
Priority:
Immediate
Assignee:
-
Category:
-
Start date:
2012-06-26
Due date:
% Done:

0%

Estimated time:
Tags:
needs-triage
Gerrit CR:

Description

i have one program to act client and server, when the client send msg to server, it's normally at start, but after many minutes or hours, it return error code 4(#define EINTR 4 /* interrupted system call */),

client code:

int ret = DDI_SUCCESS;
struct sockaddr_in addr;
bzero(&addr, sizeof(struct sockaddr_in));
addr.sin_family = AF_INET;
//inet_pton(AF_INET, ip_str, &addr.sin_addr);
addr.sin_addr.s_addr = inet_addr(ip_str);
addr.sin_port = htons(3015);
char ip1024;
inet_ntop(AF_INET, &addr.sin_addr, ip, sizeof(ip));
cmn_err(CE_WARN, "ip:%s", ip);
ksocket_t connect_sock = NULL;
ret = ksocket_socket(&connect_sock, AF_INET, SOCK_STREAM, IPPROTO_TCP, KSOCKET_SLEEP, CRED);
if(ret != DDI_SUCCESS) {
cmn_err(CE_WARN,"create client socket fail, errorcode=%d", ret);
ret = DDI_FAILURE;
return ret;
}
ret = ksocket_connect(connect_sock, (struct sockaddr *)&addr,
sizeof(struct sockaddr_in), CRED);
if(ret != DDI_SUCCESS) {
cmn_err(CE_WARN,"connect to host fail, errorcode=%d", ret);
ksocket_close(connect_sock,CRED);
return DDI_FAILURE;
}

size_t buf_size = 40 * 1024;
void * buf = NULL;
//memset(buf, 'c', buf_size);
int flag = MSG_WAITALL;
size_t sent = 0;
uint64_t cnt = 0;
while(1) {
buf = kmem_zalloc(buf_size, KM_SLEEP);
struct msghdr msg;
bzero(&msg, sizeof(struct msghdr));
struct iovec iov;
bzero(&iov, sizeof(struct iovec));
msg.msg_flags = 0;
msg.msg_name = NULL;
msg.msg_namelen = 0;
iov.iov_base = buf;
iov.iov_len = buf_size;
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
int flag = MSG_WAITALL;
//ret = ksocket_send(connect_sock, buf, buf_size, flag, &sent, CRED());
ret = ksocket_sendmsg(connect_sock, &msg, flag, &sent, CRED());
kmem_free(buf, buf_size);
if(ret != DDI_SUCCESS) {
cmn_err(CE_WARN, "ksocket_send, errcode=%ld", ret);
}
cnt++;
if(cnt % 1000 == 0) {
cmn_err(CE_WARN, "cnt=%ld", cnt);
}
}
server code:

int ret = DDI_SUCCESS;
ksocket_t listening_sk = NULL;
struct sockaddr client_addr;
ksocket_t connect_sk = NULL;
socklen_t sock_len;
bzero(&client_addr, sizeof(struct sockaddr));
ret = sv_create_bind_socket(&listening_sk);
if(ret != DDI_SUCCESS || listening_sk == NULL) {
return ret;
}

cmn_err(CE_WARN,"before accept");
sock_len = sizeof(struct sockaddr_in);
ret = ksocket_accept(listening_sk, &client_addr, &sock_len, &connect_sk, CRED());
if(ret != DDI_SUCCESS) {
cmn_err(CE_WARN,"accept fail,errorcode=%ld", ret);
return DDI_FAILURE;
}
cmn_err(CE_WARN,"after accept");
delay(drv_usectohz(1));
size_t buf_size = 40 * 1024;
void *buf = NULL;
int avail = 0, ravail = 0;
size_t recv_size = 0;
int flag = MSG_WAITALL;
while(1) {
buf = kmem_zalloc(buf_size, KM_SLEEP);
ret = ksocket_recv(connect_sk, buf, buf_size, flag, &recv_size, CRED());
kmem_free(buf, buf_size);
if(ret != DDI_SUCCESS) {
cmn_err(CE_WARN, "ksocket_recv, errcode=%ld", ret);
delay(drv_usectohz(1));
}
}

my question is why it return errorcode 4, and how to fix it. thanks!

Actions

Also available in: Atom PDF