Small fixes to get really working control sockets on Windows.

This commit is contained in:
Guus Sliepen 2009-11-07 16:09:56 +01:00
parent 5c5548fc71
commit c388527e34
2 changed files with 9 additions and 6 deletions

View file

@ -217,8 +217,15 @@ bool init_control() {
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;
@ -275,8 +282,8 @@ bool init_control() {
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);

View file

@ -296,7 +296,7 @@ static int fullread(int fd, void *data, size_t datalen) {
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)
@ -478,8 +478,6 @@ int main(int argc, char *argv[], char *envp[]) {
return 1;
}
fprintf(stderr, "Got socket %d\n", fd);
unsigned long arg = 0;
if(ioctlsocket(fd, FIONBIO, &arg) != 0) {
@ -529,8 +527,6 @@ int main(int argc, char *argv[], char *envp[]) {
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));