X-Git-Url: http://www.lcore.org/git/lcore.git/blobdiff_plain/5131f0f4f11d06c8d638c798dc1445fa52092510..90c7057fc0ae5d85a6443e7633642ef43553ab28:/lcore.pas

diff --git a/lcore.pas b/lcore.pas
index 69da11e..c936b59 100755
--- a/lcore.pas
+++ b/lcore.pas
@@ -16,21 +16,21 @@ unit lcore;
 {$ifdef fpc}
   {$mode delphi}
 {$endif}
-{$ifdef win32}
+{$ifdef mswindows}
   {$define nosignal}
 {$endif}
 interface
   uses
     sysutils,
-    {$ifndef win32}
+    {$ifndef mswindows}
       {$ifdef VER1_0}
         linux,
       {$else}
-        baseunix,unix,unixutil,
+        baseunix,unix,unixutil,sockets,
       {$endif}
       fd_utils,
     {$endif}
-    classes,pgtypes,bfifo;
+    classes,pgtypes,bfifo,ltimevalstuff;
   procedure processtasks;
 
 
@@ -106,7 +106,7 @@ interface
       lasterror:integer;
       destroying:boolean;
       recvbufsize:integer;
-      function receivestr:string; virtual;
+      function receivestr:tbufferstring; virtual;
       procedure close;
       procedure abort;
       procedure internalclose(error:word); virtual;
@@ -119,8 +119,8 @@ interface
       procedure dup(invalue:longint);
 
       function sendflush : integer;
-      procedure sendstr(const str : string);virtual;
-      procedure putstringinsendbuffer(const newstring : string);
+      procedure sendstr(const str : tbufferstring);virtual;
+      procedure putstringinsendbuffer(const newstring : tbufferstring);
       function send(data:pointer;len:integer):integer;virtual;
       procedure putdatainsendbuffer(data:pointer;len:integer); virtual;
       procedure deletebuffereddata;
@@ -136,9 +136,9 @@ interface
 
       function RealSend(Data : Pointer; Len : Integer) : Integer; //added for bewarehttpd
 
-      procedure myfdclose(fd : integer); virtual;{$ifdef win32}abstract;{$endif}
-      function myfdwrite(fd: LongInt;const buf;size: LongInt):LongInt; virtual;{$ifdef win32}abstract;{$endif}
-      function myfdread(fd: LongInt;var buf;size: LongInt):LongInt; virtual;{$ifdef win32}abstract;{$endif}
+      procedure myfdclose(fd : integer); virtual;{$ifdef mswindows}abstract;{$endif}
+      function myfdwrite(fd: LongInt;const buf;size: LongInt):LongInt; virtual;{$ifdef mswindows}abstract;{$endif}
+      function myfdread(fd: LongInt;var buf;size: LongInt):LongInt; virtual;{$ifdef mswindows}abstract;{$endif}
     protected
       procedure dupnowatch(invalue:longint);
     end;
@@ -154,12 +154,6 @@ interface
   var
     timerwrapperinterface : ttimerwrapperinterface;
   type
-    {$ifdef win32}
-      ttimeval = record
-        tv_sec : longint;
-        tv_usec : longint;
-      end;
-    {$endif}
     tltimer=class(tlcomponent)
     protected
 
@@ -171,7 +165,7 @@ interface
       fontimer            : tnotifyevent      ;
       fenabled            : boolean           ;
       finterval	          : integer	     ; {miliseconds, default 1000}
-      {$ifndef win32}
+      {$ifndef mswindows}
         procedure resettimes;
       {$endif}
 //      procedure setinitialevent(newvalue : boolean);
@@ -254,29 +248,30 @@ implementation
 {$ifndef nosignal}
   uses {sockets,}lloopback,lsignal;
 {$endif}
-{$ifdef win32}
+{$ifdef mswindows}
   uses windows,winsock;
 {$endif}
-{$ifndef win32}
+{$ifndef mswindows}
   {$include unixstuff.inc}
 {$endif}
-{$include ltimevalstuff.inc}
 
 
 {!!! added sleep call -beware}
 procedure sleep(i:integer);
+{$ifdef mswindows}
+begin
+  windows.sleep(i);
+{$else}
 var
   tv:ttimeval;
 begin
-  {$ifdef win32}
-    windows.sleep(i);
-  {$else}
-    tv.tv_sec := i div 1000;
-    tv.tv_usec := (i mod 1000) * 1000;
-    select(0,nil,nil,nil,@tv);
-  {$endif}
+  tv.tv_sec := i div 1000;
+  tv.tv_usec := (i mod 1000) * 1000;
+  select(0,nil,nil,nil,@tv);
+{$endif}
 end;
 
