addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(0x7f000001);
addr.sin_port = htons(55555);
+ int option = 1;
control_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ if(control_socket < 0) {
+ logger(LOG_ERR, "Creating control socket failed: %s", sockstrerror(sockerrno));
+ goto bail;
+ }
+
+ setsockopt(control_socket, SOL_SOCKET, SO_REUSEADDR, &option, sizeof option);
#else
struct sockaddr_un addr;
char *lastslash;
result = bind(control_socket, (struct sockaddr *)&addr, sizeof addr);
if(result < 0 && sockinuse(sockerrno)) {
- result = connect(control_socket, (struct sockaddr *)&addr, sizeof addr);
#ifndef HAVE_MINGW
+ result = connect(control_socket, (struct sockaddr *)&addr, sizeof addr);
if(result < 0) {
logger(LOG_WARNING, "Removing old control socket.");
unlink(controlsocketname);
int rv, len = 0;
while(len < datalen) {
- rv = read(fd, data + len, datalen - len);
+ rv = recv(fd, data + len, datalen - len, 0);
if(rv == -1 && errno == EINTR)
continue;
else if(rv == -1)
return 1;
}
- fprintf(stderr, "Got socket %d\n", fd);
-
unsigned long arg = 0;
if(ioctlsocket(fd, FIONBIO, &arg) != 0) {
return 1;
}
- fprintf(stderr, "Connected!\n");
-
if(fullread(fd, &greeting, sizeof greeting) == -1) {
fprintf(stderr, "Cannot read greeting from control socket: %s\n",
sockstrerror(sockerrno));