Small fixes to get really working control sockets on Windows.
This commit is contained in:
parent
5c5548fc71
commit
c388527e34
2 changed files with 9 additions and 6 deletions
|
@ -217,8 +217,15 @@ bool init_control() {
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_addr.s_addr = htonl(0x7f000001);
|
addr.sin_addr.s_addr = htonl(0x7f000001);
|
||||||
addr.sin_port = htons(55555);
|
addr.sin_port = htons(55555);
|
||||||
|
int option = 1;
|
||||||
|
|
||||||
control_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
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
|
#else
|
||||||
struct sockaddr_un addr;
|
struct sockaddr_un addr;
|
||||||
char *lastslash;
|
char *lastslash;
|
||||||
|
@ -275,8 +282,8 @@ bool init_control() {
|
||||||
result = bind(control_socket, (struct sockaddr *)&addr, sizeof addr);
|
result = bind(control_socket, (struct sockaddr *)&addr, sizeof addr);
|
||||||
|
|
||||||
if(result < 0 && sockinuse(sockerrno)) {
|
if(result < 0 && sockinuse(sockerrno)) {
|
||||||
result = connect(control_socket, (struct sockaddr *)&addr, sizeof addr);
|
|
||||||
#ifndef HAVE_MINGW
|
#ifndef HAVE_MINGW
|
||||||
|
result = connect(control_socket, (struct sockaddr *)&addr, sizeof addr);
|
||||||
if(result < 0) {
|
if(result < 0) {
|
||||||
logger(LOG_WARNING, "Removing old control socket.");
|
logger(LOG_WARNING, "Removing old control socket.");
|
||||||
unlink(controlsocketname);
|
unlink(controlsocketname);
|
||||||
|
|
|
@ -296,7 +296,7 @@ static int fullread(int fd, void *data, size_t datalen) {
|
||||||
int rv, len = 0;
|
int rv, len = 0;
|
||||||
|
|
||||||
while(len < datalen) {
|
while(len < datalen) {
|
||||||
rv = read(fd, data + len, datalen - len);
|
rv = recv(fd, data + len, datalen - len, 0);
|
||||||
if(rv == -1 && errno == EINTR)
|
if(rv == -1 && errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
else if(rv == -1)
|
else if(rv == -1)
|
||||||
|
@ -478,8 +478,6 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "Got socket %d\n", fd);
|
|
||||||
|
|
||||||
unsigned long arg = 0;
|
unsigned long arg = 0;
|
||||||
|
|
||||||
if(ioctlsocket(fd, FIONBIO, &arg) != 0) {
|
if(ioctlsocket(fd, FIONBIO, &arg) != 0) {
|
||||||
|
@ -529,8 +527,6 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "Connected!\n");
|
|
||||||
|
|
||||||
if(fullread(fd, &greeting, sizeof greeting) == -1) {
|
if(fullread(fd, &greeting, sizeof greeting) == -1) {
|
||||||
fprintf(stderr, "Cannot read greeting from control socket: %s\n",
|
fprintf(stderr, "Cannot read greeting from control socket: %s\n",
|
||||||
sockstrerror(sockerrno));
|
sockstrerror(sockerrno));
|
||||||
|
|
Loading…
Reference in a new issue