i found question," select return -1,error=1", run filebeate in my instance.
test code:
main.go:
package main
/*
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <errno.h>
#include "demo_interface.h"
void init(){
int client_sockfd = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in address;
address.sin_family = AF_INET;
address.sin_addr.s_addr = inet_addr("192.168.194.37");
address.sin_port = htons(10095);
int len = sizeof(address);
int result = connect(client_sockfd, (struct sockaddr *)&address, len);
if (result != 0){
printf("connect error:%d\n",result);
return;
}
struct timeval tv;
fd_set readfds;
while(1){
tv.tv_sec=3;
tv.tv_usec=0;
FD_ZERO(&readfds);
FD_SET(client_sockfd,&readfds);
result = select(FD_SETSIZE,&readfds,NULL,NULL,&tv);
if (-1 ==result){
printf(" select error:%d\n",errno);
continue;
}
if(0 == result){
printf("select time out\n");
continue;
}
if( FD_ISSET(client_sockfd,&readfds)){
printf("client_sockfd is event:%d\n",client_sockfd);
FD_CLR(client_sockfd,&readfds);
continue;
}
}
}
*/
import "C"
import _ "fmt"
import "time"
import "GoProxy/module/beats/filebeat"
func main() {
go func() {
time.Sleep(10 * time.Second)
filebeat.Start1()
}()
C.init()
select {}
}
filebeat_instance.go:
import "fmt"
import "github.com/elastic/beats/filebeat/cmd"
func Start1() {
if err := cmd.RootCmd.Execute(); err != nil {
fmt.Println("error.....:", err.Error())
}
}
result:
10s before
client_sockfd is event 3
client_sockfd is event 3
client_sockfd is event 3
client_sockfd is event 3
client_sockfd is event 3
10s after,filebeat is run
select error:1
select error:1
select error:1
select error:1
select error:1
select error:1
select error:1
select error:1
[zhaoya@localhost test]$ ll /proc/122571/fd
total 0
lr-x------. 1 zhaoya zhaoya 64 Nov 23 02:54 0 -> pipe:[1358645]
l-wx------. 1 zhaoya zhaoya 64 Nov 23 02:54 1 -> pipe:[1358646]
l-wx------. 1 zhaoya zhaoya 64 Nov 23 02:54 2 -> pipe:[1358647]
lrwx------. 1 zhaoya zhaoya 64 Nov 23 02:54 3 -> socket:[1360307]
lrwx------. 1 zhaoya zhaoya 64 Nov 23 02:54 4 -> anon_inode:[eventpoll]
l-wx------. 1 zhaoya zhaoya 64 Nov 23 02:54 5 -> /home/zhaoya/go/src/GoProxy/test/filebeat/logs/filebeat
i dont'know question case. can you help me?