+
 destructor tlcomponent.destroy;
 begin
   disconnecttasks(self);
@@ -400,13 +395,13 @@ begin
     eventcore.wmasterclr(fdhandleout);//fd_clr(fdhandleout,fdswmaster);
 
     if closehandles then begin
-      {$ifndef win32}
+      {$ifndef mswindows}
         //anyone remember why this is here? --plugwash
         fcntl(fdhandlein,F_SETFL,0);
       {$endif}
       myfdclose(fdhandlein);
       if fdhandleout <> fdhandlein then begin
-        {$ifndef win32}
+        {$ifndef mswindows}
           fcntl(fdhandleout,F_SETFL,0);
         {$endif}
         myfdclose(fdhandleout);
@@ -449,13 +444,13 @@ begin
   end;
 end;
 
-procedure tlasio.sendstr(const str : string);
+procedure tlasio.sendstr(const str : tbufferstring);
 begin
   putstringinsendbuffer(str);
   sendflush;
 end;
 
-procedure tlasio.putstringinsendbuffer(const newstring : string);
+procedure tlasio.putstringinsendbuffer(const newstring : tbufferstring);
 begin
   if newstring <> '' then putdatainsendbuffer(@newstring[1],length(newstring));
 end;
@@ -533,7 +528,7 @@ begin
   fdhandlein := invalue;
   fdhandleout := invalue;
   eventcore.setfdreverse(fdhandlein,self);
-  {$ifndef win32}
+  {$ifndef mswindows}
     fcntl(fdhandlein,F_SETFL,OPEN_NONBLOCK);
   {$endif}
   state := wsconnected;
@@ -566,7 +561,7 @@ begin
           internalclose(0);
 
         end else begin
-          {$ifdef win32}
+          {$ifdef mswindows}
           if getlasterror=WSAEWOULDBLOCK then begin
             //the asynchronous nature of windows messages means we sometimes
             //get here with the buffer full
@@ -574,7 +569,7 @@ begin
           end else
           {$endif}
           begin
-            internalclose({$ifdef win32}getlasterror{$else}linuxerror{$endif});
+            internalclose({$ifdef mswindows}getlasterror{$else}linuxerror{$endif});
           end  
         end;
       end;
@@ -601,7 +596,7 @@ begin
 
         internalclose(0);
       end else if (numread=-1) then begin
-        {$ifdef win32}
+        {$ifdef mswindows}
           //sometimes on windows we get stale messages due to the inherent delays
           //in the windows message queue
           if WSAGetLastError = wsaewouldblock then begin
@@ -610,7 +605,7 @@ begin
         {$endif}
         begin
           numread := 0;
-          internalclose({$ifdef win32}wsagetlasterror{$else}linuxerror{$endif});
+          internalclose({$ifdef mswindows}wsagetlasterror{$else}linuxerror{$endif});
         end;
       end else if numread > 0 then recvq.add(@tempbuf,numread);
     end;
@@ -627,7 +622,7 @@ begin
 end;
 
 procedure tlasio.flush;
-{$ifdef win32}
+{$ifdef mswindows}
 type fdset = tfdset;
 {$endif}
 var
@@ -656,7 +651,7 @@ begin
   tlasio(sender).recvq.del(maxlongint);
 end;
 
-{$ifndef win32}
+{$ifndef mswindows}
   procedure tltimer.resettimes;
   begin
     gettimeofday(nextts);
@@ -697,7 +692,7 @@ begin
     if assigned(timerwrapperinterface) then begin
       timerwrapperinterface.setenabled(wrappedtimer,newvalue);
     end else begin
-      {$ifdef win32}
+      {$ifdef mswindows}
         raise exception.create('non wrapper timers are not permitted on windows');
       {$else}
         resettimes;
@@ -713,7 +708,7 @@ begin
     if assigned(timerwrapperinterface) then begin
       timerwrapperinterface.setinterval(wrappedtimer,newvalue);
     end else begin
-      {$ifdef win32}
+      {$ifdef mswindows}
         raise exception.create('non wrapper timers are not permitted on windows');
       {$else}
         resettimes;
@@ -872,7 +867,7 @@ begin
   if (result > 0) and assigned(onsenddata) then onsenddata(self,result);
   eventcore.wmasterset(fdhandleout);
 end;
-{$ifndef win32}
+{$ifndef mswindows}
   procedure tlasio.myfdclose(fd : integer);
   begin
     fdclose(fd);