Fresh IDE . Check-in [f98c983f15]
Not logged in

This repository is a mirror!

The original is located on: https://fresh.flatassembler.net/fossil/repo/fresh
If you want to follow the project, please update your remote-url

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added SocketShutDown function in network.asm; Implemented for Win32 and Linux; FileExists function has been implemented as OS dependent for Linux and Win32 in order to make it much faster. Now it uses sys_newstat and GetFileAttributes insead of open attempt;
Timelines: family | ancestors | descendants | both | FreshLibDev
Files: files | file ages | folders
SHA1:f98c983f159d445ea31de2cb4ea27794f237c7bb
User & Date: johnfound 2017-04-13 15:15:17
Context
2017-04-13
15:19
Fixed small bug in uconfig.asm; The procedure _BlendPixel has been moved to the OS independent graphics/images.asm; The graphics/draw.asm procedure now is fully OS independent; check-in: bb87024e2e user: johnfound tags: FreshLibDev
15:15
Added SocketShutDown function in network.asm; Implemented for Win32 and Linux; FileExists function has been implemented as OS dependent for Linux and Win32 in order to make it much faster. Now it uses sys_newstat and GetFileAttributes insead of open attempt; check-in: f98c983f15 user: johnfound tags: FreshLibDev
2017-02-08
18:42
Work on different aspects of multithread applications, timers, event handling, etc. Implemented new debug macro: macro OutputCallStack depth {}; check-in: 43ff3d49ae user: johnfound tags: FreshLibDev
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to freshlib/equates/Linux/_linux.inc.

539
540
541
542
543
544
545








546
547
548
549
550
551
552
SYS_SHUTDOWN    = 13
SYS_SETSOCKOPT  = 14
SYS_GETSOCKOPT  = 15
SYS_SENDMSG     = 16
SYS_RECVMSG     = 17

;socket constants









AF_UNSPEC       = 0
AF_UNIX         = 1
AF_LOCAL        = 1
AF_INET         = 2
AF_AX25         = 3
AF_IPX          = 4







>
>
>
>
>
>
>
>







539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
SYS_SHUTDOWN    = 13
SYS_SETSOCKOPT  = 14
SYS_GETSOCKOPT  = 15
SYS_SENDMSG     = 16
SYS_RECVMSG     = 17

;socket constants

; SYS_SHUTDOWN argument:

SHUT_RD = 0
SHUT_WR = 1
SHUT_RDWR = 2

;

AF_UNSPEC       = 0
AF_UNIX         = 1
AF_LOCAL        = 1
AF_INET         = 2
AF_AX25         = 3
AF_IPX          = 4

Changes to freshlib/equates/Win32/_WSOCK32.INC.

171
172
173
174
175
176
177






178
179
180
181
182
183
184
FD_CLOSE        = 20h

; commands for ioctlsocket

FIONBIO         = 8004667Eh
FIONSYNC        = 8004667Dh
FIONREAD        = 4004667Fh








; flags

MSG_OOB       = 1
MSG_PEEK      = 2
MSG_DONTROUTE = 4







>
>
>
>
>
>







171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
FD_CLOSE        = 20h

; commands for ioctlsocket

FIONBIO         = 8004667Eh
FIONSYNC        = 8004667Dh
FIONREAD        = 4004667Fh

; Commands for shutdown

SD_RECEIVE = 0
SD_SEND    = 1
SD_BOTH    = 2


; flags

MSG_OOB       = 1
MSG_PEEK      = 2
MSG_DONTROUTE = 4

Changes to freshlib/system/Linux/files.asm.

535
536
537
538
539
540
541










































542
543
544
545
546
547
548
        mov     [esp], eax

        pop     eax ecx ebx edi
        stc
        return

endp












































flushInput = 0
flushOutput = 1
flushInputOutput = 2

TCFLSH  = $540B         ; Linux constant.







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
        mov     [esp], eax

        pop     eax ecx ebx edi
        stc
        return

endp



; Returns:
; CF=1 if the file NOT EXISTS
; CF=0 if the file EXISTS
body FileExists
.fstat STAT
begin
        pushad

        lea     edi, [.fstat]
        mov     ecx, sizeof.STAT / 4
        xor     eax, eax
        rep stosd

        if defined ptrStrTable
          stdcall StrPtr, [.hFileName]
          mov     ebx, eax
        else
          mov   ebx, [.hFileName]
        end if

        mov     eax, sys_newstat
        lea     ecx, [.fstat]
        int     80h
        test    eax, eax
        jz      .exists

; error
        stc
        popad
        return

.exists:
        clc
        popad
        return
endp





flushInput = 0
flushOutput = 1
flushInputOutput = 2

TCFLSH  = $540B         ; Linux constant.

Changes to freshlib/system/Linux/network.asm.

59
60
61
62
63
64
65





66

















67
68
69

70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98

        call    __SocketError
        pop     edx ecx ebx
        return
endp

























body SocketClose
;.buffer rb 1024
;.params rd 2

begin
        push    ebx ecx edx

;        push    [.hSocket]
;        pop     [.params]
;        mov     [.params+4], 1
;
;        mov     eax, sys_socketcall
;        mov     ebx, SYS_SHUTDOWN
;        lea     ecx, [.params]
;        int     $80
;        call    __SocketError
;        jc      .finish
;
;.loop:
;        lea     ecx, [.buffer]
;        stdcall SocketReceive, [.hSocket], ecx, 1024, 0
;        jc      .finish
;        test    eax, eax
;        jnz     .loop
;
;.finish:

        mov     eax, sys_close
        mov     ebx, [.hSocket]
        int     $80
        call    __SocketError

        pop     edx ecx ebx







