???????????????????????
??????????????????????佨?????????socket??·?????????????
???????????????????????????????????socket?????????????????????????socket??????????????????????io?????б??У????????£?
int listenfd;
struct sockaddr_in server_sin;
/* establish socket */
listenfd=socket(AF_INET??SOCK_STREAM??0);
server_sin.sin_family=AF_INET;
server_sin.sin_addr.s_addr=htonl(INADDR_ANY);
server_sin.sin_port=htons(PORT);
bind(listenfd??(struct sockaddr *)&server_sin??sizeof(server_sin));
/* establish end */
listen(listenfd??1024);
qemu_set_fd_handler2(listenfd?? NULL?? tcpkeepalive_server?? NULL??
(void *)(intptr_t)listenfd);
??????socket??????????????£?
static void tcpkeepalive_server(void *opaque)
{
int connfd;
struct sockaddr_in client_sin;
socklen_t client_len=sizeof(client_sin);
int listenfd = (intptr_t)opaque;
connfd=accept(listenfd??(struct sockaddr *)&client_sin??&client_len);
}
????????????????儷????????????????socket?????????????????????????tcpkeepalive?????????socket????????????????io?????б??
?????????????socket?????????????????·??????????????????????????????????????????????????????????????tcpkeepalive???????????????????????????????????????????????????????????????????????????С?
??????????????£?
int sockfd;
struct sockaddr_in sin;
int optval;
socklen_t optlen = sizeof(optval);
sockfd=socket(AF_INET??SOCK_STREAM??0);
sin.sin_family=AF_INET;
sin.sin_addr.s_addr=addr.sin_addr.s_addr;
sin.sin_port=htons(PORT);
optval = 1;
setsockopt(sockfd?? SOL_SOCKET?? SO_KEEPALIVE?? &optval?? optlen);
optval = 5;
setsockopt(sockfd?? SOL_TCP?? TCP_KEEPCNT?? &optval?? optlen);
optval = 1;
setsockopt(sockfd?? SOL_TCP?? TCP_KEEPIDLE?? &optval?? optlen);
optval = 1;
setsockopt(sockfd?? SOL_TCP?? TCP_KEEPINTVL?? &optval?? optlen);
connect(sockfd??(struct sockaddr *)&sin??sizeof(sin));
qemu_set_fd_handler2(sockfd?? NULL?? tcpkeepalive_vm_start?? NULL??
(void *)(intptr_t)sockfd);
??????socket??????????????????????????????У?
????static void tcpkeepalive_vm_start(void *opaque)
????{
????vm_start();
????}