YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

Debugger sometimes not connects - bind() returns EADDRINUSE
belbardonisakel
#1 Posted : Friday, December 25, 2015 12:37:02 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 6/28/2015(UTC)
Posts: 9
Location: Germany

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Hello Squirrel Developers

i had some problems with the debugger. In linux sometimes it's not possible to attach the debugger because of an still open handle. The reason is that bind() fails and returns EADDRINUSE.

The problem with solution is described here:
http://stackoverflow.com...hen-other-side-connects

If you're interrested, here is my patch to sqrdbg.cpp including some minor changes due to error verbosity and removed some warnings in my environment:

The main point is to add:
setsockopt(rdbg->_accept, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));


2,10c2,6
< #ifdef _WIN32
< # include <winsock.h>
< #else
< # include <sys/types.h>
< # include <sys/socket.h>
< # include <arpa/inet.h>
< # include <sys/time.h>
< # define SOCKET_ERROR (-1)
< # define TIMEVAL struct timeval
---
> #if defined(WIN32)
> #include <winsock.h>
> #if !defined(_WIN32)
> #define _WIN32
> #endif
12,15d7
< #include <stdio.h>
< #include <string.h>
< #include <squirrel.h>
< #include <squirrel.h>
17a10,13
> #include <stdio.h>
> #include <string.h>
> #include <errno.h>
>
25c21
< struct sockaddr_in bindaddr;
---
> sockaddr_in bindaddr = {0};
34a31,37
> // taken from http://stackoverflow.com/questions/10384575/
> // why-might-bind-sometimes-give-eaddrinuse-when-other-side-connects
> int yes = 1;
> #if !defined(WIN32)
> setsockopt(rdbg->_accept, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
> #endif
40c43,44
< sq_throwerror(v,_SC("failed to bind the socket"));
---
> sq_throwerror(v,_SC("failed to bind the socket\n"));
> fprintf(stderr,"failed to initialize the debugger - errno is %d\n",errno);
45a50
> fprintf(stderr,"failed to initialize the debugger\n");
61a67,69
> #if defined(WIN32)
> int addrlen=sizeof(cliaddr);
> #else
62a71
> #endif
80c89
< TIMEVAL time;
---
> struct timeval time;
86c95
< select(NULL/*ignored*/, &read_flags, NULL, NULL, &time);
---
> select(rdbg->_endpoint+1, &read_flags, NULL, NULL, &time);
103c112
< if(size >= sizeof(temp)-2) break;
---
> if(((unsigned)size) >= (sizeof(temp)-2)) break;
154c163
< scprintf(_SC("*FUNCTION [%s] %s line [%d]\n"),fn,src,si.line);
---
> scprintf(_SC("*FUNCTION [%s] %s line [%d]\n"),fn,src,(int)si.line);
169d177
<

Regards
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Clean Slate theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.121 seconds.