>
>
>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

<
|
>



|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|







59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89

90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120

        call    __SocketError
        pop     edx ecx ebx
        return
endp


body SocketShutDown
.sock dd ?
.dir  dd ?
begin
        push    ebx ecx edx

        push    [.hSocket]
        pop     [.sock]
        mov     [.dir], SHUT_RDWR

        mov     eax, sys_socketcall
        mov     ebx, SYS_SHUTDOWN
        lea     ecx, [.sock]
        int     $80

        call    __SocketError

        pop     edx ecx ebx
        return
endp



body SocketClose

.params rd 2
.buffer rb 256
begin
        push    ebx ecx edx

        push    [.hSocket]
        pop     [.params]
        mov     [.params+4], SHUT_RDWR

        mov     eax, sys_socketcall
        mov     ebx, SYS_SHUTDOWN
        lea     ecx, [.params]
        int     $80
        call    __SocketError
        jc      .finish

.loop:
        lea     ecx, [.buffer]
        stdcall SocketReceive, [.hSocket], ecx, 256, 0
        jc      .finish
        test    eax, eax
        jnz     .loop

.finish:

        mov     eax, sys_close
        mov     ebx, [.hSocket]
        int     $80
        call    __SocketError

        pop     edx ecx ebx

Changes to freshlib/system/Win32/files.asm.

505
506
507
508
509
510
511





























.error:
        stc
        popad
        return

endp





































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
.error:
        stc
        popad
        return

endp





; Returns:
; CF=1 if the file NOT EXISTS
; CF=0 if the file EXISTS
body FileExists
begin
        pushad

        stdcall utf8ToWideChar, [.hFileName]
        push    eax

        invoke  GetFileAttributesW, eax
        stdcall FreeMem ; from the stack
        cmp     eax, -1
        je      .notexists

        clc
        popad
        return

.notexists:
        stc
        popad
        return
endp

Changes to freshlib/system/Win32/network.asm.

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
..
65
66
67
68
69
70
71












72
73
74
75
76
77
78
;
;  Notes: This library follows the rules of Berkley sockets library with some small
;         differences (for example in the return values)
;_________________________________________________________________________________________

uses wsock32, ws2_32

serrTimeout = 10060




uglobal
  __wsaData WSADATA
endg
................................................................................


body SocketCreate
begin
        push    ecx edx
        invoke  socket, [.protocol_family], [.socket_type], [.protocol]
        call    __SocketError












        pop     edx ecx
        return
endp



body SocketClose







|







 







>
>
>
>
>
>
>
>
>
>
>
>







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
..
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
;
;  Notes: This library follows the rules of Berkley sockets library with some small
;         differences (for example in the return values)
;_________________________________________________________________________________________

uses wsock32, ws2_32

serrTimeout = WSAETIMEDOUT




uglobal
  __wsaData WSADATA
endg
................................................................................


body SocketCreate
begin
        push    ecx edx
        invoke  socket, [.protocol_family], [.socket_type], [.protocol]
        call    __SocketError
        pop     edx ecx
        return
endp


body SocketShutDown
begin
        push    ecx edx

        invoke  shutdown, [.hSocket], SD_BOTH
        call    __SocketError

        pop     edx ecx
        return
endp



body SocketClose

Changes to freshlib/system/files.asm.

73
74
75
76
77
78
79

80
81
82
83
84
85
86
...
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
;   if error:     CF=1; eax = error code;

interface DirectoryRead, .dir


interface GetFileInfo, .hFile, .ptrFileInfo



interface CreateDirectory, .DirName



;--------------------------------------
; if CF = 0, eax is handle to the file.
................................................................................

.error:
        stc
        pop     edi
        return
endp




; Returns:
; CF=1 if the file NOT EXISTS
; CF=0 if the file EXISTS

proc FileExists, .ptrFileName
begin
        push    eax

        stdcall FileOpen, [.ptrFileName]
        jc      .exit
        stdcall FileClose, eax
        clc
.exit:
        pop     eax
        return
endp




; This structure contains one directory item information.
;

struct TDirItem







>







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
...
341
342
343
344
345
346
347




















348
349
350
351
352
353
354
;   if error:     CF=1; eax = error code;

interface DirectoryRead, .dir


interface GetFileInfo, .hFile, .ptrFileInfo

interface FileExists, .hFileName

interface CreateDirectory, .DirName



;--------------------------------------
; if CF = 0, eax is handle to the file.
................................................................................

.error:
        stc
        pop     edi
        return
endp
























; This structure contains one directory item information.
;

struct TDirItem

Changes to freshlib/system/network.asm.

60
61
62
63
64
65
66


67
68
69
70
71
72
73
soRecvTimeout = SO_RCVTIMEO     ; timeout in [ms] for all OSes
soSendTimeout = SO_SNDTIMEO     ; timeout in [ms] for all OSes
soLinger      = SO_LINGER       ; timout in [s]



interface SocketCreate, .protocol_family, .socket_type, .protocol



interface SocketClose, .hSocket

interface SocketConnect, .hSocket, .pAddress

interface SocketBind, .hSocket, .pAddress








>
>







60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
soRecvTimeout = SO_RCVTIMEO     ; timeout in [ms] for all OSes
soSendTimeout = SO_SNDTIMEO     ; timeout in [ms] for all OSes
soLinger      = SO_LINGER       ; timout in [s]



interface SocketCreate, .protocol_family, .socket_type, .protocol

interface SocketShutDown, .hSocket

interface SocketClose, .hSocket

interface SocketConnect, .hSocket, .pAddress

interface SocketBind, .hSocket, .pAddress