From: plugwash <plugwash@p10link.net>
Date: Fri, 12 Feb 2010 00:51:00 +0000 (+0000)
Subject: make some os-x related fixes to lmessages
X-Git-Url: http://www.lcore.org/git/lcore.git/commitdiff_plain/f8e139db970666e906db30417763f81e2ae5e801

make some os-x related fixes to lmessages

force bindv6only to 0 to make things behave with debian squeeze+  (note: this
is likely to break on some operating systems but I suspect said operating
systems were broken already)



git-svn-id: file:///svnroot/lcore/trunk@73 b1de8a11-f9be-4011-bde0-cc7ace90066a
---

diff --git a/lmessages.pas b/lmessages.pas
index a7bd01e..39f6f92 100755
--- a/lmessages.pas
+++ b/lmessages.pas
@@ -78,6 +78,7 @@ const
   WM_USER = 1024;
   WM_TIMER = 275;
   INFINITE = syncobjs.infinite;
+
 function getwindowlongptr(ahwnd:hwnd;nindex:integer) : taddrint;
 function setwindowlongptr(ahwnd:hwnd;nindex:integer;dwNewLong : taddrint) : taddrint;
 function DefWindowProc(ahWnd:HWND; auMsg:Integer; awParam:WPARAM; alParam:LPARAM):Integer; stdcall;
@@ -103,6 +104,7 @@ uses
 {$i unixstuff.inc}
 
 type
+  
   tmessageintransit = class
     msg : tmsg;
     next : tmessageintransit;
@@ -114,7 +116,7 @@ type
     waiting : boolean;
     lcorethread : boolean;
     nexttimer : ttimeval;
-    threadid : integer;
+    threadid : tthreadid;
   end;
   twindow=class
     hwnd : hwnd;
@@ -138,15 +140,15 @@ var
 
 
 //findthreaddata should only be called while holding the structurelock
-function findthreaddata(threadid : integer) : tthreaddata;
+function findthreaddata(threadid : tthreadid) : tthreaddata;
 begin
-  result := tthreaddata(findtree(@threaddata,inttostr(threadid)));
+  result := tthreaddata(findtree(@threaddata,inttostr(taddrint(threadid))));
   if result = nil then begin
     result := tthreaddata.create;
     result.messageevent := teventobject.create(nil,false,false,inttostr(taddrint(result)));
     result.nexttimer := tv_invalidtimebig;
     result.threadid := threadid;
-    addtree(@threaddata,inttostr(threadid),result);
+    addtree(@threaddata,inttostr(taddrint(threadid)),result);
   end;
 end;
 
@@ -160,7 +162,7 @@ begin
     //writeln('freeing thread data object');
     athreaddata.free;
     //writeln('deleting thread data object from hashtable');
-    deltree(@threaddata,inttostr(athreaddata.threadid));
+    deltree(@threaddata,inttostr(taddrint(athreaddata.threadid)));
     //writeln('finished deleting thread data');
   end else begin
     //writeln('thread data is not unused');
@@ -292,7 +294,7 @@ begin
       //writeln('aboute to delete window from windows structure');
       deltree(@windows,inttostr(ahwnd));
       //writeln('deleted window from windows structure');
-      windowthreaddata := tthreaddata(findtree(@threaddata,inttostr(window.threadid)));
+      windowthreaddata := tthreaddata(findtree(@threaddata,inttostr(taddrint(window.threadid))));
 
       if windowthreaddata <> nil then begin
         //writeln('found thread data scanning for messages to clean up');
diff --git a/lsocket.pas b/lsocket.pas
index af3faf8..c099cf5 100755
--- a/lsocket.pas
+++ b/lsocket.pas
@@ -177,10 +177,6 @@ end;
   begin
     result := getpeername(sock,addr,addrlen);
   end;
-  function system_getsocketname(Sock: LongInt;var Addr;var Addrlen: LongInt):LongInt;
-  begin
-    result := getsocketname(sock,addr,addrlen);
-  end;
   function system_listen(Sock: LongInt; MaxConnect: LongInt):Boolean;
   begin
     result := listen(sock,maxconnect);
@@ -373,7 +369,7 @@ end;
 
 procedure tlsocket.listen;
 var
-  yes:longint;
+  yes,no:longint;
   socktype:integer;
   biniptemp:tbinip;
   origaddr:string;
@@ -412,10 +408,14 @@ begin
   try
     yes := $01010101;  {Copied this from existing code. Value is empiric,
                     but works. (yes=true<>0) }
+    no := 0;
     {$ifndef win32}
       if SetSocketOptions(fdhandlein, SOL_SOCKET, SO_REUSEADDR,yes,sizeof(yes))=-1 then begin
         raise ESocketException.create('unable to set socket options');
       end;
+      if SetSocketOptions(fdhandlein, IPPROTO_IPV6,IPV6_V6ONLY,no,sizeof(no))=-1 then begin
+        raise ESocketException.create('unable to set socket options');
+      end;
     {$endif}
     localaddr := addr;
     localport := port;
@@ -690,7 +690,7 @@ begin
   {$ifdef win32}
     winsock.getsockname(self.fdhandlein,psockaddr(@addr)^,i);
   {$else}
-    system_getsocketname(self.fdhandlein,addr,i);
+    getsocketname(self.fdhandlein,addr,i);
   {$endif}
   binip := inaddrvtobinip(addr);
   converttov4(binip);
@@ -741,7 +741,7 @@ begin
     winsock.getsockname(self.fdhandlein,psockaddrin(@addr)^,i);
 
   {$else}
-    system_getsocketname(self.fdhandlein,addr,i);
+    getsocketname(self.fdhandlein,addr,i);
 
   {$endif}
   result := inttostr(htons(addr.InAddr.port));