author | Claus Gittinger <cg@exept.de> |
Sun, 05 Jan 2020 17:27:00 +0100 | |
changeset 25177 | 1c618f3d51f5 |
parent 25142 | bd49177015de |
child 25180 | 965b85dbd676 |
permissions | -rw-r--r-- |
25134 | 1 |
"{ Encoding: utf8 }" |
2 |
||
1 | 3 |
" |
5 | 4 |
COPYRIGHT (c) 1988 by Claus Gittinger |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5 |
All Rights Reserved |
1 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
5414 | 14 |
"{ Package: 'stx:libbasic' }" |
15 |
||
17418 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
1 | 18 |
ReadWriteStream subclass:#ExternalStream |
22848 | 19 |
instanceVariableNames:'handleType handle mode buffered binary eolMode hitEOF didWrite |
23744 | 20 |
lastErrorNumber readAhead dependents' |
22848 | 21 |
classVariableNames:'Lobby LastErrorNumber InvalidReadSignal InvalidWriteSignal |
22 |
InvalidModeSignal OpenErrorSignal StreamNotOpenSignal |
|
23 |
InvalidOperationSignal DefaultEOLMode ReadMode ReadWriteMode |
|
24 |
WriteMode AppendMode CreateReadWriteMode StreamIOErrorSignal |
|
25 |
FileOpenTrace MaxNonTenurableExecutors DefaultCopyBufferSize' |
|
26 |
poolDictionaries:'' |
|
27 |
category:'Streams-External' |
|
1 | 28 |
! |
29 |
||
216 | 30 |
!ExternalStream primitiveDefinitions! |
1 | 31 |
%{ |
10328
ad731a7584a3
ensure that win32_fwrite is used for stdout and stderr
Claus Gittinger <cg@exept.de>
parents:
9053
diff
changeset
|
32 |
#undef fwrite |
ad731a7584a3
ensure that win32_fwrite is used for stdout and stderr
Claus Gittinger <cg@exept.de>
parents:
9053
diff
changeset
|
33 |
|
17078 | 34 |
#include "stxOSDefs.h" |
35 |
||
1 | 36 |
#include <stdio.h> |
437 | 37 |
#define _STDIO_H_INCLUDED_ |
38 |
||
2903 | 39 |
#ifndef NO_FCNTL_H |
40 |
# include <fcntl.h> |
|
41 |
# define _FCNTL_H_INCLUDED_ |
|
42 |
#endif |
|
437 | 43 |
|
10 | 44 |
#include <errno.h> |
437 | 45 |
#define _ERRNO_H_INCLUDED_ |
42 | 46 |
|
1141 | 47 |
#ifdef LINUX |
48 |
/* use inline string macros */ |
|
49 |
# define __STRINGDEFS__ |
|
50 |
# include <linuxIntern.h> |
|
51 |
#endif |
|
52 |
||
16508 | 53 |
#if !defined(MSDOS_LIKE) && !defined(__openVMS__) |
54 |
# include <termios.h> |
|
55 |
#endif |
|
56 |
||
42 | 57 |
#ifdef hpux |
58 |
# define fileno(f) ((f->__fileH << 8) | (f->__fileL)) |
|
59 |
#endif |
|
216 | 60 |
|
933
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
61 |
#ifndef SEEK_SET |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
62 |
# define SEEK_SET 0 |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
63 |
#endif |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
64 |
#ifndef SEEK_CUR |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
65 |
# define SEEK_CUR 1 |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
66 |
#endif |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
67 |
#ifndef SEEK_END |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
68 |
# define SEEK_END 2 |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
69 |
#endif |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
70 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
71 |
#if defined(__VMS__) || defined(__sparc__) || defined(__win32__) |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
5101
diff
changeset
|
72 |
# define CLEAR_ERRNO __threadErrno = 0; |
2961 | 73 |
#else |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
74 |
# define CLEAR_ERRNO /* nothing */ |
2961 | 75 |
#endif |
76 |
||
3420 | 77 |
#ifdef LATER |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
78 |
# define __isFilePointer(x) (__Class(x) == ExternalStream__FilePointer) |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
79 |
# define __CHANGECLASS(o, x) (__qClass(o) = (x), o) |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
80 |
# define __MKFILEPOINTER(f) __CHANGECLASS(__MKEXTERNALADDRESS(f), ExternalStream__FilePointer) |
3420 | 81 |
#else |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
82 |
# define __MKFILEPOINTER(f) __MKEXTERNALADDRESS(f) |
3420 | 83 |
#endif |
84 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
85 |
#ifdef __win32__ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
86 |
# define NO_STDIO |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
87 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
88 |
# undef __HANDLE_INTERRUPTS__ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
89 |
# define __HANDLE_INTERRUPTS__ /* nothing */ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
90 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
91 |
# undef __BEGIN_INTERRUPTABLE__ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
92 |
# define __BEGIN_INTERRUPTABLE__ /* nothing */ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
93 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
94 |
# undef __END_INTERRUPTABLE__ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
95 |
# define __END_INTERRUPTABLE__ /* nothing */ |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
96 |
#endif |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
97 |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
98 |
# ifdef __i386__ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
99 |
# define _X86_ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
100 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
101 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
102 |
#ifdef __win32__ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
103 |
# undef INT |
14644 | 104 |
# undef UINT |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
105 |
# undef Array |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
106 |
# undef Number |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
107 |
# undef Method |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
108 |
# undef Point |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
109 |
# undef Rectangle |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
110 |
# undef Block |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
111 |
# undef Time |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
112 |
# undef Date |
7832 | 113 |
# undef Delay |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
114 |
# undef Set |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
115 |
# undef Signal |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
116 |
# undef Context |
9023 | 117 |
# undef Message |
9024 | 118 |
# undef Process |
10339 | 119 |
# undef Processor |
14632 | 120 |
# undef String |
121 |
# undef Character |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
122 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
123 |
# define NOATOM |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
124 |
# define NOGDICAPMASKS |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
125 |
# define NOMETAFILE |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
126 |
# define NOMINMAX |
14068 | 127 |
//# define NOOPENFILE |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
128 |
# define NOSOUND |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
129 |
# define NOWH |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
130 |
//# define NOCOMM |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
131 |
# define NOKANJI |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
132 |
# define NOCRYPT |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
133 |
//# define NOMCX |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
134 |
# define WIN32_LEAN_AND_MEAN |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
135 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
136 |
# include <windows.h> |
15435
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
137 |
# include <winsock2.h> |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
138 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
139 |
# ifdef __DEF_Array |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
140 |
# define Array __DEF_Array |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
141 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
142 |
# ifdef __DEF_Number |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
143 |
# define Number __DEF_Number |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
144 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
145 |
# ifdef __DEF_Method |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
146 |
# define Method __DEF_Method |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
147 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
148 |
# ifdef __DEF_Point |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
149 |
# define Point __DEF_Point |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
150 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
151 |
# ifdef __DEF_Block |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
152 |
# define Block __DEF_Block |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
153 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
154 |
# ifdef __DEF_Time |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
155 |
# define Time __DEF_Time |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
156 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
157 |
# ifdef __DEF_Date |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
158 |
# define Date __DEF_Date |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
159 |
# endif |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
160 |
# ifdef __DEF_Set |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
161 |
# define Set __DEF_Set |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
162 |
# endif |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
163 |
# ifdef __DEF_Signal |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
164 |
# define Signal __DEF_Signal |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
165 |
# endif |
7832 | 166 |
# ifdef __DEF_Delay |
167 |
# define Delay __DEF_Delay |
|
168 |
# endif |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
169 |
# ifdef __DEF_Context |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
170 |
# define Context __DEF_Context |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
171 |
# endif |
9023 | 172 |
# ifdef __DEF_Message |
173 |
# define Message __DEF_Message |
|
174 |
# endif |
|
9024 | 175 |
# ifdef __DEF_Process |
176 |
# define Process __DEF_Process |
|
177 |
# endif |
|
10339 | 178 |
# ifdef __DEF_Processor |
179 |
# define Processor __DEF_Processor |
|
180 |
# endif |
|
14632 | 181 |
# ifdef __DEF_String |
182 |
# define String __DEF_String |
|
183 |
# endif |
|
184 |
# ifdef __DEF_Character |
|
185 |
# define Character __DEF_Character |
|
186 |
# endif |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
187 |
|
14644 | 188 |
# define INT STX_INT |
189 |
# define UINT STX_UINT |
|
190 |
# ifndef off_t |
|
191 |
# define off_t long |
|
192 |
# endif |
|
23110 | 193 |
|
23111 | 194 |
size_t __win32_fwrite(char *, size_t , size_t , FILE *); |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
195 |
#endif /* __win32__ */ |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
196 |
|
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
197 |
#ifndef NO_STDIO /* use STDIO */ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
198 |
# define STDIO_NEEDS_FSEEK |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
199 |
# define FILEPOINTER FILE * |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
200 |
# define READ(f, cp, n) read(f, cp, n) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
201 |
# define WRITE(f, cp, n) write(f, cp, n) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
202 |
# define FFLUSH(fp) fflush(fp) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
203 |
# define FILENO(f) fileno(f) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
204 |
#endif /* use STDIO */ |
3681 | 205 |
|
3682 | 206 |
#ifdef DEBUGGING |
4092 | 207 |
extern char *__survStartPtr, *__survEndPtr; |
3682 | 208 |
# define DEBUGBUFFER(buf) \ |
3681 | 209 |
if (((char *)(buf) >= __survStartPtr) \ |
210 |
&& ((char *)(buf) < __survEndPtr)) { \ |
|
23743 | 211 |
__fatal0("read into survivor\n"); \ |
3681 | 212 |
} |
213 |
||
3682 | 214 |
#else |
215 |
# define DEBUGBUFFER(buf) /* nothing */ |
|
216 |
#endif |
|
217 |
||
216 | 218 |
/* |
219 |
* stdio library requires an fseek before reading whenever a file |
|
220 |
* is open for read/write and the last operation was a write. |
|
221 |
* (also vice-versa). |
|
222 |
* All code should use the following macro before doing reads: |
|
223 |
*/ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
224 |
#ifdef STDIO_NEEDS_FSEEK |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
225 |
# define OPT_FSEEK(f, pos, whence) fseek(f, pos, whence) |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
226 |
#else |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
227 |
# define OPT_FSEEK(f, pos, whence) /* nothing */ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
228 |
#endif |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
229 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
230 |
#ifdef __win32__ |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
231 |
# define READ(ret, f, cp, n, handleType) { \ |
23743 | 232 |
if (handleType == @symbol(socketHandle)) { \ |
233 |
(ret) = __STX_WSA_NOINT_CALL4("recv", recv, (f), (cp), (n), 0); \ |
|
234 |
} else { \ |
|
235 |
HANDLE h = _get_osfhandle(fileno(f)); \ |
|
236 |
if (handleType == @symbol(socketFilePointer)) { \ |
|
237 |
(ret) = __STX_WSA_NOINT_CALL4("recv", recv, h, (cp), (n), 0);\ |
|
238 |
} else { \ |
|
239 |
int __res; \ |
|
240 |
(ret) = __STX_API_NOINT_CALL5("ReadFile", ReadFile, h, (cp), (n), &__res, 0);\ |
|
241 |
(ret) = (ret) > 0 ? __res : (__threadErrno == __WIN32_ERR(ERROR_BROKEN_PIPE) ? 0 : -1); \ |
|
242 |
} \ |
|
243 |
} \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
244 |
} |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
245 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
246 |
# define WRITE(ret, f, cp, n, handleType) { \ |
23743 | 247 |
if (handleType == @symbol(socketHandle)) { \ |
248 |
(ret) = __STX_WSA_NOINT_CALL4("send", send, (f), (cp), (n), 0); \ |
|
249 |
} else {\ |
|
250 |
HANDLE h = _get_osfhandle(fileno(f)); \ |
|
251 |
if (handleType == @symbol(socketFilePointer)) { \ |
|
252 |
(ret) = __STX_WSA_NOINT_CALL4("send", send, h, (cp), (n), 0);\ |
|
253 |
} else {\ |
|
254 |
int __res; \ |
|
255 |
(ret) = __STX_API_NOINT_CALL5("WriteFile", WriteFile, h, (cp), (n), &__res, 0);\ |
|
256 |
(ret) = (ret) ? __res : -1; \ |
|
257 |
} \ |
|
258 |
} \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
259 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
260 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
261 |
# define FFLUSH(fp) fflush(fp) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
262 |
# undef STDIO_NEEDS_FSEEK |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
263 |
# define FILEPOINTER FILE * |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
264 |
# define FILENO(f) fileno(f) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
265 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
266 |
# define __READING__(f) \ |
1133 | 267 |
if ((__INST(didWrite) != false) \ |
268 |
&& (__INST(mode) == @symbol(readwrite))) { \ |
|
23743 | 269 |
__INST(didWrite) = false; \ |
270 |
OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */ \ |
|
216 | 271 |
} |
272 |
||
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
273 |
# define __WRITING__(f) \ |
1133 | 274 |
if ((__INST(didWrite) != true) \ |
275 |
&& (__INST(mode) == @symbol(readwrite))) { \ |
|
23743 | 276 |
__INST(didWrite) = true; \ |
277 |
OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */ \ |
|
216 | 278 |
} |
279 |
||
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
280 |
# define __UNGETC__(c, f, isBuffered) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
281 |
if (isBuffered) { \ |
23743 | 282 |
ungetc((c), (f)); \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
283 |
} else { \ |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
284 |
__INST(readAhead) = __mkSmallInteger((c)); \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
285 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
286 |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
287 |
# define __READBYTE__(ret, f, buf, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
288 |
if (isBuffered) { \ |
23743 | 289 |
for (;;) { \ |
290 |
CLEAR_ERRNO; \ |
|
291 |
(ret) = getc(f); \ |
|
292 |
if ((ret) >= 0) { \ |
|
293 |
*(buf) = (ret); \ |
|
294 |
(ret) = 1; \ |
|
295 |
} else if (ferror(f)) { \ |
|
296 |
if (__threadErrno == EINTR) { \ |
|
297 |
clearerr(f); \ |
|
298 |
continue; \ |
|
299 |
} \ |
|
25142
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
300 |
(ret) = -1; \ |
23743 | 301 |
} else { \ |
302 |
(ret) = 0; \ |
|
303 |
} \ |
|
304 |
break; \ |
|
305 |
} \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
306 |
} else { \ |
23743 | 307 |
OBJ rA = __INST(readAhead); \ |
308 |
if (rA != nil) { \ |
|
309 |
*(buf) = (char)__intVal(rA); \ |
|
310 |
__INST(readAhead) = nil; \ |
|
311 |
(ret) = 1; \ |
|
312 |
} else { \ |
|
313 |
for (;;) { \ |
|
314 |
CLEAR_ERRNO; \ |
|
315 |
READ((ret), f, buf, 1, handleType); \ |
|
316 |
if ((ret) >= 0 || __threadErrno != EINTR) \ |
|
317 |
break; \ |
|
318 |
} \ |
|
319 |
} \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
320 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
321 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
322 |
/* |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
323 |
* read_bytes into a c-buffer |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
324 |
* (which may NOT move) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
325 |
*/ |
12548 | 326 |
# define __READBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
327 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
328 |
if (isBuffered) { \ |
23743 | 329 |
int __offs = 0; \ |
330 |
while (__offs < (cnt)) { \ |
|
331 |
CLEAR_ERRNO; \ |
|
332 |
(ret) = getc(f); \ |
|
333 |
if ((ret) < 0) { \ |
|
334 |
if (ferror(f)) { \ |
|
335 |
if (__threadErrno == EINTR) { \ |
|
336 |
clearerr(f); \ |
|
337 |
continue; \ |
|
338 |
} \ |
|
339 |
} else { \ |
|
340 |
(ret) = 0; \ |
|
341 |
} \ |
|
342 |
break; \ |
|
343 |
} \ |
|
344 |
(buf)[__offs++] = (ret); \ |
|
345 |
} \ |
|
346 |
if (__offs > 0) \ |
|
347 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
348 |
} else { \ |
23743 | 349 |
int __offs = 0; \ |
350 |
\ |
|
351 |
while (__offs < (cnt)) { \ |
|
352 |
OBJ rA = __INST(readAhead); \ |
|
353 |
if (rA != nil) { \ |
|
354 |
(buf)[__offs] = __intVal(rA); \ |
|
355 |
__INST(readAhead) = nil; \ |
|
356 |
(ret) = 1; \ |
|
357 |
} else { \ |
|
358 |
CLEAR_ERRNO; \ |
|
359 |
READ((ret), f, (buf)+__offs, (cnt)-__offs, handleType); \ |
|
360 |
if ((ret) <= 0) { \ |
|
361 |
if ((ret) < 0 && __threadErrno == EINTR) { \ |
|
362 |
continue; \ |
|
363 |
} \ |
|
364 |
break; \ |
|
365 |
} \ |
|
366 |
} \ |
|
367 |
__offs += (ret); \ |
|
368 |
} \ |
|
369 |
if (__offs > 0) \ |
|
370 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
371 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
372 |
|
12548 | 373 |
# define __READAVAILBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
374 |
{ \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
375 |
int __offs = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
376 |
int oldFlags; \ |
23743 | 377 |
\ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
378 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
379 |
if (isBuffered) { \ |
23743 | 380 |
while (__offs < (cnt)) { \ |
381 |
CLEAR_ERRNO; \ |
|
382 |
(ret) = getc(f); \ |
|
383 |
if ((ret) < 0) { \ |
|
384 |
if (ferror(f)) { \ |
|
385 |
if (__threadErrno == EINTR) { \ |
|
386 |
clearerr(f); \ |
|
387 |
continue; \ |
|
388 |
} \ |
|
389 |
} else { \ |
|
390 |
(ret) = 0; \ |
|
391 |
} \ |
|
392 |
break; \ |
|
393 |
} \ |
|
394 |
(buf)[__offs++] = (ret); \ |
|
395 |
} \ |
|
396 |
if (__offs > 0) \ |
|
397 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
398 |
} else { \ |
23743 | 399 |
while (__offs < (cnt)) { \ |
400 |
OBJ rA = __INST(readAhead); \ |
|
401 |
if (rA != nil) { \ |
|
402 |
(buf)[__offs] = __intVal(rA); \ |
|
403 |
__INST(readAhead) = nil; \ |
|
404 |
(ret) = 1; \ |
|
405 |
__offs ++; \ |
|
406 |
continue; \ |
|
407 |
} \ |
|
408 |
CLEAR_ERRNO; \ |
|
409 |
{ \ |
|
410 |
int res = -1, ok = 0; \ |
|
411 |
SOCKET sock = 0; \ |
|
412 |
if ((handleType == @symbol(socketFilePointer) && ((ok = ioctlsocket(sock = (SOCKET)_get_osfhandle(fileno(f)),FIONREAD,&res) == 0), 1)) \ |
|
413 |
|| (handleType == @symbol(socketHandle) && ((ok = ioctlsocket(sock = (SOCKET)(f), FIONREAD, &res) == 0), 1)) \ |
|
414 |
|| (handleType == @symbol(pipeFilePointer) && ((ok = PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0, 0,0,&res,0)), 1))) { \ |
|
415 |
if (!ok) { \ |
|
416 |
__threadErrno = sock ? WSAGetLastError() : __WIN32_ERR(GetLastError()); \ |
|
417 |
(ret) = __threadErrno == __WIN32_ERR(ERROR_BROKEN_PIPE) ? 0 : -1; \ |
|
418 |
break; \ |
|
419 |
} \ |
|
420 |
if (res > 0) { \ |
|
421 |
if (res > ((cnt)-__offs)) \ |
|
422 |
res = (cnt)-__offs; \ |
|
423 |
READ((ret), f, (buf)+__offs, res, handleType); \ |
|
424 |
} else { \ |
|
425 |
if (sock && send(sock, NULL, 0, 0) == SOCKET_ERROR) { \ |
|
426 |
(ret) = -1; __threadErrno = WSAGetLastError(); \ |
|
427 |
} else { \ |
|
428 |
(ret) = 0; \ |
|
429 |
} \ |
|
430 |
break; \ |
|
431 |
} \ |
|
432 |
} else { \ |
|
433 |
READ((ret), f, (buf)+__offs, (cnt)-__offs, handleType); \ |
|
434 |
} \ |
|
435 |
} \ |
|
436 |
if ((ret) <= 0) { \ |
|
437 |
if ((ret) < 0 && __threadErrno == EINTR)\ |
|
438 |
continue; \ |
|
439 |
break; \ |
|
440 |
} \ |
|
441 |
__offs += (ret); \ |
|
442 |
} \ |
|
443 |
if (__offs > 0) \ |
|
444 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
445 |
} \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
446 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
447 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
448 |
# define IO_BUFFER_SIZE (8*1024) |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
449 |
|
12548 | 450 |
# define __READBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
451 |
{ \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
452 |
int __ooffs = obj_offs; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
453 |
int __offs = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
454 |
char *buf = (char *)(obj); \ |
23743 | 455 |
\ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
456 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
457 |
if (isBuffered) { \ |
23743 | 458 |
while (__offs < (cnt)) { \ |
459 |
CLEAR_ERRNO; \ |
|
460 |
(ret) = getc(f); \ |
|
461 |
if ((ret) < 0) { \ |
|
462 |
if (ferror(f)) { \ |
|
463 |
if (__threadErrno == EINTR) { \ |
|
464 |
clearerr(f); \ |
|
465 |
/* refetch */ \ |
|
466 |
buf = (char *)(obj); \ |
|
467 |
continue; \ |
|
468 |
} \ |
|
469 |
} else { \ |
|
470 |
(ret) = 0; \ |
|
471 |
} \ |
|
472 |
break; \ |
|
473 |
} \ |
|
474 |
(buf)[__ooffs+__offs] = (ret); \ |
|
475 |
__offs++; \ |
|
476 |
} \ |
|
477 |
if (__offs > 0) \ |
|
478 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
479 |
} else { \ |
23743 | 480 |
while (__offs < (cnt)) { \ |
481 |
char __buf[IO_BUFFER_SIZE]; \ |
|
482 |
OBJ rA = __INST(readAhead); \ |
|
483 |
if (rA != nil) { \ |
|
484 |
(buf)[__ooffs+__offs] = __intVal(rA); \ |
|
485 |
__INST(readAhead) = nil; \ |
|
486 |
(ret) = 1; \ |
|
487 |
} else { \ |
|
488 |
int l; \ |
|
489 |
CLEAR_ERRNO; \ |
|
490 |
l = (cnt)-__offs; \ |
|
491 |
if ( l > IO_BUFFER_SIZE) \ |
|
492 |
l = IO_BUFFER_SIZE; \ |
|
493 |
READ((ret),f, __buf, l, handleType); \ |
|
494 |
if ((ret) <= 0) { \ |
|
495 |
if ((ret) < 0 && __threadErrno == EINTR) { \ |
|
496 |
continue; \ |
|
497 |
} \ |
|
498 |
break; \ |
|
499 |
} \ |
|
500 |
} \ |
|
501 |
if ((ret) > 0 ) { \ |
|
502 |
/* refetch */ \ |
|
503 |
buf = (char *)(obj); \ |
|
504 |
memcpy((buf)+__ooffs+__offs,__buf,(ret)); \ |
|
505 |
__offs += (ret); \ |
|
506 |
} else { \ |
|
507 |
(ret) = 0; \ |
|
508 |
} \ |
|
509 |
} \ |
|
510 |
if (__offs > 0) \ |
|
511 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
512 |
} \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
513 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
514 |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
515 |
# define __READAVAILBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
516 |
{ \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
517 |
int __ooffs = obj_offs; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
518 |
int __offs = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
519 |
char *buf = (char *)(obj); \ |
23743 | 520 |
\ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
521 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
522 |
if (isBuffered) { \ |
23743 | 523 |
while (__offs < (cnt)) { \ |
524 |
CLEAR_ERRNO; \ |
|
525 |
(ret) = getc(f); \ |
|
526 |
if ((ret) < 0) { \ |
|
527 |
if (ferror(f)) { \ |
|
528 |
if (__threadErrno == EINTR) { \ |
|
529 |
clearerr(f); \ |
|
530 |
/* refetch */ \ |
|
531 |
buf = (char *)(obj); \ |
|
532 |
continue; \ |
|
533 |
} \ |
|
534 |
} else { \ |
|
535 |
(ret) = 0; \ |
|
536 |
} \ |
|
537 |
break; \ |
|
538 |
} \ |
|
539 |
(buf)[__ooffs+__offs] = (ret); \ |
|
540 |
__offs++; \ |
|
541 |
} \ |
|
542 |
if (__offs > 0) \ |
|
543 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
544 |
} else { \ |
23743 | 545 |
while (__offs < (cnt)) { \ |
546 |
char __buf[IO_BUFFER_SIZE]; \ |
|
547 |
OBJ rA = __INST(readAhead); \ |
|
548 |
if (rA != nil) { \ |
|
549 |
(buf)[__ooffs+__offs] = __intVal(rA);\ |
|
550 |
__INST(readAhead) = nil; \ |
|
551 |
(ret) = 1; \ |
|
552 |
__offs++; \ |
|
553 |
continue; \ |
|
554 |
} \ |
|
555 |
{ \ |
|
556 |
int res = -1, ok = 0; \ |
|
557 |
SOCKET sock = 0; \ |
|
558 |
int l = (cnt)-__offs; \ |
|
559 |
CLEAR_ERRNO; \ |
|
560 |
if (l > IO_BUFFER_SIZE) l = IO_BUFFER_SIZE; \ |
|
561 |
if ((handleType == @symbol(socketFilePointer) && ((ok = ioctlsocket(sock = (SOCKET)_get_osfhandle(fileno(f)),FIONREAD,&res) == 0), 1)) \ |
|
562 |
|| (handleType == @symbol(socketHandle) && ((ok = ioctlsocket(sock = (SOCKET)(f), FIONREAD, &res) == 0), 1)) \ |
|
563 |
|| (handleType == @symbol(pipeFilePointer) && ((ok = PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0, 0,0,&res,0)), 1))) { \ |
|
564 |
if (!ok) { \ |
|
565 |
__threadErrno = sock ? WSAGetLastError() : __WIN32_ERR(GetLastError()); \ |
|
566 |
(ret) = __threadErrno == __WIN32_ERR(ERROR_BROKEN_PIPE) ? 0 : -1; \ |
|
567 |
break; \ |
|
568 |
} \ |
|
569 |
if (res > 0) { \ |
|
570 |
if (res > l) res = l; \ |
|
571 |
READ((ret), f, __buf, res, handleType); \ |
|
572 |
} else { \ |
|
573 |
if (sock && send(sock, NULL, 0, 0) == SOCKET_ERROR) { \ |
|
574 |
(ret) = -1; __threadErrno = WSAGetLastError(); \ |
|
575 |
} else { \ |
|
576 |
(ret) = 0; \ |
|
577 |
} \ |
|
578 |
break; \ |
|
579 |
} \ |
|
580 |
} else { \ |
|
581 |
READ((ret), f, __buf, l, handleType); \ |
|
582 |
} \ |
|
583 |
if ((ret) <= 0) { \ |
|
584 |
if ((ret) < 0 && __threadErrno == EINTR) \ |
|
585 |
continue; \ |
|
586 |
break; \ |
|
587 |
} \ |
|
588 |
} \ |
|
589 |
if ((ret) > 0) { \ |
|
590 |
buf = (char *)(obj); \ |
|
591 |
memcpy((buf)+__ooffs+__offs, __buf, (ret)); \ |
|
592 |
__offs += (ret); \ |
|
593 |
} else { \ |
|
594 |
(ret) = 0; \ |
|
595 |
} \ |
|
596 |
} \ |
|
597 |
if (__offs > 0) \ |
|
598 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
599 |
} \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
600 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
601 |
|
12548 | 602 |
# define __WRITEBYTE__(ret, f, buf, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
603 |
if (isBuffered) { \ |
23743 | 604 |
for (;;) { \ |
605 |
CLEAR_ERRNO; \ |
|
606 |
ret = putc(*(buf), f); \ |
|
607 |
if ((ret) >= 0) { \ |
|
608 |
(ret) = 1; \ |
|
609 |
} else if (ferror(f)) { \ |
|
610 |
if (__threadErrno == EINTR) { \ |
|
611 |
clearerr(f); \ |
|
612 |
continue; \ |
|
613 |
} \ |
|
614 |
} else \ |
|
615 |
(ret) = 0; \ |
|
616 |
break; \ |
|
617 |
} \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
618 |
} else { \ |
23743 | 619 |
for (;;) { \ |
620 |
CLEAR_ERRNO; \ |
|
621 |
WRITE(ret,f, buf, 1, handleType); \ |
|
622 |
if ((ret) >= 0 || __threadErrno != EINTR) \ |
|
623 |
break; \ |
|
624 |
} \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
625 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
626 |
|
12548 | 627 |
# define __WRITEBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
628 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
629 |
if (isBuffered) { \ |
23743 | 630 |
int __offs = 0; \ |
631 |
while (__offs < (cnt)) { \ |
|
632 |
CLEAR_ERRNO; \ |
|
633 |
(ret) = fwrite((buf)+__offs, 1, (cnt)-__offs, f);\ |
|
634 |
if ((ret) <= 0) { \ |
|
635 |
if (ferror(f)) { \ |
|
636 |
if (__threadErrno == EINTR) { \ |
|
637 |
clearerr(f); \ |
|
638 |
continue; \ |
|
639 |
} \ |
|
25142
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
640 |
(ret) = -1; \ |
23743 | 641 |
break; \ |
642 |
} else { \ |
|
643 |
(ret) = 0; \ |
|
644 |
} \ |
|
645 |
} \ |
|
646 |
__offs += (ret); \ |
|
647 |
} \ |
|
648 |
if (__offs > 0) \ |
|
649 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
650 |
} else { \ |
23743 | 651 |
int __offs = 0; \ |
652 |
while (__offs < (cnt)) { \ |
|
653 |
CLEAR_ERRNO; \ |
|
654 |
WRITE((ret),f, (buf)+__offs, (cnt)-__offs, handleType); \ |
|
655 |
if ((ret) <= 0) { \ |
|
656 |
if ((ret) < 0 && __threadErrno == EINTR) { \ |
|
657 |
continue; \ |
|
658 |
} \ |
|
659 |
break; \ |
|
660 |
} \ |
|
661 |
__offs += (ret); \ |
|
662 |
} \ |
|
663 |
if (__offs > 0) \ |
|
664 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
665 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
666 |
|
12548 | 667 |
# define __WRITEBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
668 |
{ \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
669 |
int __ooffs = obj_offs; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
670 |
int __offs = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
671 |
char *buf = (char *)(obj); \ |
23743 | 672 |
\ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
673 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
674 |
if (isBuffered) { \ |
23743 | 675 |
while (__offs < (cnt)) { \ |
676 |
CLEAR_ERRNO; \ |
|
677 |
ret = fwrite((buf)+__ooffs+__offs, 1, (cnt)-__offs, f); \ |
|
678 |
if ((ret) <= 0) { \ |
|
679 |
if (ferror(f)) { \ |
|
680 |
if (__threadErrno == EINTR) { \ |
|
681 |
/* refetch */ \ |
|
682 |
buf = (char *)(obj); \ |
|
683 |
clearerr(f); \ |
|
684 |
continue; \ |
|
685 |
} \ |
|
25142
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
686 |
(ret) = -1; \ |
23743 | 687 |
break; \ |
688 |
} else { \ |
|
689 |
(ret) = 0; \ |
|
690 |
} \ |
|
691 |
} \ |
|
692 |
__offs += (ret); \ |
|
693 |
} \ |
|
694 |
if (__offs > 0) \ |
|
695 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
696 |
} else { \ |
23743 | 697 |
while (__offs < (cnt)) { \ |
698 |
char __buf[IO_BUFFER_SIZE]; \ |
|
699 |
int l; \ |
|
700 |
CLEAR_ERRNO; \ |
|
701 |
l = (cnt)-__offs; \ |
|
702 |
if ( l > IO_BUFFER_SIZE) \ |
|
703 |
l = IO_BUFFER_SIZE; \ |
|
704 |
/* refetch */ \ |
|
705 |
buf = (char *)(obj); \ |
|
706 |
memcpy(__buf,(buf)+__ooffs+__offs,l); \ |
|
707 |
WRITE(ret,f, __buf, l, handleType); \ |
|
708 |
if ((ret) <= 0) { \ |
|
709 |
if ((ret) < 0 && __threadErrno == EINTR) { \ |
|
710 |
continue; \ |
|
711 |
} \ |
|
712 |
break; \ |
|
713 |
} \ |
|
714 |
__offs += (ret); \ |
|
715 |
} \ |
|
716 |
if (__offs > 0) \ |
|
717 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
718 |
} \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
719 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
720 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
721 |
#else /* ! __win32__ */ |
16296 | 722 |
/* ======================== UNIX / LINUX ====================================================== */ |
16373
9b9827530bf4
Adapt previous change for linux
Stefan Vogel <sv@exept.de>
parents:
16368
diff
changeset
|
723 |
typedef int SOCKET; |
9b9827530bf4
Adapt previous change for linux
Stefan Vogel <sv@exept.de>
parents:
16368
diff
changeset
|
724 |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
725 |
# define __READING__(f) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
726 |
if ((__INST(didWrite) != false) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
727 |
&& (__INST(mode) == @symbol(readwrite))) { \ |
23743 | 728 |
__INST(didWrite) = false; \ |
729 |
OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */ \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
730 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
731 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
732 |
# define __WRITING__(f) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
733 |
if ((__INST(didWrite) != true) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
734 |
&& (__INST(mode) == @symbol(readwrite))) { \ |
23743 | 735 |
__INST(didWrite) = true; \ |
736 |
OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */ \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
737 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
738 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
739 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
740 |
# ifdef NO_STDIO |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
741 |
# define __UNGETC__(c, f, isBuffered) \ |
8913 | 742 |
__INST(readAhead) = __mkSmallInteger((c)); |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
743 |
# else /* use STDIO */ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
744 |
# define __UNGETC__(c, f, isBuffered) \ |
2264 | 745 |
if (isBuffered) { \ |
23743 | 746 |
ungetc((c), (f)); \ |
2264 | 747 |
} else { \ |
23743 | 748 |
__INST(readAhead) = __mkSmallInteger((c)); \ |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
749 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
750 |
# endif /* use STDIO */ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
751 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
752 |
# ifdef NO_STDIO |
12548 | 753 |
# define __READBYTE__(ret, f, buf, isBuffered, handleType) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
754 |
{ \ |
23743 | 755 |
OBJ rA = __INST(readAhead); \ |
756 |
if (rA != nil) { \ |
|
757 |
*(buf) = __intVal(rA); \ |
|
758 |
DEBUGBUFFER(buf); \ |
|
759 |
__INST(readAhead) = nil; \ |
|
760 |
(ret) = 1; \ |
|
761 |
} else { \ |
|
762 |
for (;;) { \ |
|
763 |
CLEAR_ERRNO; \ |
|
764 |
(ret) = READ(f, buf, 1, handleType); \ |
|
765 |
DEBUGBUFFER(buf); \ |
|
766 |
if ((ret) >= 0) break; \ |
|
767 |
if (errno != EINTR) { \ |
|
768 |
break; \ |
|
769 |
} \ |
|
770 |
__HANDLE_INTERRUPTS__; \ |
|
771 |
} \ |
|
772 |
} \ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
773 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
774 |
# else /* use STDIO */ |
12548 | 775 |
# define __READBYTE__(ret, f, buf, isBuffered, handleType) \ |
2264 | 776 |
if (isBuffered) { \ |
23743 | 777 |
for (;;) { \ |
778 |
CLEAR_ERRNO; \ |
|
779 |
(ret) = getc(f); \ |
|
780 |
if ((ret) >= 0) { \ |
|
781 |
DEBUGBUFFER(buf); \ |
|
782 |
*(buf) = (ret); \ |
|
783 |
(ret) = 1; \ |
|
784 |
} else if (ferror(f)) { \ |
|
785 |
if (errno == EINTR) { \ |
|
786 |
__HANDLE_INTERRUPTS__; \ |
|
787 |
clearerr(f); \ |
|
788 |
continue; \ |
|
789 |
} \ |
|
790 |
} else \ |
|
791 |
(ret) = 0; \ |
|
792 |
break; \ |
|
793 |
} \ |
|
2264 | 794 |
} else { \ |
23743 | 795 |
OBJ rA = __INST(readAhead); \ |
796 |
if (rA != nil) { \ |
|
797 |
*(buf) = __intVal(rA); \ |
|
798 |
DEBUGBUFFER(buf); \ |
|
799 |
__INST(readAhead) = nil; \ |
|
800 |
(ret) = 1; \ |
|
801 |
} else { \ |
|
802 |
for (;;) { \ |
|
803 |
CLEAR_ERRNO; \ |
|
804 |
(ret) = read(fileno(f), buf, 1); \ |
|
805 |
DEBUGBUFFER(buf); \ |
|
806 |
if ((ret) >= 0) break; \ |
|
807 |
if (errno != EINTR) { \ |
|
808 |
break; \ |
|
809 |
} \ |
|
810 |
__HANDLE_INTERRUPTS__; \ |
|
811 |
} \ |
|
812 |
} \ |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
813 |
} |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
814 |
# endif /* use STDIO */ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
815 |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
816 |
/* |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
817 |
* read_bytes into a c-buffer |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
818 |
* (which may NOT move) |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
819 |
*/ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
820 |
# ifdef NO_STDIO |
12548 | 821 |
# define __READBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
822 |
{ \ |
23743 | 823 |
int __offs = 0, __cnt; \ |
824 |
\ |
|
825 |
while (__offs < (cnt)) { \ |
|
826 |
OBJ rA = __INST(readAhead); \ |
|
827 |
if (rA != nil) { \ |
|
828 |
(buf)[__offs] = __intVal(rA); \ |
|
829 |
DEBUGBUFFER(buf); \ |
|
830 |
__INST(readAhead) = nil; \ |
|
831 |
__offs++; \ |
|
832 |
} else { \ |
|
833 |
CLEAR_ERRNO; \ |
|
834 |
__cnt = READ(f, (buf)+__offs, (cnt)-__offs, handleType); \ |
|
835 |
DEBUGBUFFER(buf); \ |
|
836 |
if (__cnt <= 0) { \ |
|
837 |
if (__cnt < 0 && errno == EINTR) { \ |
|
838 |
__HANDLE_INTERRUPTS__; \ |
|
839 |
continue; \ |
|
840 |
} \ |
|
841 |
break; \ |
|
842 |
} \ |
|
843 |
__offs += __cnt; \ |
|
844 |
} \ |
|
845 |
} \ |
|
846 |
if (__offs > 0) \ |
|
847 |
(ret) = __offs; \ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
848 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
849 |
# else /* use STDIO */ |
12548 | 850 |
# define __READBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
851 |
(ret) = 0; \ |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
852 |
if (isBuffered) { \ |
23743 | 853 |
int __offs = 0; \ |
854 |
while (__offs < (cnt)) { \ |
|
855 |
CLEAR_ERRNO; \ |
|
856 |
(ret) = getc(f); \ |
|
857 |
if ((ret) < 0) { \ |
|
858 |
if (ferror(f)) { \ |
|
859 |
if (errno == EINTR) { \ |
|
860 |
__HANDLE_INTERRUPTS__; \ |
|
861 |
clearerr(f); \ |
|
862 |
continue; \ |
|
863 |
} \ |
|
864 |
} else { \ |
|
865 |
(ret) = 0; \ |
|
866 |
} \ |
|
867 |
break; \ |
|
868 |
} \ |
|
869 |
DEBUGBUFFER(buf); \ |
|
870 |
(buf)[__offs++] = (ret); \ |
|
871 |
} \ |
|
872 |
if (__offs > 0) \ |
|
873 |
(ret) = __offs; \ |
|
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
874 |
} else { \ |
23743 | 875 |
int __offs = 0, __cnt; \ |
876 |
int fd = fileno(f); \ |
|
877 |
\ |
|
878 |
while (__offs < (cnt)) { \ |
|
879 |
OBJ rA = __INST(readAhead); \ |
|
880 |
if (rA != nil) { \ |
|
881 |
DEBUGBUFFER(buf); \ |
|
882 |
(buf)[__offs] = __intVal(rA); \ |
|
883 |
__INST(readAhead) = nil; \ |
|
884 |
__offs++; \ |
|
885 |
} else { \ |
|
886 |
CLEAR_ERRNO; \ |
|
887 |
__cnt = read(fd, (buf)+__offs, (cnt)-__offs); \ |
|
888 |
DEBUGBUFFER(buf); \ |
|
889 |
if (__cnt <= 0) { \ |
|
890 |
if (__cnt < 0 && errno == EINTR) { \ |
|
891 |
__HANDLE_INTERRUPTS__; \ |
|
892 |
continue; \ |
|
893 |
} \ |
|
894 |
break; \ |
|
895 |
} \ |
|
896 |
__offs += __cnt; \ |
|
897 |
} \ |
|
898 |
} \ |
|
899 |
if (__offs > 0) \ |
|
900 |
(ret) = __offs; \ |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
901 |
} |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
902 |
|
6563
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
903 |
|
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
904 |
/* |
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
905 |
* FNDELAY and O_NDELAY is deprecated, O_NONBLOCK is used in POSIX, XPG, etc... |
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
906 |
*/ |
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
907 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
908 |
# if defined(F_GETFL) && defined(F_SETFL) && (defined(O_NONBLOCK) || defined(O_NDELAY) || defined(FNDELAY)) |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
909 |
# define SETFLAGS(fd, flags) \ |
23743 | 910 |
fcntl(fd, F_SETFL, flags) |
6563
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
911 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
912 |
# if defined(O_NONBLOCK) |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
913 |
# define __STX_NONBLOCK_FLAG O_NONBLOCK |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
914 |
# else |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
915 |
# if defined(O_NDELAY) |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
916 |
# define __STX_NONBLOCK_FLAG O_NDELAY |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
917 |
# else |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
918 |
# define __STX_NONBLOCK_FLAG FNDELAY |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
919 |
# endif |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
920 |
# endif |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
921 |
|
15342 | 922 |
# define SETNONBLOCKING(fd, oldFlags) \ |
23743 | 923 |
{ \ |
924 |
int flags = fcntl(fd, F_GETFL, 0); \ |
|
925 |
if (flags >= 0) { \ |
|
926 |
fcntl(fd, F_SETFL, flags | __STX_NONBLOCK_FLAG); \ |
|
927 |
} \ |
|
928 |
oldFlags = flags; \ |
|
929 |
} |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
930 |
# else |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
931 |
# define SETFLAGS(fd, flags) /* nothing */ |
15342 | 932 |
# define SETNONBLOCKING(fd, oldFlags) /* nothing */ |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
933 |
# endif |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
934 |
|
12548 | 935 |
# define __READAVAILBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
936 |
{ \ |
15342 | 937 |
int __offs = 0, __cnt; \ |
3681 | 938 |
int oldFlags; \ |
23743 | 939 |
\ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
940 |
(ret) = 0; \ |
15342 | 941 |
SETNONBLOCKING(fileno(f), oldFlags); \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
942 |
if (isBuffered) { \ |
23743 | 943 |
while (__offs < (cnt)) { \ |
944 |
CLEAR_ERRNO; \ |
|
945 |
(ret) = getc(f); \ |
|
946 |
if ((ret) < 0) { \ |
|
947 |
if (ferror(f)) { \ |
|
948 |
if (errno == EINTR) { \ |
|
949 |
(ret) = 0; \ |
|
950 |
clearerr(f); \ |
|
951 |
break; \ |
|
952 |
} \ |
|
953 |
} else { \ |
|
954 |
(ret) = 0; \ |
|
955 |
} \ |
|
956 |
break; \ |
|
957 |
} \ |
|
958 |
(buf)[__offs++] = (ret); \ |
|
959 |
DEBUGBUFFER(buf); \ |
|
960 |
} \ |
|
961 |
if (__offs > 0) \ |
|
962 |
(ret) = __offs; \ |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
963 |
} else { \ |
23743 | 964 |
int fd = fileno(f); \ |
965 |
\ |
|
966 |
while (__offs < (cnt)) { \ |
|
967 |
OBJ rA = __INST(readAhead); \ |
|
968 |
if (rA != nil) { \ |
|
969 |
(buf)[__offs] = __intVal(rA); \ |
|
970 |
DEBUGBUFFER(buf); \ |
|
971 |
__INST(readAhead) = nil; \ |
|
972 |
__offs++; \ |
|
973 |
continue; \ |
|
974 |
} \ |
|
975 |
CLEAR_ERRNO; \ |
|
976 |
__cnt = read(fd, (buf)+__offs, (cnt)-__offs); \ |
|
977 |
DEBUGBUFFER(buf); \ |
|
978 |
if (__cnt > 0) { \ |
|
979 |
__offs += __cnt; \ |
|
980 |
} \ |
|
981 |
break; \ |
|
982 |
} \ |
|
983 |
if (__offs > 0) \ |
|
984 |
(ret) = __offs; \ |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
985 |
} \ |
3681 | 986 |
SETFLAGS(fileno(f), oldFlags); \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
987 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
988 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
989 |
# endif /* use STDIO */ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
990 |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
991 |
/* |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
992 |
* read_bytes into an object |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
993 |
* (which may be moved by GC) |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
994 |
*/ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
995 |
# ifdef NO_STDIO |
12548 | 996 |
# define __READBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered, handleType) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
997 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
998 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
999 |
int __offs = 0; \ |
7540
7cd542f29024
Fix reading when readAheadBuffer is filled and following read fails
Stefan Vogel <sv@exept.de>
parents:
7503
diff
changeset
|
1000 |
int __cnt; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1001 |
char *buf = (char *)(obj); \ |
23743 | 1002 |
\ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1003 |
(ret) = 0; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1004 |
{ \ |
23743 | 1005 |
while (__offs < (cnt)) { \ |
1006 |
OBJ rA = __INST(readAhead); \ |
|
1007 |
if (rA != nil) { \ |
|
1008 |
(buf)[__ooffs+__offs] = __intVal(rA); \ |
|
1009 |
DEBUGBUFFER(buf); \ |
|
1010 |
__INST(readAhead) = nil; \ |
|
1011 |
__offs++; \ |
|
1012 |
} else { \ |
|
1013 |
CLEAR_ERRNO; \ |
|
1014 |
__cnt = READ(f, (buf)+__ooffs+__offs, (cnt)-__offs, handleType); \ |
|
1015 |
DEBUGBUFFER(buf); \ |
|
1016 |
if (__cnt <= 0) { \ |
|
1017 |
if (__cnt < 0 && errno == EINTR) { \ |
|
1018 |
__HANDLE_INTERRUPTS__; \ |
|
1019 |
/* refetch */ \ |
|
1020 |
buf = (char *)(obj); \ |
|
1021 |
continue; \ |
|
1022 |
} \ |
|
1023 |
break; \ |
|
1024 |
} \ |
|
1025 |
__offs += __cnt; \ |
|
1026 |
} \ |
|
1027 |
} \ |
|
1028 |
if (__offs > 0) \ |
|
1029 |
(ret) = __offs; \ |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1030 |
} \ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1031 |
} |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
1032 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1033 |
# else /* use STDIO */ |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
1034 |
|
12548 | 1035 |
# define __READBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered, handleType) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1036 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1037 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1038 |
int __offs = 0; \ |
7540
7cd542f29024
Fix reading when readAheadBuffer is filled and following read fails
Stefan Vogel <sv@exept.de>
parents:
7503
diff
changeset
|
1039 |
int __cnt; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1040 |
char *buf = (char *)(obj); \ |
23743 | 1041 |
\ |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1042 |
(ret) = 0; \ |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1043 |
if (isBuffered) { \ |
23743 | 1044 |
while (__offs < (cnt)) { \ |
1045 |
CLEAR_ERRNO; \ |
|
1046 |
(ret) = getc(f); \ |
|
1047 |
if ((ret) < 0) { \ |
|
1048 |
if (ferror(f)) { \ |
|
1049 |
if (errno == EINTR) { \ |
|
1050 |
__HANDLE_INTERRUPTS__; \ |
|
1051 |
clearerr(f); \ |
|
1052 |
/* refetch */ \ |
|
1053 |
buf = (char *)(obj); \ |
|
1054 |
DEBUGBUFFER(buf); \ |
|
1055 |
continue; \ |
|
1056 |
} \ |
|
1057 |
} else { \ |
|
1058 |
(ret) = 0; \ |
|
1059 |
} \ |
|
1060 |
break; \ |
|
1061 |
} \ |
|
1062 |
(buf)[__ooffs+__offs] = (ret); \ |
|
1063 |
DEBUGBUFFER(buf); \ |
|
1064 |
__offs++; \ |
|
1065 |
} \ |
|
1066 |
if (__offs > 0) \ |
|
1067 |
(ret) = __offs; \ |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1068 |
} else { \ |
23743 | 1069 |
int fd = fileno(f); \ |
1070 |
\ |
|
1071 |
while (__offs < (cnt)) { \ |
|
1072 |
OBJ rA = __INST(readAhead); \ |
|
1073 |
if (rA != nil) { \ |
|
1074 |
(buf)[__ooffs+__offs] = __intVal(rA); \ |
|
1075 |
DEBUGBUFFER(buf); \ |
|
1076 |
__INST(readAhead) = nil; \ |
|
1077 |
__offs++; \ |
|
1078 |
} else { \ |
|
1079 |
CLEAR_ERRNO; \ |
|
1080 |
__cnt = read(fd, (buf)+__ooffs+__offs, (cnt)-__offs); \ |
|
1081 |
DEBUGBUFFER(buf); \ |
|
1082 |
if (__cnt <= 0) { \ |
|
1083 |
if (__cnt < 0 && errno == EINTR) { \ |
|
1084 |
__HANDLE_INTERRUPTS__; \ |
|
1085 |
/* refetch */ \ |
|
1086 |
buf = (char *)(obj); \ |
|
1087 |
continue; \ |
|
1088 |
} \ |
|
1089 |
break; \ |
|
1090 |
} \ |
|
1091 |
__offs += __cnt; \ |
|
1092 |
} \ |
|
1093 |
} \ |
|
1094 |
if (__offs > 0) \ |
|
1095 |
(ret) = __offs; \ |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1096 |
} \ |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1097 |
} |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1098 |
|
12548 | 1099 |
# define __READAVAILBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered, handleType) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1100 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1101 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1102 |
int __offs = 0; \ |
7540
7cd542f29024
Fix reading when readAheadBuffer is filled and following read fails
Stefan Vogel <sv@exept.de>
parents:
7503
diff
changeset
|
1103 |
int __cnt; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1104 |
char *buf = (char *)(obj); \ |
15342 | 1105 |
int oldFlags; \ |
23743 | 1106 |
\ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1107 |
(ret) = 0; \ |
15342 | 1108 |
SETNONBLOCKING(fileno(f), oldFlags); \ |
23743 | 1109 |
\ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1110 |
if (isBuffered) { \ |
23743 | 1111 |
while (__offs < (cnt)) { \ |
1112 |
CLEAR_ERRNO; \ |
|
1113 |
(ret) = getc(f); \ |
|
1114 |
if ((ret) < 0) { \ |
|
1115 |
if (ferror(f)) { \ |
|
1116 |
if (errno == EINTR) { \ |
|
1117 |
clearerr(f); \ |
|
1118 |
/* refetch */ \ |
|
1119 |
buf = (char *)(obj); \ |
|
1120 |
(ret) = 0; \ |
|
1121 |
break; \ |
|
1122 |
} \ |
|
1123 |
} else { \ |
|
1124 |
(ret) = 0; \ |
|
1125 |
} \ |
|
1126 |
break; \ |
|
1127 |
} \ |
|
1128 |
(buf)[__ooffs+__offs] = (ret); \ |
|
1129 |
DEBUGBUFFER(buf); \ |
|
1130 |
__offs++; \ |
|
1131 |
} \ |
|
1132 |
if (__offs > 0) \ |
|
1133 |
(ret) = __offs; \ |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1134 |
} else { \ |
23743 | 1135 |
int fd = fileno(f); \ |
1136 |
\ |
|
1137 |
while (__offs < (cnt)) { \ |
|
1138 |
OBJ rA = __INST(readAhead); \ |
|
1139 |
if (rA != nil) { \ |
|
1140 |
(buf)[__ooffs+__offs] = __intVal(rA); \ |
|
1141 |
DEBUGBUFFER(buf); \ |
|
1142 |
__INST(readAhead) = nil; \ |
|
1143 |
__offs++; \ |
|
1144 |
continue; \ |
|
1145 |
} \ |
|
1146 |
CLEAR_ERRNO; \ |
|
1147 |
__cnt = read(fd, (buf)+__ooffs+__offs, (cnt)-__offs); \ |
|
1148 |
DEBUGBUFFER(buf); \ |
|
1149 |
if (__cnt > 0) { \ |
|
1150 |
__offs += __cnt; \ |
|
1151 |
} \ |
|
1152 |
break; \ |
|
1153 |
} \ |
|
1154 |
if (__offs > 0) \ |
|
1155 |
(ret) = __offs; \ |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1156 |
} \ |
15342 | 1157 |
SETFLAGS(fileno(f), oldFlags); \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1158 |
} |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1159 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1160 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1161 |
# endif /* use STDIO */ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1162 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1163 |
# ifdef NO_STDIO |
12548 | 1164 |
# define __WRITEBYTE__(ret, f, buf, isBuffered, handleType) \ |
23743 | 1165 |
for (;;) { \ |
1166 |
CLEAR_ERRNO; \ |
|
1167 |
(ret) = WRITE(f, buf, 1, handleType); \ |
|
1168 |
if ((ret) >= 0) break; \ |
|
1169 |
if (errno != EINTR) { \ |
|
1170 |
break; \ |
|
1171 |
} \ |
|
1172 |
__HANDLE_INTERRUPTS__; \ |
|
1173 |
} |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1174 |
# else /* use STDIO */ |
12548 | 1175 |
# define __WRITEBYTE__(ret, f, buf, isBuffered, handleType) \ |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
1176 |
if (isBuffered) { \ |
23743 | 1177 |
for (;;) { \ |
1178 |
CLEAR_ERRNO; \ |
|
1179 |
ret = putc(*(buf), f); \ |
|
1180 |
if ((ret) >= 0) { \ |
|
1181 |
(ret) = 1; \ |
|
1182 |
} else if (ferror(f)) { \ |
|
1183 |
/* SOLARIS/SPARC (2.6) generates spurious errors with errno = 0 */ \ |
|
1184 |
if (errno == EINTR || errno == 0) { \ |
|
1185 |
__HANDLE_INTERRUPTS__; \ |
|
1186 |
clearerr(f); \ |
|
1187 |
continue; \ |
|
1188 |
} \ |
|
1189 |
} else \ |
|
1190 |
(ret) = 0; \ |
|
1191 |
break; \ |
|
1192 |
} \ |
|
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
1193 |
} else { \ |
23743 | 1194 |
for (;;) { \ |
1195 |
CLEAR_ERRNO; \ |
|
1196 |
(ret) = write(fileno(f), buf, 1); \ |
|
1197 |
if ((ret) >= 0) break; \ |
|
1198 |
if (errno != EINTR) { \ |
|
1199 |
break; \ |
|
1200 |
} \ |
|
1201 |
__HANDLE_INTERRUPTS__; \ |
|
1202 |
} \ |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1203 |
} |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1204 |
# endif /* use STDIO */ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1205 |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1206 |
/* |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1207 |
* write_bytes from a c-buffer |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1208 |
* (which may NOT move) |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1209 |
*/ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1210 |
# ifdef NO_STDIO |
12548 | 1211 |
# define __WRITEBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
2961 | 1212 |
(ret) = 0; \ |
1213 |
{ \ |
|
23743 | 1214 |
int __offs = 0; \ |
1215 |
while (__offs < (cnt)) { \ |
|
1216 |
CLEAR_ERRNO; \ |
|
1217 |
ret = WRITE(f, (buf)+__offs, (cnt)-__offs, handleType); \ |
|
1218 |
if (ret <= 0) { \ |
|
1219 |
if (ret < 0 && errno == EINTR) { \ |
|
1220 |
__HANDLE_INTERRUPTS__; \ |
|
1221 |
continue; \ |
|
1222 |
} \ |
|
1223 |
break; \ |
|
1224 |
} \ |
|
1225 |
__offs += (ret); \ |
|
1226 |
} \ |
|
1227 |
if (__offs > 0) \ |
|
1228 |
(ret) = __offs; \ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1229 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1230 |
# else /* use STDIO */ |
12548 | 1231 |
# define __WRITEBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
2961 | 1232 |
(ret) = 0; \ |
1233 |
if (isBuffered) { \ |
|
23743 | 1234 |
int __offs = 0; \ |
1235 |
while (__offs < (cnt)) { \ |
|
1236 |
CLEAR_ERRNO; \ |
|
1237 |
(ret) = fwrite((buf)+__offs, 1, (cnt)-__offs, f);\ |
|
1238 |
if ((ret) <= 0) { \ |
|
1239 |
if (ferror(f)) { \ |
|
1240 |
if (errno == EINTR) { \ |
|
1241 |
__HANDLE_INTERRUPTS__; \ |
|
1242 |
clearerr(f); \ |
|
1243 |
continue; \ |
|
1244 |
} \ |
|
1245 |
} else { \ |
|
1246 |
(ret) = 0; \ |
|
1247 |
} \ |
|
1248 |
break; \ |
|
1249 |
} \ |
|
1250 |
__offs += (ret); \ |
|
1251 |
} \ |
|
1252 |
if (__offs > 0) \ |
|
1253 |
(ret) = __offs; \ |
|
2961 | 1254 |
} else { \ |
23743 | 1255 |
int __offs = 0; \ |
1256 |
while (__offs < (cnt)) { \ |
|
1257 |
CLEAR_ERRNO; \ |
|
1258 |
(ret) = write(fileno(f), (buf)+__offs, (cnt)-__offs);\ |
|
1259 |
if ((ret) <= 0) { \ |
|
1260 |
if ((ret) < 0) { \ |
|
1261 |
if (errno == EINTR) { \ |
|
1262 |
__HANDLE_INTERRUPTS__; \ |
|
1263 |
continue; \ |
|
1264 |
} \ |
|
1265 |
} \ |
|
1266 |
break; \ |
|
1267 |
} \ |
|
1268 |
__offs += (ret); \ |
|
1269 |
} \ |
|
1270 |
if (__offs > 0) \ |
|
1271 |
(ret) = __offs; \ |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1272 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1273 |
# endif /* use STDIO */ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1274 |
|
223 | 1275 |
/* |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1276 |
* write_bytes from an object |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1277 |
* (which may be moved around by GC) |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1278 |
*/ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1279 |
# ifdef NO_STDIO |
12548 | 1280 |
# define __WRITEBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered, handleType) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1281 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1282 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1283 |
int __offs = 0; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1284 |
char *buf = (char *)(obj); \ |
23743 | 1285 |
\ |
2961 | 1286 |
(ret) = 0; \ |
1287 |
{ \ |
|
23743 | 1288 |
while (__offs < (cnt)) { \ |
1289 |
CLEAR_ERRNO; \ |
|
1290 |
ret = WRITE(f, (buf)+__ooffs+__offs, (cnt)-__offs, handleType); \ |
|
1291 |
if (ret <= 0) { \ |
|
1292 |
if (ret < 0 && errno == EINTR) { \ |
|
1293 |
__HANDLE_INTERRUPTS__; \ |
|
1294 |
/* refetch */ \ |
|
1295 |
buf = (char *)(obj); \ |
|
1296 |
continue; \ |
|
1297 |
} \ |
|
1298 |
break; \ |
|
1299 |
} \ |
|
1300 |
__offs += (ret); \ |
|
1301 |
} \ |
|
1302 |
if (__offs > 0) \ |
|
1303 |
(ret) = __offs; \ |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1304 |
} \ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1305 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1306 |
# else /* use STDIO */ |
12548 | 1307 |
# define __WRITEBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered, handleType) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1308 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1309 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1310 |
int __offs = 0; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1311 |
char *buf = (char *)(obj); \ |
23743 | 1312 |
\ |
2961 | 1313 |
(ret) = 0; \ |
1314 |
if (isBuffered) { \ |
|
23743 | 1315 |
while (__offs < (cnt)) { \ |
1316 |
CLEAR_ERRNO; \ |
|
1317 |
(ret) = fwrite((buf)+__ooffs+__offs, 1, (cnt)-__offs, f); \ |
|
1318 |
if ((ret) <= 0) { \ |
|
1319 |
if (ferror(f)) { \ |
|
1320 |
if (errno == EINTR) { \ |
|
1321 |
__HANDLE_INTERRUPTS__; \ |
|
1322 |
/* refetch */ \ |
|
1323 |
buf = (char *)(obj); \ |
|
1324 |
clearerr(f); \ |
|
1325 |
continue; \ |
|
1326 |
} \ |
|
1327 |
break; \ |
|
1328 |
} else { \ |
|
1329 |
(ret) = 0; \ |
|
1330 |
} \ |
|
1331 |
} \ |
|
1332 |
__offs += (ret); \ |
|
1333 |
} \ |
|
2961 | 1334 |
} else { \ |
23743 | 1335 |
while (__offs < (cnt)) { \ |
1336 |
CLEAR_ERRNO; \ |
|
1337 |
(ret) = write(fileno(f), (buf)+__ooffs+__offs, (cnt)-__offs); \ |
|
1338 |
if ((ret) <= 0) { \ |
|
1339 |
if ((ret) < 0) { \ |
|
1340 |
if (errno == EINTR){ \ |
|
1341 |
__HANDLE_INTERRUPTS__; \ |
|
1342 |
/* refetch */ \ |
|
1343 |
buf = (char *)(obj); \ |
|
1344 |
continue; \ |
|
1345 |
} \ |
|
1346 |
} \ |
|
1347 |
break; \ |
|
1348 |
} \ |
|
1349 |
__offs += (ret); \ |
|
1350 |
} \ |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1351 |
} \ |
15845 | 1352 |
if (__offs > 0) \ |
23743 | 1353 |
(ret) = __offs; \ |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1354 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1355 |
# endif /* use STDIO */ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1356 |
#endif /* unix */ |
1 | 1357 |
%} |
188 | 1358 |
! ! |
1 | 1359 |
|
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1360 |
!ExternalStream class methodsFor:'documentation'! |
22 | 1361 |
|
88 | 1362 |
copyright |
1363 |
" |
|
1364 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1365 |
All Rights Reserved |
88 | 1366 |
|
1367 |
This software is furnished under a license and may be used |
|
1368 |
only in accordance with the terms of that license and with the |
|
1369 |
inclusion of the above copyright notice. This software may not |
|
1370 |
be provided or otherwise made available to, or used by, any |
|
1371 |
other person. No title to or ownership of the software is |
|
1372 |
hereby transferred. |
|
1373 |
" |
|
1374 |
! |
|
1375 |
||
22 | 1376 |
documentation |
1377 |
" |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1378 |
ExternalStream defines protocol common to Streams which have a file-descriptor and |
68 | 1379 |
represent some file or communicationChannel of the underlying OperatingSystem. |
1380 |
ExternalStream is abstract; concrete classes are FileStream, PipeStream etc. |
|
77 | 1381 |
|
159 | 1382 |
ExternalStreams can be in two modes: text- (the default) and binary-mode. |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1383 |
In text-mode, the elements read/written are characters; |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1384 |
while in binary-mode the basic elements are bytes which read/write as SmallIntegers |
68 | 1385 |
in the range 0..255. |
22 | 1386 |
|
68 | 1387 |
Also, the stream can be either in buffered or unbuffered mode. In buffered mode, |
1388 |
data is not written until either a cr is written (in text mode) or a synchronizeOutput |
|
1389 |
is sent (in both modes). |
|
22 | 1390 |
|
77 | 1391 |
The underlying OperatingSystem streams may either be closed explicitely (sending a close) |
68 | 1392 |
or just forgotten - in this case, the garbage collector will eventually collect the |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1393 |
object AND a close will be performed automatically (but you will NOT know when this |
77 | 1394 |
happens - so it is recommended, that you close your files when no longer needed). |
159 | 1395 |
Closing is also suggested, since if smalltalk is finished (be it by purpose, or due to |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1396 |
some crash) the data will not be in the file, if unclosed. |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1397 |
All streams understand the close message, so it never hurts to use it (it is defined as |
77 | 1398 |
a noop in one of the superclasses). |
22 | 1399 |
|
68 | 1400 |
Most of the methods found here redefine inherited methods for better performance, |
1401 |
since I/O from/to files should be fast. |
|
22 | 1402 |
|
68 | 1403 |
Recovering a snapshot: |
1295 | 1404 |
not all streams can be restored to the state they had before - see the implementation of |
1405 |
reOpen in subclasses for more information. |
|
1406 |
For streams sitting on some communication channel (i.e. Pipes and Sockets) you should |
|
1407 |
reestablish the stream upon image restart (make someone dependent on ObjectMemory). |
|
1408 |
FileStreams are reopened and positioned to their offset they had at snapshot time. |
|
1409 |
This may fail, if the file was removed or renamed - or lead to confusion |
|
1410 |
if the contents changed in the meantime. |
|
1411 |
Therefore, it is a good idea to reopen files and check for these things at restart time. |
|
1412 |
||
1413 |
[Instance variables:] |
|
1414 |
||
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1415 |
handleType <Symbol> desribes what handle is: |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1416 |
win32: #fileHandle, #socketHandle, |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1417 |
#filePointer, #socketFilePointer, #pipeFilePointer |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1418 |
unix: #filePointer, #socketFilePointer, #pipeFilePointer |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1419 |
needed for win32, which uses different APIs for the different handles (sigh) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1420 |
handle <Integer> used to be always a filePointer somehow mapped to an integer (FILE* - not the fd); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1421 |
now, either a filePointer or a handle (win32) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1422 |
mode <Symbol> #readwrite, #readonly or #writeonly |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1423 |
buffered <Boolean> true, if buffered (i.e. collects characters - does |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1424 |
not output immediately) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1425 |
binary <Boolean> true if in binary mode (reads bytes instead of chars) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1426 |
eolMode <Symbol> one of nil, #nl, #cr or #crlf. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1427 |
determines how lines should be terminated. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1428 |
nil -> newLine (as in Unix); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1429 |
#crlf -> with cr-lf (as in MSDOS) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1430 |
#cr -> with cr (as in VMS) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1431 |
hitEOF <Boolean> true, if EOF was reached |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1432 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1433 |
lastErrorNumber <Integer> the value of errno (only valid right after the error - |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1434 |
updated with next i/o operation) |
1295 | 1435 |
|
1436 |
[Class variables:] |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1437 |
Lobby <Registry> keeps track of used ext-streams (to free up FILE*'s) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1438 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1439 |
StreamErrorSignal <Signal> parent of all stream errors (see Stream class) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1440 |
InvalidReadSignal <Signal> raised on read from writeonly stream |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1441 |
InvalidWriteSignal <Signal> raised on write to readonly stream |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1442 |
InvalidModeSignal <Signal> raised on text I/O with binary-stream |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1443 |
or binary I/O with text-stream |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1444 |
OpenErrorSignal <Signal> raised if open fails |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1445 |
StreamNotOpenSignal <Signal> raised on I/O with non-open stream |
159 | 1446 |
|
1447 |
Additional notes: |
|
1448 |
This class is implemented using the underlying stdio-c library package, which |
|
1449 |
has both advantages and disadvantages: since it is portable (posix defined), porting |
|
1450 |
ST/X to non-Unix machines is simplified. The disadvantage is that the stdio library |
|
1451 |
has big problems handling unbounded Streams, since the EOF handling in stdio is |
|
1452 |
not prepared for data to arrive after EOF has been reached - time will show, if we need |
|
1453 |
a complete rewrite for UnboundedStream ... |
|
325 | 1454 |
|
188 | 1455 |
Also, depending on the system, the stdio library behaves infriendly when signals |
1456 |
occur while reading (for example, timer interrupts) - on real unixes (i.e. BSD) the signal |
|
1457 |
is handled transparently - on SYS5.3 (i.e. non unixes :-) the read operation returns |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1458 |
an error and errno is set to EINTR. |
20411 | 1459 |
That's what the ugly code around all getc-calls is for ... |
1295 | 1460 |
Since things get more and more ugly - we will rewrite ExternalStream |
1461 |
completely, to NOT use any stdio stuff (and do its buffering itself). |
|
325 | 1462 |
|
1463 |
Notice that typical stdio's use a single errno global variable to return an error code, |
|
16508 | 1464 |
this was bad design in the stdio lib (right from the very beginning), since it's much |
325 | 1465 |
harder to deal with this in the presence of lightweight processes, where errno gets |
1466 |
overwritten by an I/O operation done in another thread. (stdio should have been written |
|
1467 |
to return errno as a negative number ...). |
|
1468 |
To deal with this, the scheduler treats errno like a per-thread private variable, |
|
1469 |
and saves/restores the errno setting when switching to another thread. |
|
1470 |
(Notice that some thread packages do this also, but ST/X's thread implementation |
|
1471 |
does not depend on those, but instead uses a portable private package). |
|
1472 |
||
216 | 1473 |
Finally, if an stdio-stream is open for both reading and writing, we have to call |
1474 |
fseek whenever we are about to read after write and vice versa. |
|
1475 |
Two macros (__READING__ and __WRITING__) have been defined to be used before every |
|
1476 |
fread/fgetc and fwrite/putc respectively. |
|
1295 | 1477 |
|
1478 |
[author:] |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1479 |
Claus Gittinger |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1480 |
Stefan Vogel (many, many fixes ...) |
1295 | 1481 |
|
1482 |
[see also:] |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1483 |
FileStream Socket PipeStream |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1484 |
Filename OperatingSystem |
22 | 1485 |
" |
3255 | 1486 |
! |
1487 |
||
1488 |
examples |
|
1489 |
" |
|
1490 |
open a file, read the contents and display it in a textView: |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1491 |
[exBegin] |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1492 |
|topView scrollPane textView fileStream text| |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1493 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1494 |
topView := StandardSystemView new. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1495 |
topView label:'contents of Makefile'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1496 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1497 |
scrollPane := HVScrollableView in:topView. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1498 |
scrollPane origin:0.0@0.0 corner:1.0@1.0. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1499 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1500 |
textView := EditTextView new. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1501 |
scrollPane scrolledView:textView. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1502 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1503 |
fileStream := 'Makefile' asFilename readStream. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1504 |
text := fileStream upToEnd. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1505 |
fileStream close. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1506 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1507 |
textView contents:text. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1508 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1509 |
topView open. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1510 |
[exEnd] |
3255 | 1511 |
|
1512 |
||
1513 |
Notice, all of the above can also be done (simply) as: |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1514 |
[exBegin] |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1515 |
EditTextView openOn:'Makefile' |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1516 |
[exEnd] |
3255 | 1517 |
" |
22 | 1518 |
! ! |
1519 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1520 |
!ExternalStream class methodsFor:'initialization'! |
1 | 1521 |
|
18636 | 1522 |
closeFiles |
1523 |
"close all files. |
|
1524 |
To be called on exit of Smalltalk." |
|
1525 |
||
1526 |
Lobby do:[:eachFileStream | |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1527 |
(eachFileStream ~~ Stdin |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1528 |
and:[eachFileStream ~~ Stdout |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1529 |
and:[eachFileStream ~~ Stderr]]) ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1530 |
eachFileStream close |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1531 |
]. |
18636 | 1532 |
]. |
22709 | 1533 |
|
1534 |
"Modified: / 25-04-2018 / 15:23:41 / stefan" |
|
18636 | 1535 |
! |
1536 |
||
2920 | 1537 |
initDefaultEOLMode |
1538 |
OperatingSystem isUNIXlike ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1539 |
"/ unix EOL conventions |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1540 |
DefaultEOLMode := #nl |
2920 | 1541 |
] ifFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1542 |
OperatingSystem isVMSlike ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1543 |
"/ vms EOL conventions |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1544 |
DefaultEOLMode := #cr |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1545 |
] ifFalse:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1546 |
"/ msdos EOL conventions |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1547 |
"/ msdos uses #crlf. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1548 |
"/ the following breaks all programs, which do not explicitly |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1549 |
"/ change th eolMode when writing/reading binary files (zip reader) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1550 |
"/ MUST change all classes before doing the following. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1551 |
"/ Anyway: for backward compatibility (swisscom), it is left in this |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1552 |
"/ mode (for a while, I hope). |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1553 |
DefaultEOLMode := #crlf. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1554 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1555 |
"/ DefaultEOLMode := #nl |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1556 |
] |
2920 | 1557 |
] |
1558 |
! |
|
1559 |
||
1560 |
initModeStrings |
|
1561 |
"initialize modeStrings which are passed down to the underlying |
|
1562 |
fopen/fdopen functions." |
|
1563 |
||
3132
037027ae20fd
msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1564 |
OperatingSystem isMSDOSlike ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1565 |
ReadMode := 'rb'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1566 |
ReadWriteMode := 'rb+'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1567 |
WriteMode := 'wb'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1568 |
AppendMode := 'ab+'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1569 |
CreateReadWriteMode := 'wb+'. |
3132
037027ae20fd
msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1570 |
] ifFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1571 |
ReadMode := 'r'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1572 |
ReadWriteMode := 'r+'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1573 |
WriteMode := 'w'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1574 |
AppendMode := 'a+'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1575 |
CreateReadWriteMode := 'w+'. |
3132
037027ae20fd
msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1576 |
] |
2920 | 1577 |
! |
1578 |
||
1 | 1579 |
initialize |
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
583
diff
changeset
|
1580 |
OpenErrorSignal isNil ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1581 |
OpenErrorSignal := OpenError. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1582 |
OpenErrorSignal notifierString:'open error'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1583 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1584 |
InvalidReadSignal := InvalidReadError. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1585 |
InvalidReadSignal notifierString:'stream does not support reading'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1586 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1587 |
InvalidWriteSignal := InvalidWriteError. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1588 |
InvalidWriteSignal notifierString:'stream does not support writing'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1589 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1590 |
InvalidModeSignal := InvalidModeError. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1591 |
InvalidModeSignal notifierString:'binary/text mode mismatch'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1592 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1593 |
InvalidOperationSignal := InvalidOperationError. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1594 |
InvalidOperationSignal notifierString:'unsupported file operation'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1595 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1596 |
StreamNotOpenSignal := StreamNotOpenError. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1597 |
StreamNotOpenSignal notifierString:'stream is not open'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1598 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1599 |
StreamIOErrorSignal := StreamIOError. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1600 |
StreamIOErrorSignal notifierString:'I/O error'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1601 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1602 |
"/ self patchByteOrderOptimizedMethods |
159 | 1603 |
]. |
1604 |
||
31 | 1605 |
Lobby isNil ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1606 |
Lobby := Registry new. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1607 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1608 |
"want to get informed when returning from snapshot" |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1609 |
ObjectMemory addDependent:self |
2920 | 1610 |
]. |
5442 | 1611 |
DefaultEOLMode isNil ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1612 |
self initDefaultEOLMode. |
5442 | 1613 |
]. |
1614 |
ReadMode isNil ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1615 |
self initModeStrings. |
5442 | 1616 |
]. |
18790 | 1617 |
|
1618 |
"limit the amount of newspace to be used for non-tenurable executors to 5%" |
|
18929 | 1619 |
"/ MaxNonTenurableExecutors := ObjectMemory newSpaceSize // (Socket sizeOfInst:0) // 20. |
1620 |
"/ cg: changed because Socket is not in libbasic. Thus, standalone (libbasic only) |
|
1621 |
"/ programs would fail to start. |
|
19213
b990f28738b2
refactored to get rid of implizit sizeinnextPutXX:MSM:methods
Claus Gittinger <cg@exept.de>
parents:
19072
diff
changeset
|
1622 |
MaxNonTenurableExecutors := (ObjectMemory newSpaceSize // 20 min:2000). |
18790 | 1623 |
|
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1624 |
"Modified: / 21.5.1998 / 16:33:53 / cg" |
1 | 1625 |
! |
1626 |
||
19615 | 1627 |
patchByteOrderOptimizedMethods |
1628 |
"EXPERIMENTAL (not yet done by default): |
|
1629 |
change the underlying implementation of |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1630 |
nextPutInt16MSB / nextPutInt16LSB |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1631 |
nextPutInt32MSB / nextPutInt32LSB |
19615 | 1632 |
to the corresponding NATIVE methods." |
1633 |
||
1634 |
|native16 native32| |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
1635 |
|
19615 | 1636 |
native16 := self compiledMethodAt:#nextPutInt16NATIVE:. |
1637 |
native32 := self compiledMethodAt:#nextPutInt32NATIVE:. |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
1638 |
|
19615 | 1639 |
UninterpretedBytes isBigEndian ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1640 |
(self compiledMethodAt:#nextPutInt16MSB:) code:(native16 code). |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1641 |
(self compiledMethodAt:#nextPutInt32MSB:) code:(native32 code). |
19615 | 1642 |
] ifFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1643 |
(self compiledMethodAt:#nextPutInt16LSB:) code:(native16 code). |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1644 |
(self compiledMethodAt:#nextPutInt32LSB:) code:(native32 code). |
19615 | 1645 |
]. |
1646 |
! |
|
1647 |
||
1 | 1648 |
reOpenFiles |
4108
8c4a45bc70eb
perform reOpen of streams earlier (before doing the view-reinit)
Claus Gittinger <cg@exept.de>
parents:
4093
diff
changeset
|
1649 |
"reopen all files (if possible) after a snapShot load. |
8c4a45bc70eb
perform reOpen of streams earlier (before doing the view-reinit)
Claus Gittinger <cg@exept.de>
parents:
4093
diff
changeset
|
1650 |
This is invoked via the #earlyRestart change notification." |
1 | 1651 |
|
18636 | 1652 |
Lobby do:[:eachFileStream | |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1653 |
eachFileStream reOpen |
2920 | 1654 |
]. |
1 | 1655 |
! |
1656 |
||
1469 | 1657 |
update:something with:aParameter from:changedObject |
1 | 1658 |
"have to reopen files when returning from snapshot" |
1659 |
||
4108
8c4a45bc70eb
perform reOpen of streams earlier (before doing the view-reinit)
Claus Gittinger <cg@exept.de>
parents:
4093
diff
changeset
|
1660 |
something == #earlyRestart ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1661 |
self reOpenFiles. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1662 |
self initDefaultEOLMode |
1 | 1663 |
] |
1469 | 1664 |
|
1665 |
"Created: 15.6.1996 / 15:19:59 / cg" |
|
1 | 1666 |
! ! |
1667 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1668 |
!ExternalStream class methodsFor:'instance creation'! |
612 | 1669 |
|
12706 | 1670 |
forFileDescriptor:aFileDescriptor mode:modeSymbol |
2920 | 1671 |
"given a fileDescriptor, create an ExternalStream object |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1672 |
to operate on this fd. |
12706 | 1673 |
The modeSymbol-argument is #readonly, #readwrite, .... |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1674 |
This may be used to wrap fd's as returned by user |
2920 | 1675 |
primitive code, or to wrap pipe-fds into externalStreams." |
1676 |
||
12706 | 1677 |
^ self forFileDescriptor:aFileDescriptor mode:modeSymbol buffered:true handleType:nil |
7002 | 1678 |
|
1679 |
" |
|
1680 |
the example below will probably fail (15 is a random FD): |
|
1681 |
||
1682 |
|s| |
|
1683 |
||
1684 |
s := ExternalStream forFileDescriptor:15 mode:'r'. |
|
1685 |
s next. |
|
1686 |
" |
|
1687 |
||
1688 |
"Created: 29.2.1996 / 18:05:00 / cg" |
|
1689 |
"Modified: 29.2.1996 / 18:17:07 / cg" |
|
1690 |
! |
|
1691 |
||
12706 | 1692 |
forFileDescriptor:aFileDescriptor mode:modeSymbol buffered:buffered handleType:handleTypeSymbol |
7002 | 1693 |
"given a fileDescriptor, create an ExternalStream object |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1694 |
to operate on this fd. |
12706 | 1695 |
The modeSymbol-argument is #readonly, #readwrite, .... |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1696 |
This may be used to wrap fd's as returned by user |
7002 | 1697 |
primitive code, or to wrap pipe-fds into externalStreams." |
1698 |
||
21224 | 1699 |
^ self new |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1700 |
buffered:buffered; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1701 |
connectTo:aFileDescriptor withMode:modeSymbol handleType:handleTypeSymbol. |
2920 | 1702 |
|
1703 |
" |
|
1704 |
the example below will probably fail (15 is a random FD): |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1705 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1706 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1707 |
|
21224 | 1708 |
s := ExternalStream forFileDescriptor:15 mode:#readonly buffered:false handleType:#filePointer. |
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1709 |
s next. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1710 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1711 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1712 |
"Created: 29.2.1996 / 18:05:00 / cg" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1713 |
"Modified: 29.2.1996 / 18:17:07 / cg" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1714 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1715 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1716 |
forReadWriteToFileDescriptor:aFileDescriptor |
2920 | 1717 |
"given a fileDescriptor, create an ExternalStream object |
1718 |
to read/write from/to this fd. This may be used to wrap fd's |
|
1719 |
as returned by user primitive code, or to wrap pipe- |
|
1720 |
filedescriptors into externalStreams." |
|
1721 |
||
12706 | 1722 |
^ self forFileDescriptor:aFileDescriptor mode:#readWrite |
2920 | 1723 |
|
1724 |
" |
|
1725 |
the example below will probably fail (15 is a random FD): |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1726 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1727 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1728 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1729 |
s := ExternalStream forReadWriteToFileDescriptor:15. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1730 |
s next. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1731 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1732 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1733 |
"Created: 29.2.1996 / 18:15:08 / cg" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1734 |
"Modified: 29.2.1996 / 18:16:25 / cg" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1735 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1736 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1737 |
forReadingFromFileDescriptor:aFileDescriptor |
2920 | 1738 |
"given a fileDescriptor, create an ExternalStream object |
1739 |
to read from this fd. This may be used to wrap fd's |
|
1740 |
as returned by user primitive code, or to wrap pipe- |
|
1741 |
filedescriptors into externalStreams." |
|
1742 |
||
12706 | 1743 |
^ self forFileDescriptor:aFileDescriptor mode:#readonly |
2920 | 1744 |
|
1745 |
" |
|
1746 |
the example below will probably fail (15 is a random FD): |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1747 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1748 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1749 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1750 |
s := ExternalStream forReadingFromFileDescriptor:15. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1751 |
s next. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1752 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1753 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1754 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1755 |
|pipe readFd writeFd rs ws| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1756 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1757 |
'create OS pipe ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1758 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1759 |
pipe := OperatingSystem makePipe. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1760 |
readFd := pipe at:1. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1761 |
writeFd := pipe at:2. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1762 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1763 |
'connect Smalltalk streams ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1764 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1765 |
rs := ExternalStream forReadingFromFileDescriptor:readFd. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1766 |
ws := ExternalStream forWritingToFileDescriptor:writeFd. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1767 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1768 |
'read ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1769 |
[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1770 |
1 to:10 do:[:i | |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1771 |
Transcript showCR:rs nextLine |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1772 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1773 |
rs close. |
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1774 |
] forkAt:7. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1775 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1776 |
'write ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1777 |
[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1778 |
1 to:10 do:[:i | |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1779 |
ws nextPutAll:'hello world '; nextPutAll:i printString; cr |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1780 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1781 |
ws close. |
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1782 |
] fork. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1783 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1784 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1785 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1786 |
"Created: 29.2.1996 / 18:14:24 / cg" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1787 |
"Modified: 29.2.1996 / 18:25:02 / cg" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1788 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1789 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1790 |
forWritingToFileDescriptor:aFileDescriptor |
2920 | 1791 |
"given a fileDescriptor, create an ExternalStream object |
1792 |
to write to this fd. This may be used to wrap fd's |
|
1793 |
as returned by user primitive code, or to wrap pipe- |
|
1794 |
filedescriptors into externalStreams." |
|
1795 |
||
12706 | 1796 |
^ self forFileDescriptor:aFileDescriptor mode:#writeonly |
2920 | 1797 |
|
1798 |
" |
|
1799 |
the example below will probably fail (15 is a random FD): |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1800 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1801 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1802 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1803 |
s := ExternalStream forWritingToFileDescriptor:15. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1804 |
s binary. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1805 |
s nextPut:1. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1806 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1807 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1808 |
"Created: 29.2.1996 / 18:14:43 / cg" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1809 |
"Modified: 29.2.1996 / 18:15:54 / cg" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1810 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1811 |
|
612 | 1812 |
new |
15918
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
1813 |
"re-enable new - disabled in Stream superclass" |
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
1814 |
|
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
1815 |
^ self basicNew initialize. |
612 | 1816 |
! ! |
1817 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1818 |
!ExternalStream class methodsFor:'Signal constants'! |
159 | 1819 |
|
1522
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1820 |
inaccessibleSignal |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1821 |
"ST-80 compatibility: return openErrorSignal" |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1822 |
|
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1823 |
^ self openErrorSignal |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1824 |
|
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1825 |
"Created: 2.7.1996 / 12:27:16 / stefan" |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1826 |
! |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1827 |
|
612 | 1828 |
invalidModeSignal |
1829 |
"return the signal raised when doing text-I/O with a binary stream |
|
1830 |
or binary-I/O with a text stream" |
|
1831 |
||
8074 | 1832 |
^ InvalidModeError |
159 | 1833 |
! |
1834 |
||
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1835 |
invalidOperationSignal |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1836 |
"return the signal raised when an unsupported or invalid |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1837 |
I/O operation is attempted" |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1838 |
|
8074 | 1839 |
^ InvalidOperationError |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1840 |
! |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1841 |
|
159 | 1842 |
invalidReadSignal |
1843 |
"return the signal raised when reading from writeonly streams" |
|
1844 |
||
8074 | 1845 |
^ InvalidReadError |
159 | 1846 |
! |
1847 |
||
1848 |
invalidWriteSignal |
|
1849 |
"return the signal raised when writing to readonly streams" |
|
1850 |
||
8074 | 1851 |
^ InvalidWriteError |
159 | 1852 |
! |
1853 |
||
612 | 1854 |
openErrorSignal |
1855 |
"return the signal raised when a file open failed" |
|
1856 |
||
1857 |
^ OpenErrorSignal |
|
1858 |
! |
|
1859 |
||
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1860 |
streamIOErrorSignal |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1861 |
"return the signal raised when an I/O error occurs. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1862 |
(for example, a device-IO-error, or reading an NFS-dir, |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1863 |
which is no longer available and has been mounted soft)" |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1864 |
|
8074 | 1865 |
^ StreamIOError |
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1866 |
|
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1867 |
"Created: / 21.5.1998 / 16:32:55 / cg" |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1868 |
! |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1869 |
|
159 | 1870 |
streamNotOpenSignal |
1871 |
"return the signal raised on I/O with closed streams" |
|
1872 |
||
8074 | 1873 |
^ StreamNotOpenError |
2 | 1874 |
! ! |
1875 |
||
22697 | 1876 |
!ExternalStream class methodsFor:'accessing'! |
1877 |
||
1878 |
openStreams |
|
1879 |
"answer a collection of open Streams having this class" |
|
1880 |
||
1881 |
|openStreams| |
|
1882 |
||
1883 |
openStreams := OrderedCollection new. |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1884 |
Lobby keysDo:[:eachStream| |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1885 |
(eachStream isKindOf:self) ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1886 |
openStreams add:eachStream |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1887 |
] |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1888 |
]. |
22697 | 1889 |
|
1890 |
^ openStreams |
|
1891 |
||
1892 |
" |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1893 |
self openStreams |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1894 |
Socket openStreams |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1895 |
NonPositionableExternalStream openStreams |
22697 | 1896 |
" |
1897 |
||
1898 |
"Created: / 24-04-2018 / 09:23:33 / stefan" |
|
1899 |
! ! |
|
1900 |
||
21337 | 1901 |
!ExternalStream class methodsFor:'defaults'! |
1902 |
||
1903 |
defaultCopyBufferSize:anInteger |
|
1904 |
"allows changing the size of buffer used when copying big |
|
1905 |
files/buld data from one stream to another. |
|
1906 |
Due to a bug on older Windows systems, the default used in copyToEndInto: |
|
1907 |
is chosen very conservatively, as the copy used to fail with big buffers. |
|
1908 |
However, modern Windows systems seem to not suffer from that bug, |
|
22578 | 1909 |
and bigger buffer sizes will dramatically increase the performance of |
21337 | 1910 |
copies to/from network drives. |
1911 |
This method allows for fine tuning, in case you run into performance problems, |
|
1912 |
or network buffer failures. |
|
1913 |
When nil, a somewhat conservative compromise is used." |
|
22578 | 1914 |
|
21337 | 1915 |
^ DefaultCopyBufferSize |
1916 |
! ! |
|
1917 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1918 |
!ExternalStream class methodsFor:'error handling'! |
92 | 1919 |
|
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1920 |
errorReporter |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1921 |
"I know about error codes" |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1922 |
|
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1923 |
^ self |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1924 |
! |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1925 |
|
92 | 1926 |
lastErrorNumber |
159 | 1927 |
"return the errno of the last error" |
92 | 1928 |
|
1929 |
^ LastErrorNumber |
|
159 | 1930 |
|
1931 |
" |
|
1932 |
ExternalStream lastErrorNumber |
|
1933 |
" |
|
92 | 1934 |
! |
1935 |
||
1936 |
lastErrorString |
|
1937 |
"return a message string describing the last error" |
|
1938 |
||
1939 |
^ OperatingSystem errorTextForNumber:LastErrorNumber |
|
1940 |
||
1941 |
" |
|
1942 |
ExternalStream lastErrorString |
|
1943 |
" |
|
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1944 |
! |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1945 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1946 |
reportOn:anErrorSymbolOrNumber |
20259 | 1947 |
"an error occurred. |
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1948 |
Report it via an Exception" |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1949 |
|
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1950 |
anErrorSymbolOrNumber isInteger ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1951 |
StreamError |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1952 |
raiseRequestWith:anErrorSymbolOrNumber |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1953 |
errorString:(' - os error:' , (OperatingSystem errorTextForNumber:anErrorSymbolOrNumber)) |
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1954 |
]. |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1955 |
(self respondsTo:anErrorSymbolOrNumber) ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1956 |
self perform:anErrorSymbolOrNumber |
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1957 |
] ifFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1958 |
StreamError |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1959 |
raiseRequestWith:anErrorSymbolOrNumber |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1960 |
errorString:(' - ' , anErrorSymbolOrNumber printString) |
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1961 |
]. |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1962 |
^ false |
92 | 1963 |
! ! |
1964 |
||
20987 | 1965 |
!ExternalStream class methodsFor:'finalization'! |
1966 |
||
1967 |
finalizationLobby |
|
1968 |
"answer the registry used for finalization. |
|
1969 |
ExternalStreams have their own Registry" |
|
1970 |
||
1971 |
^ Lobby |
|
1972 |
! ! |
|
1973 |
||
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1974 |
!ExternalStream class methodsFor:'obsolete'! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1975 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1976 |
makePTYPair |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1977 |
"obsolete since 12-07-2003" |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1978 |
<resource:#obsolete> |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1979 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1980 |
self obsoleteMethodWarning:'use NonPositionableExternalStream makePTYPair'. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1981 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1982 |
^ NonPositionableExternalStream makePTYPair. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1983 |
! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1984 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1985 |
makePipe |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1986 |
"obsolete since 12-07-2003" |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1987 |
<resource:#obsolete> |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1988 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1989 |
self obsoleteMethodWarning:'use NonPositionableExternalStream makePipe'. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1990 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1991 |
^ NonPositionableExternalStream makePipe. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1992 |
! ! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1993 |
|
21037 | 1994 |
!ExternalStream class methodsFor:'testing'! |
1995 |
||
1996 |
isAbstract |
|
1997 |
^ self == ExternalStream |
|
1998 |
! ! |
|
1999 |
||
7261 | 2000 |
!ExternalStream methodsFor:'Compatibility-Dolphin'! |
6474 | 2001 |
|
2002 |
beText |
|
2003 |
self text |
|
2004 |
! ! |
|
2005 |
||
7261 | 2006 |
!ExternalStream methodsFor:'Compatibility-Squeak'! |
3044 | 2007 |
|
3872
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2008 |
nextInto:aByteArrayOrString |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2009 |
"read elements into the argument, whose size determines the amount |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2010 |
of bytes to read. If not enough elements could be read, return |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2011 |
a copy of the argument; otherwise, return the filled argument." |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2012 |
|
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2013 |
|n nWanted| |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2014 |
|
4368 | 2015 |
nWanted := aByteArrayOrString byteSize. |
3872
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2016 |
n := self nextAvailableBytes:nWanted into:aByteArrayOrString startingAt:1. |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2017 |
n == nWanted ifTrue:[^ aByteArrayOrString]. |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2018 |
^ aByteArrayOrString copyTo:n |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2019 |
|
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2020 |
! |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2021 |
|
4368 | 2022 |
readInto:aContainer startingAt:index count:nElements |
2023 |
"same as #nextBytes:into:startingAt: for ByteArrays; |
|
2024 |
for LongArrays, nelements longs are read. |
|
3872
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2025 |
Squeak compatibility." |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2026 |
|
4368 | 2027 |
|elementSize n| |
2028 |
||
2029 |
elementSize := aContainer class elementByteSize. |
|
13940
12eb1c056d5e
fixed: #readInto:startingAt:count:; offset was wrong for non-byte elements
Claus Gittinger <cg@exept.de>
parents:
13927
diff
changeset
|
2030 |
n := self nextBytes:nElements*elementSize into:aContainer startingAt:(index-1)*elementSize+1. |
4368 | 2031 |
^ n // elementSize |
3872
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2032 |
|
13940
12eb1c056d5e
fixed: #readInto:startingAt:count:; offset was wrong for non-byte elements
Claus Gittinger <cg@exept.de>
parents:
13927
diff
changeset
|
2033 |
"Modified: / 14-01-2012 / 19:00:35 / cg" |
3872
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2034 |
! |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2035 |
|
3044 | 2036 |
readOnly |
2037 |
"Squeak compatibility: make the stream readOnly" |
|
2038 |
||
2039 |
mode := #readonly |
|
2040 |
||
2041 |
"Modified: 20.10.1997 / 19:23:04 / cg" |
|
2042 |
"Created: 20.10.1997 / 19:23:19 / cg" |
|
2043 |
! ! |
|
2044 |
||
5187 | 2045 |
!ExternalStream methodsFor:'Signal constants'! |
2046 |
||
2047 |
invalidReadSignal |
|
2048 |
^ self class invalidReadSignal |
|
2049 |
||
2050 |
"Created: / 3.12.1998 / 15:12:06 / cg" |
|
2051 |
! |
|
2052 |
||
2053 |
invalidWriteSignal |
|
2054 |
^ self class invalidWriteSignal |
|
2055 |
||
2056 |
"Created: / 3.12.1998 / 15:12:10 / cg" |
|
2057 |
! ! |
|
2058 |
||
1 | 2059 |
!ExternalStream methodsFor:'accessing'! |
2060 |
||
612 | 2061 |
binary |
2062 |
"switch to binary mode - default is text" |
|
2063 |
||
2064 |
binary := true |
|
1 | 2065 |
! |
2066 |
||
23900 | 2067 |
binary:beBinaryBool |
2068 |
"switch to binary mode - default is text" |
|
2069 |
||
2070 |
|wasBinary| |
|
2071 |
||
2072 |
wasBinary := binary. |
|
2073 |
binary := beBinaryBool. |
|
2074 |
^ wasBinary |
|
2075 |
||
2076 |
"Created: / 13-03-2019 / 19:18:53 / Stefan Vogel" |
|
2077 |
! |
|
2078 |
||
1 | 2079 |
buffered:aBoolean |
23900 | 2080 |
"turn buffering on or off - default is on. |
2081 |
Answer the previous bufferd state." |
|
2082 |
||
2083 |
|wasBuffered| |
|
2084 |
||
2085 |
wasBuffered := buffered. |
|
2086 |
buffered := aBoolean. |
|
2087 |
^ wasBuffered. |
|
2088 |
||
2089 |
"Modified (comment): / 13-03-2019 / 19:33:16 / Stefan Vogel" |
|
1 | 2090 |
! |
2091 |
||
2092 |
contents |
|
2 | 2093 |
"return the contents of the file from the current position up-to |
2094 |
the end. If the stream is in binary mode, a ByteArray containing |
|
2095 |
the byte values is returned. |
|
2096 |
In text-mode, a collection of strings, each representing one line, |
|
2097 |
is returned." |
|
2098 |
||
20092 | 2099 |
|text| |
2 | 2100 |
|
2101 |
binary ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2102 |
^ self upToEnd. |
2 | 2103 |
]. |
1 | 2104 |
|
20092 | 2105 |
"/ text mode |
244 | 2106 |
text := StringCollection new. |
1 | 2107 |
[self atEnd] whileFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2108 |
|line| |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2109 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2110 |
line := self nextLine. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2111 |
line isNil ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2112 |
^ text |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2113 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2114 |
text add:line |
1 | 2115 |
]. |
2116 |
^ text |
|
2117 |
! |
|
2118 |
||
11751
1e75c54748ef
added #contentsAsString for Filename compatibility
Stefan Vogel <sv@exept.de>
parents:
11651
diff
changeset
|
2119 |
contentsAsString |
1e75c54748ef
added #contentsAsString for Filename compatibility
Stefan Vogel <sv@exept.de>
parents:
11651
diff
changeset
|
2120 |
"to compensate for the bad naming, use this to make things explicit. |
1e75c54748ef
added #contentsAsString for Filename compatibility
Stefan Vogel <sv@exept.de>
parents:
11651
diff
changeset
|
2121 |
See also #contents, which returns the lines as stringCollection for textFiles." |
1e75c54748ef
added #contentsAsString for Filename compatibility
Stefan Vogel <sv@exept.de>
parents:
11651
diff
changeset
|
2122 |
|
22848 | 2123 |
binary ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2124 |
^ [ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2125 |
binary := false. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2126 |
self contentsOfEntireFile. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2127 |
] ensure:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2128 |
binary := true. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2129 |
]. |
22848 | 2130 |
]. |
2131 |
||
2132 |
^ self contentsOfEntireFile. |
|
2133 |
||
2134 |
"Modified: / 09-05-2018 / 19:37:36 / stefan" |
|
11751
1e75c54748ef
added #contentsAsString for Filename compatibility
Stefan Vogel <sv@exept.de>
parents:
11651
diff
changeset
|
2135 |
! |
1e75c54748ef
added #contentsAsString for Filename compatibility
Stefan Vogel <sv@exept.de>
parents:
11651
diff
changeset
|
2136 |
|
612 | 2137 |
contentsOfEntireFile |
3938
4e7d1880336b
oops - #contentsOfEntireFile must return a byteArray if in binaryMode.
Claus Gittinger <cg@exept.de>
parents:
3906
diff
changeset
|
2138 |
"ST-80 compatibility: return contents as a String (or byteArray, if in binary mode). |
3876 | 2139 |
See also #contents, which returns the lines as stringCollection for text files." |
1522
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
2140 |
|
6305 | 2141 |
^ self upToEnd |
1522
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
2142 |
|
3876 | 2143 |
"Modified: / 3.7.1996 / 13:22:16 / stefan" |
3938
4e7d1880336b
oops - #contentsOfEntireFile must return a byteArray if in binaryMode.
Claus Gittinger <cg@exept.de>
parents:
3906
diff
changeset
|
2144 |
"Modified: / 27.11.1998 / 16:29:43 / cg" |
2 | 2145 |
! |
2146 |
||
612 | 2147 |
contentsSpecies |
2148 |
"return the kind of object to be returned by sub-collection builders |
|
2149 |
(such as upTo)" |
|
159 | 2150 |
|
21139 | 2151 |
binary ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2152 |
^ ByteArray |
159 | 2153 |
]. |
612 | 2154 |
^ String |
2 | 2155 |
! |
2156 |
||
23745 | 2157 |
dependents |
23751 | 2158 |
^ dependents ? #() |
23745 | 2159 |
|
2160 |
"Created: / 19-02-2019 / 16:08:09 / Claus Gittinger" |
|
23751 | 2161 |
"Modified: / 19-02-2019 / 23:42:56 / Claus Gittinger" |
23745 | 2162 |
! |
2163 |
||
2164 |
dependents:aDependentsCollection |
|
2165 |
dependents := aDependentsCollection |
|
2166 |
||
2167 |
"Created: / 19-02-2019 / 16:08:23 / Claus Gittinger" |
|
2168 |
! |
|
2169 |
||
16776 | 2170 |
eolMode |
2171 |
"return how end-of-line (EOL) is to be marked. |
|
2172 |
Returns one one of: |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2173 |
#crlf -> add a CR-NL, as in MSDOS |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2174 |
#cr -> add a CR, as in VMS |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2175 |
#nl -> add a NL, as in Unix |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2176 |
#eot -> add an EOT (= 0x04, as used in some modems/protocols) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2177 |
#etx -> add an ETX (= 0x03, as used in some modems/protocols) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2178 |
#nl -> add a NL, as in Unix |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2179 |
nil -> transparent |
16776 | 2180 |
" |
2181 |
||
17115
2ef08a902c34
did report error in close always as writeError - although it could also happen on a readonly stream
Claus Gittinger <cg@exept.de>
parents:
17078
diff
changeset
|
2182 |
^ eolMode |
21097 | 2183 |
|
2184 |
"Modified (comment): / 06-12-2016 / 14:26:24 / cg" |
|
16776 | 2185 |
! |
2186 |
||
2920 | 2187 |
eolMode:aSymbolOrNil |
2188 |
"specify how end-of-line (EOL) is to be marked. |
|
2189 |
The argument may be one of: |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2190 |
#crlf -> add a CR-NL, as in MSDOS |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2191 |
#cr -> add a CR, as in VMS |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2192 |
#nl -> add a NL, as in Unix |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2193 |
#eot -> add an EOT (= 0x04, as used in some modems/protocols) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2194 |
#etx -> add an ETX (= 0x03, as used in some modems/protocols) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2195 |
anyOther -> like #nl |
2920 | 2196 |
" |
2197 |
||
17462 | 2198 |
aSymbolOrNil == #crnl ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2199 |
eolMode := #crlf |
17462 | 2200 |
] ifFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2201 |
aSymbolOrNil == #lf ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2202 |
eolMode := #nl |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2203 |
] ifFalse:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2204 |
eolMode := aSymbolOrNil |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2205 |
] |
17462 | 2206 |
]. |
21097 | 2207 |
|
2208 |
"Modified (comment): / 06-12-2016 / 14:26:37 / cg" |
|
2920 | 2209 |
! |
2210 |
||
612 | 2211 |
fileDescriptor |
2212 |
"return the fileDescriptor of the receiver - |
|
2213 |
notice: this one returns the underlying OSs fileDescriptor - |
|
2214 |
this may not be available on all platforms (i.e. non unix systems)." |
|
1 | 2215 |
|
21742 | 2216 |
|fileClosed| |
22578 | 2217 |
|
3971 | 2218 |
%{ |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2219 |
OBJ _handle = __INST(handle); |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2220 |
|
21742 | 2221 |
fileClosed = false; |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2222 |
if (_handle != nil) { |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2223 |
if ((__INST(handleType) == @symbol(fileHandle)) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2224 |
|| (__INST(handleType) == @symbol(socketHandle))) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2225 |
RETURN (_handle); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2226 |
} |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2227 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2228 |
if ((__INST(handleType) == nil) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2229 |
|| (__INST(handleType) == @symbol(filePointer)) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2230 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2231 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2232 |
FILE *file = __FILEVal(_handle); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2233 |
if (file != NULL) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2234 |
int fileNo = fileno(file); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2235 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2236 |
if (fileNo >= 0) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2237 |
RETURN ( __MKINT(fileNo)); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2238 |
} |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2239 |
fileClosed = true; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2240 |
} |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2241 |
} |
1 | 2242 |
} |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2243 |
%}. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2244 |
handle isNil ifTrue:[^ self errorNotOpen]. |
21742 | 2245 |
fileClosed ifTrue:[handle := nil. ^ self errorNotOpen]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2246 |
^ self fileDescriptorOfFile:handle |
21689 | 2247 |
|
21742 | 2248 |
"Modified: / 05-05-2017 / 16:27:34 / cg" |
2249 |
! |
|
2250 |
||
2251 |
fileDescriptorOfFile:aHandle |
|
5852 | 2252 |
"for migration to rel5 only: |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2253 |
return the fileDescriptor of the argument handle - |
5852 | 2254 |
notice: this one returns the underlying OSs fileDescriptor - |
2255 |
this may not be available on all platforms (i.e. non unix systems)." |
|
2256 |
||
18312 | 2257 |
%{ |
2258 |
#ifdef __SCHTEAM__ |
|
21742 | 2259 |
return context._RETURN(aHandle); |
18312 | 2260 |
#endif |
2261 |
%}. |
|
21742 | 2262 |
^ nil |
2263 |
||
2264 |
"Modified: / 05-05-2017 / 16:20:20 / cg" |
|
612 | 2265 |
! |
2266 |
||
10455 | 2267 |
fileHandle |
2268 |
"return the fileHandle of the receiver. |
|
2269 |
Under unix, this is the fileDescriptor; under windows, this is the Handle." |
|
2270 |
||
2271 |
%{ |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2272 |
OBJ _handle = __INST(handle); |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2273 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2274 |
if (_handle != nil) { |
25142
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
2275 |
if ((__INST(handleType) == @symbol(fileHandle)) |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
2276 |
|| (__INST(handleType) == @symbol(socketHandle))) { |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
2277 |
RETURN (_handle); |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
2278 |
} |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
2279 |
if (__INST(handleType) == @symbol(pipeFilePointer)) { |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
2280 |
RETURN (__MKINT(fileno(__FILEVal(_handle)))); |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
2281 |
} |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
2282 |
if ((__INST(handleType) == nil) |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
2283 |
|| (__INST(handleType) == @symbol(filePointer)) |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
2284 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
2285 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
2286 |
FILE *file = __FILEVal(_handle); |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
2287 |
if (file != NULL) { |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
2288 |
int fileNo = fileno(file); |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
2289 |
if (fileNo >= 0) { |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
2290 |
#ifdef __win32__ |
25142
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
2291 |
RETURN(__MKEXTERNALADDRESS(_get_osfhandle(fileNo))); |
10455 | 2292 |
#else |
25142
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
2293 |
RETURN (__MKINT(fileNo)); |
10455 | 2294 |
#endif |
25142
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
2295 |
} |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
2296 |
} |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
2297 |
} |
10455 | 2298 |
} |
2299 |
%}. |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2300 |
^ handle |
21688 | 2301 |
|
2302 |
"Modified: / 07-04-2017 / 16:34:40 / cg" |
|
10455 | 2303 |
! |
2304 |
||
612 | 2305 |
filePointer |
2306 |
"return the filePointer of the receiver - |
|
2307 |
notice: for portability stdio is used; this means you will get |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
2308 |
a FILE * - not a fileDescriptor. |
612 | 2309 |
(what you really get is a corresponding integer). |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
2310 |
You cannot do much with the returned value |
612 | 2311 |
- except passing it to a primitive, for example." |
2312 |
||
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2313 |
(handleType isNil or:[handleType == #filePointer]) ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2314 |
^ handle |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2315 |
]. |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2316 |
^ self error:'not a FILE*' |
612 | 2317 |
! |
2318 |
||
21229 | 2319 |
handle |
2320 |
^ handle |
|
2321 |
! |
|
2322 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2323 |
handleType |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2324 |
^ handleType |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2325 |
! |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2326 |
|
5323 | 2327 |
lineEndCRLF |
2328 |
eolMode := #crlf |
|
2329 |
! |
|
2330 |
||
17672 | 2331 |
lineEndLF |
2332 |
eolMode := #nl |
|
2333 |
! |
|
2334 |
||
3016 | 2335 |
lineEndTransparent |
17426
6e49243ce4e0
fix: code treated everything but nl,cr,crnl symbols als cr (by accident).
Claus Gittinger <cg@exept.de>
parents:
17420
diff
changeset
|
2336 |
eolMode := #nl |
3016 | 2337 |
! |
2338 |
||
8069
fdf460457c96
acessing: pathName added (returns nil)
Michael Beyl <mb@exept.de>
parents:
8066
diff
changeset
|
2339 |
pathName |
8511
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2340 |
"answer the pathName of the stream. |
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2341 |
Only FileStreams know the pathName, so we return an empty string here" |
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2342 |
|
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2343 |
^ '' |
8069
fdf460457c96
acessing: pathName added (returns nil)
Michael Beyl <mb@exept.de>
parents:
8066
diff
changeset
|
2344 |
! |
fdf460457c96
acessing: pathName added (returns nil)
Michael Beyl <mb@exept.de>
parents:
8066
diff
changeset
|
2345 |
|
612 | 2346 |
readonly |
2347 |
"set access mode to readonly" |
|
2348 |
||
2349 |
mode := #readonly |
|
2350 |
! |
|
2351 |
||
2352 |
readwrite |
|
2353 |
"set access mode to readwrite" |
|
2354 |
||
2355 |
mode := #readwrite |
|
2356 |
! |
|
2357 |
||
2358 |
text |
|
2359 |
"switch to text mode - default is text" |
|
2360 |
||
2361 |
binary := false |
|
2362 |
! |
|
2363 |
||
2364 |
useCRLF:aBoolean |
|
20147 | 2365 |
<resource: #obsolete> |
2920 | 2366 |
"turn on or off CRLF sending (instead of LF only) - default is off. |
2367 |
This method is provided for backward compatibility - see #eolMode: |
|
2368 |
which offers another choice." |
|
2369 |
||
2370 |
aBoolean ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2371 |
eolMode := #crlf |
2920 | 2372 |
] ifFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2373 |
eolMode := #nl |
2920 | 2374 |
]. |
1 | 2375 |
! |
2376 |
||
612 | 2377 |
writeonly |
2378 |
"set access mode to writeonly" |
|
2379 |
||
2380 |
mode := #writeonly |
|
2381 |
! ! |
|
2382 |
||
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2383 |
!ExternalStream methodsFor:'closing'! |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2384 |
|
20679 | 2385 |
abortAndClose |
2386 |
"close the stream - added for protocol compatibility with Socket and PipeStream. |
|
2387 |
see comment there" |
|
2388 |
||
2389 |
self close. |
|
2390 |
||
2391 |
"Modified: 30.8.1996 / 00:39:21 / cg" |
|
2392 |
! |
|
2393 |
||
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2394 |
close |
20106 | 2395 |
"Close the stream. |
2396 |
No error if the stream is not open." |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2397 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2398 |
self isOpen ifTrue:[ |
23879 | 2399 |
self unregisterForFinalization. |
2400 |
self isOpen ifTrue:[ |
|
2401 |
self closeFile. |
|
2402 |
dependents notNil ifTrue:[ |
|
2403 |
self changed:#close. |
|
2404 |
]. |
|
2405 |
]. |
|
16300 | 2406 |
]. |
23745 | 2407 |
|
2408 |
"Modified: / 19-02-2019 / 16:08:51 / Claus Gittinger" |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2409 |
! |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2410 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2411 |
shutDown |
20679 | 2412 |
"close the stream - added for protocol compatibility with Socket. |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2413 |
see comment there" |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2414 |
|
19072 | 2415 |
self close. |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2416 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2417 |
"Modified: 30.8.1996 / 00:39:21 / cg" |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2418 |
! ! |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2419 |
|
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2420 |
!ExternalStream methodsFor:'copying'! |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2421 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2422 |
copy |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2423 |
"answer a copy of myself. |
22713 | 2424 |
Have to dup the filedescriptor and position the copy" |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2425 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2426 |
|copy| |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2427 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2428 |
copy := super copy. |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2429 |
copy dupFd. |
22713 | 2430 |
self isPositionable ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2431 |
copy position:position. |
22713 | 2432 |
]. |
18779 | 2433 |
copy registerForFinalization. |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2434 |
^ copy |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2435 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2436 |
" |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2437 |
|stream1 stream2| |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2438 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2439 |
stream1 := Filename newTemporary writeStream. |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2440 |
stream2 := stream1 copy. |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2441 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2442 |
stream1 inspect. |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2443 |
stream2 inspect. |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2444 |
" |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2445 |
! ! |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2446 |
|
23913 | 2447 |
!ExternalStream methodsFor:'defaults'! |
2448 |
||
2449 |
bufferSizeForBulkCopy |
|
25136 | 2450 |
"return the size of buffer used when copying big files/bulk data |
23913 | 2451 |
from one stream to another. |
2452 |
Due to a bug on older Windows systems, the default used |
|
2453 |
is chosen very conservatively, as the copy used to fail with big buffers. |
|
2454 |
However, modern Windows systems seem to not suffer from that bug, |
|
2455 |
and bigger buffer sizes will dramatically increase the performance of |
|
2456 |
copies to/from network drives. |
|
2457 |
Setting DefaultCopyBufferSize allows for fine tuning, |
|
2458 |
in case you run into performance problems, or network buffer failures. |
|
2459 |
When nil, a somewhat conservative compromise is used." |
|
2460 |
||
2461 |
DefaultCopyBufferSize notNil ifTrue:[^ DefaultCopyBufferSize]. |
|
2462 |
||
2463 |
(OperatingSystem isMSWINDOWSlike and:[OperatingSystem isWin7Like not]) ifTrue:[ |
|
25136 | 2464 |
"/ mhmh - NT hangs, when copying bigger blocks to a network drive - why ? |
2465 |
^ 1 * 1024. |
|
23913 | 2466 |
]. |
2467 |
^ 64 * 1024. |
|
2468 |
||
2469 |
"Created: / 13-03-2019 / 16:49:17 / Stefan Vogel" |
|
2470 |
"Modified: / 13-03-2019 / 23:19:43 / Stefan Vogel" |
|
2471 |
! ! |
|
2472 |
||
612 | 2473 |
!ExternalStream methodsFor:'error handling'! |
2474 |
||
2475 |
argumentMustBeCharacter |
|
14440 | 2476 |
"report an error, that the argument must be a character in 0..FF" |
2477 |
||
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2478 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2479 |
|
14440 | 2480 |
ArgumentError raiseErrorString:' - argument must be a single byte character' |
612 | 2481 |
! |
2482 |
||
2483 |
argumentMustBeInteger |
|
14440 | 2484 |
"report an error, that the argument must be an integer" |
2485 |
||
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2486 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2487 |
|
14440 | 2488 |
ArgumentError raiseErrorString:' - argument must be an integer' |
77 | 2489 |
! |
2490 |
||
612 | 2491 |
argumentMustBeString |
14440 | 2492 |
"report an error, that the argument must be a string" |
2493 |
||
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2494 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2495 |
|
14440 | 2496 |
ArgumentError raiseErrorString:' - argument must be a string' |
612 | 2497 |
! |
2498 |
||
4526
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2499 |
errorAlreadyOpen |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2500 |
"{ Pragma: +optSpace }" |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2501 |
|
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2502 |
"report an error, that the stream is already opened" |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2503 |
|
8074 | 2504 |
^ OpenError |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2505 |
raiseRequestWith:self |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2506 |
errorString:' - stream is already open' |
8511
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2507 |
|
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2508 |
" |
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2509 |
self new errorAlreadyOpen |
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2510 |
" |
4526
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2511 |
|
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2512 |
"Modified: / 8.5.1999 / 20:12:30 / cg" |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2513 |
! |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2514 |
|
612 | 2515 |
errorBinary |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2516 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2517 |
|
612 | 2518 |
"report an error, that the stream is in binary mode" |
2519 |
||
8074 | 2520 |
^ InvalidModeError |
25136 | 2521 |
raiseRequestWith:self |
2522 |
errorString:(self className , ' is in binary mode') |
|
2523 |
"/ in:thisContext sender |
|
24383 | 2524 |
|
2525 |
"Modified: / 08-05-1999 / 20:12:43 / cg" |
|
2526 |
"Modified: / 28-06-2019 / 08:43:06 / Claus Gittinger" |
|
612 | 2527 |
! |
2528 |
||
2529 |
errorNotBinary |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2530 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2531 |
|
612 | 2532 |
"report an error, that the stream is not in binary mode" |
2533 |
||
8074 | 2534 |
^ InvalidModeError |
25136 | 2535 |
raiseRequestWith:self |
2536 |
errorString:(self className , ' is not in binary mode') |
|
2537 |
"/ in:thisContext sender |
|
24383 | 2538 |
|
2539 |
"Modified: / 08-05-1999 / 20:12:40 / cg" |
|
2540 |
"Modified: / 28-06-2019 / 08:43:11 / Claus Gittinger" |
|
1 | 2541 |
! |
2542 |
||
612 | 2543 |
errorNotBuffered |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2544 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2545 |
|
612 | 2546 |
"report an error, that the stream is not in buffered mode" |
2547 |
||
8074 | 2548 |
^ StreamError |
25136 | 2549 |
raiseRequestWith:self |
2550 |
errorString:(self className , ' is unbuffered - operation not allowed') |
|
2551 |
"/ in:thisContext sender |
|
24383 | 2552 |
|
2553 |
"Modified: / 08-05-1999 / 20:12:36 / cg" |
|
2554 |
"Modified: / 28-06-2019 / 08:43:14 / Claus Gittinger" |
|
612 | 2555 |
! |
2556 |
||
2557 |
errorReadOnly |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2558 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2559 |
|
612 | 2560 |
"report an error, that the stream is a readOnly stream" |
2561 |
||
8511
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2562 |
^ InvalidWriteSignal raiseRequestWith:self "/ in:thisContext sender |
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2563 |
|
4468 | 2564 |
"Modified: / 30.7.1999 / 17:08:19 / cg" |
612 | 2565 |
! |
2566 |
||
6255
d68343dc8288
Define #errorReporter and #reportError: (ST-80 protocol)
Stefan Vogel <sv@exept.de>
parents:
6012
diff
changeset
|
2567 |
errorReporter |
d68343dc8288
Define #errorReporter and #reportError: (ST-80 protocol)
Stefan Vogel <sv@exept.de>
parents:
6012
diff
changeset
|
2568 |
"ST-80 mimicry." |
d68343dc8288
Define #errorReporter and #reportError: (ST-80 protocol)
Stefan Vogel <sv@exept.de>
parents:
6012
diff
changeset
|
2569 |
|
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
2570 |
^ self class |
6255
d68343dc8288
Define #errorReporter and #reportError: (ST-80 protocol)
Stefan Vogel <sv@exept.de>
parents:
6012
diff
changeset
|
2571 |
! |
d68343dc8288
Define #errorReporter and #reportError: (ST-80 protocol)
Stefan Vogel <sv@exept.de>
parents:
6012
diff
changeset
|
2572 |
|
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2573 |
errorUnsupportedOperation |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2574 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2575 |
|
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2576 |
"report an error, that some unsupported operation was attempted" |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2577 |
|
8511
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2578 |
^ InvalidOperationError raiseRequestWith:self "/ in:thisContext sender |
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2579 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2580 |
"Modified: / 8.5.1999 / 20:12:24 / cg" |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2581 |
! |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2582 |
|
612 | 2583 |
errorWriteOnly |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2584 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2585 |
|
612 | 2586 |
"report an error, that the stream is a writeOnly stream" |
2587 |
||
8511
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2588 |
^ InvalidReadError raiseRequestWith:self "/ in:thisContext sender |
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2589 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2590 |
"Modified: / 8.5.1999 / 20:12:20 / cg" |
2 | 2591 |
! |
2592 |
||
612 | 2593 |
ioError |
20259 | 2594 |
"report an error, that some I/O error occurred. |
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
2595 |
(for example, a device-IO-error, or reading an NFS-dir, |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
2596 |
which is no longer available and has been mounted soft)" |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
2597 |
|
16296 | 2598 |
"{ Pragma: +optSpace }" |
2599 |
||
2600 |
self ioError:lastErrorNumber |
|
2601 |
||
2602 |
"Modified: / 8.5.1999 / 20:12:16 / cg" |
|
2603 |
! |
|
2604 |
||
2605 |
ioError:errorNumber |
|
20259 | 2606 |
"report an error, that some I/O error occurred. |
16296 | 2607 |
(for example, a device-IO-error, or reading an NFS-dir, |
2608 |
which is no longer available and has been mounted soft)" |
|
2609 |
||
2610 |
"{ Pragma: +optSpace }" |
|
2611 |
||
2612 |
^ StreamIOError newException |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2613 |
errorCode:errorNumber; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2614 |
osErrorHolder:(OperatingSystem errorHolderForNumber:errorNumber); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2615 |
parameter:self; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2616 |
raiseRequest |
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2617 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2618 |
"Modified: / 8.5.1999 / 20:12:16 / cg" |
612 | 2619 |
! |
2620 |
||
2621 |
lastErrorNumber |
|
2622 |
"return the last error" |
|
2623 |
||
2624 |
^ lastErrorNumber |
|
2625 |
! |
|
2626 |
||
2627 |
lastErrorString |
|
2628 |
"return a message string describing the last error" |
|
2629 |
||
2630 |
(lastErrorNumber isNil or:[lastErrorNumber == 0]) ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2631 |
^ 'I/O error' |
612 | 2632 |
]. |
2633 |
^ OperatingSystem errorTextForNumber:lastErrorNumber |
|
2 | 2634 |
! |
2635 |
||
10932 | 2636 |
lastErrorSymbol |
2637 |
"return an error symbol describing the last error" |
|
2638 |
||
2639 |
^ OperatingSystem errorSymbolForNumber:lastErrorNumber |
|
2640 |
! |
|
2641 |
||
612 | 2642 |
openError |
12688 | 2643 |
"report an error, that the open failed" |
2644 |
||
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2645 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2646 |
|
14438 | 2647 |
^ self openError:lastErrorNumber. |
612 | 2648 |
! |
2649 |
||
12688 | 2650 |
openError:errorNumber |
2651 |
"report an error, that the open failed" |
|
2652 |
||
2653 |
"{ Pragma: +optSpace }" |
|
2654 |
||
15496 | 2655 |
|exClass errorHolder| |
2656 |
||
2657 |
errorHolder := OperatingSystem errorHolderForNumber:errorNumber. |
|
2658 |
||
2659 |
exClass := (errorHolder errorCategory == #nonexistentSignal) |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2660 |
ifTrue:[ FileDoesNotExistException ] |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2661 |
ifFalse:[ OpenError ]. |
13673 | 2662 |
|
2663 |
^ exClass newException |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2664 |
errorCode:errorNumber; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2665 |
osErrorHolder:errorHolder; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2666 |
"/ cg: initialized lazily - see OpenError>>#description |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2667 |
"/ errorString:(' : ' , errorHolder errorString); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2668 |
parameter:self; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2669 |
raiseRequest |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2670 |
"/ in:thisContext sender |
13673 | 2671 |
|
2672 |
"Modified: / 09-09-2011 / 07:22:49 / cg" |
|
12688 | 2673 |
! |
2674 |
||
612 | 2675 |
readError |
20259 | 2676 |
"report an error, that some read error occurred" |
15845 | 2677 |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2678 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2679 |
|
15845 | 2680 |
^ self readError:lastErrorNumber |
2681 |
! |
|
2682 |
||
2683 |
readError:errorNumber |
|
20259 | 2684 |
"report an error, that some read error occurred" |
612 | 2685 |
|
15845 | 2686 |
"{ Pragma: +optSpace }" |
2687 |
||
2688 |
^ ReadError newException |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2689 |
errorCode:errorNumber; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2690 |
osErrorHolder:(OperatingSystem errorHolderForNumber:errorNumber); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2691 |
parameter:self; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2692 |
raiseRequest |
612 | 2693 |
! |
2694 |
||
2695 |
writeError |
|
20259 | 2696 |
"report an error, that some write error occurred" |
15845 | 2697 |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2698 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2699 |
|
15845 | 2700 |
^ self writeError:lastErrorNumber |
2701 |
! |
|
2702 |
||
2703 |
writeError:errorNumber |
|
20259 | 2704 |
"report an error, that some write error occurred" |
612 | 2705 |
|
15845 | 2706 |
"{ Pragma: +optSpace }" |
2707 |
||
2708 |
^ WriteError newException |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2709 |
errorCode:errorNumber; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2710 |
osErrorHolder:(OperatingSystem errorHolderForNumber:errorNumber); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2711 |
parameter:self; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2712 |
raiseRequest |
612 | 2713 |
! ! |
2714 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2715 |
!ExternalStream methodsFor:'finalization'! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2716 |
|
22694 | 2717 |
beExecutor |
2718 |
"mark myself as being an executor for finalization. |
|
2719 |
We mis-use the mode symbol for this." |
|
2720 |
||
2721 |
mode := #executor. |
|
2722 |
||
2723 |
"Created: / 23-04-2018 / 18:17:01 / stefan" |
|
2724 |
! |
|
2725 |
||
15468 | 2726 |
executor |
2727 |
"return a copy for finalization-registration; |
|
2728 |
since all we need at finalization time is the fileDescriptor, |
|
2729 |
a cheaper copy is possible." |
|
2730 |
||
22694 | 2731 |
^ self class basicNew |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2732 |
beExecutor; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2733 |
setAccessor:handleType to:handle; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2734 |
yourself. |
22694 | 2735 |
|
2736 |
"Modified: / 23-04-2018 / 18:34:38 / stefan" |
|
15468 | 2737 |
! |
2738 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2739 |
finalize |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2740 |
"some Stream has been collected - close the file if not already done" |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2741 |
|
20679 | 2742 |
self closeFile |
18779 | 2743 |
! |
2744 |
||
2745 |
reRegisterForFinalization |
|
2746 |
Lobby registerChange:self. |
|
2747 |
! |
|
2748 |
||
2749 |
registerForFinalization |
|
2750 |
||
2751 |
"keep myself in newSpace, so it will be finalized early" |
|
18790 | 2752 |
Lobby size < MaxNonTenurableExecutors ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2753 |
ObjectMemory preventTenureOf:self. |
18790 | 2754 |
]. |
18779 | 2755 |
Lobby register:self. |
2756 |
! |
|
2757 |
||
2758 |
unregisterForFinalization |
|
2759 |
Lobby unregister:self. |
|
2760 |
"probably the object will be collected soon..." |
|
18793 | 2761 |
ObjectMemory allowTenureOf:self |
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2762 |
! ! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2763 |
|
15918
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
2764 |
!ExternalStream methodsFor:'initialization'! |
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
2765 |
|
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
2766 |
initialize |
15921 | 2767 |
position := 0. |
2768 |
binary := false. |
|
2769 |
buffered := true. |
|
19687 | 2770 |
self initializeEOLMode. |
2771 |
hitEOF := false. |
|
2772 |
! |
|
2773 |
||
2774 |
initializeEOLMode |
|
15921 | 2775 |
eolMode := DefaultEOLMode. |
15918
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
2776 |
! ! |
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
2777 |
|
2 | 2778 |
!ExternalStream methodsFor:'line reading/writing'! |
1 | 2779 |
|
2780 |
nextLine |
|
2781 |
"read the next line (characters up to newline). |
|
2782 |
Return a string containing those characters excluding the newline. |
|
2783 |
If the previous-to-last character is a cr, this is also removed, |
|
16508 | 2784 |
so it's possible to read alien (i.e. ms-dos) text as well. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2785 |
The line must be shorter than 32K characters - otherwise an error is signalled." |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
2786 |
|
16296 | 2787 |
|line error| |
971
eb70f5674303
max lineLength (in nextLine) increased to 16k
Claus Gittinger <cg@exept.de>
parents:
933
diff
changeset
|
2788 |
|
25136 | 2789 |
%{ /* STACK:50000 */ |
1 | 2790 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2791 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2792 |
int len, ret; |
3029
aa14768e0e6a
larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents:
3016
diff
changeset
|
2793 |
char buffer[32*1024]; |
521
70533ec40482
use new MKSTRING_L if length is known (avoids a useless strlen)
Claus Gittinger <cg@exept.de>
parents:
481
diff
changeset
|
2794 |
char *rslt, *nextPtr, *limit; |
22 | 2795 |
int fd, ch; |
1068
92fdcccf12a3
alles MIST - zurueck zu 1.89 und NOCONTEXT entfernt
Claus Gittinger <cg@exept.de>
parents:
1067
diff
changeset
|
2796 |
int _buffered; |
216 | 2797 |
OBJ fp; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
2798 |
int lineTooLong = 0; |
2920 | 2799 |
int cutOff = 0; |
1 | 2800 |
|
1133 | 2801 |
__INST(lastErrorNumber) = nil; |
12548 | 2802 |
if ((__INST(handleType) == nil) |
2803 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
2804 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2805 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 2806 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 2807 |
if (((fp = __INST(handle)) != nil) |
2808 |
&& (__INST(mode) != @symbol(writeonly)) |
|
2809 |
&& (__INST(binary) != true) |
|
2810 |
) { |
|
2811 |
f = __FILEVal(fp); |
|
2812 |
buffer[0] = '\0'; |
|
2813 |
||
2814 |
_buffered = (__INST(buffered) == true); |
|
2815 |
if (_buffered) { |
|
2816 |
__READING__(f); |
|
2817 |
} |
|
2818 |
||
2819 |
rslt = nextPtr = buffer; |
|
2820 |
limit = buffer + sizeof(buffer) - 2; |
|
2821 |
||
2822 |
for (;;) { |
|
2823 |
__READBYTE__(ret, f, nextPtr, _buffered, __INST(handleType)); |
|
2824 |
if (ret <= 0) { |
|
2825 |
if (nextPtr == buffer) |
|
2826 |
rslt = NULL; |
|
2827 |
if (ret == 0) { |
|
2828 |
__INST(hitEOF) = true; |
|
2829 |
break; |
|
2830 |
} else { |
|
23538 | 2831 |
# ifdef __win32__ |
23743 | 2832 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 2833 |
# endif |
23743 | 2834 |
error = __mkSmallInteger(__threadErrno); |
2835 |
goto err; |
|
2836 |
} |
|
2837 |
} |
|
2838 |
||
2839 |
if (*nextPtr == '\n') { |
|
2840 |
cutOff = 1; |
|
2841 |
*nextPtr = '\0'; |
|
2842 |
break; |
|
2843 |
} |
|
2844 |
if (*nextPtr == '\r') { |
|
2845 |
char peekChar; |
|
2846 |
||
2847 |
/* |
|
2848 |
* peek ahead for a newLine ... |
|
2849 |
*/ |
|
2850 |
__READBYTE__(ret, f, &peekChar, _buffered, __INST(handleType)); |
|
2851 |
if (ret <= 0) { |
|
2852 |
cutOff = 1; |
|
2853 |
*nextPtr = '\0'; |
|
2854 |
if (ret == 0) { |
|
2855 |
__INST(hitEOF) = true; |
|
2856 |
break; |
|
2857 |
} |
|
23538 | 2858 |
# ifdef __win32__ |
23743 | 2859 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 2860 |
# endif |
23743 | 2861 |
error = __mkSmallInteger(__threadErrno); |
2862 |
goto err; |
|
2863 |
} |
|
2864 |
||
2865 |
if (peekChar == '\n') { |
|
2866 |
cutOff = 2; |
|
2867 |
*nextPtr = '\0'; |
|
2868 |
break; |
|
2869 |
} |
|
2870 |
||
2871 |
__UNGETC__(peekChar, f, _buffered); |
|
2872 |
||
2873 |
cutOff = 1; |
|
2874 |
*nextPtr = '\0'; |
|
2875 |
break; |
|
2876 |
} |
|
2877 |
||
2878 |
nextPtr++; |
|
2879 |
if (nextPtr >= limit) { |
|
2880 |
*nextPtr = '\0'; |
|
2881 |
lineTooLong = 1; |
|
2882 |
break; |
|
2883 |
} |
|
2884 |
} |
|
2885 |
||
2886 |
if (rslt != NULL) { |
|
2887 |
len = nextPtr-buffer; |
|
2888 |
||
2889 |
if (__isSmallInteger(__INST(position))) { |
|
2890 |
INT np = __intVal(__INST(position)) + len + cutOff; |
|
2891 |
OBJ t; |
|
2892 |
||
2893 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
2894 |
} else { |
|
2895 |
__INST(position) = nil; /* i.e. do not know */ |
|
2896 |
} |
|
2897 |
/* remove any EOL character */ |
|
2898 |
if (len != 0) { |
|
2899 |
if (buffer[len-1] == '\n') { |
|
2900 |
buffer[--len] = '\0'; |
|
2901 |
} |
|
2902 |
if ((len != 0) && (buffer[len-1] == '\r')) { |
|
2903 |
buffer[--len] = '\0'; |
|
2904 |
} |
|
2905 |
} |
|
2906 |
line = __MKSTRING_L(buffer, len); |
|
2907 |
if (! lineTooLong) { |
|
2908 |
RETURN ( line ); |
|
2909 |
} |
|
2910 |
} |
|
2911 |
} |
|
1 | 2912 |
} |
1478
aae07192b7d1
labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
2913 |
err: ; |
159 | 2914 |
%}. |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
2915 |
line notNil ifTrue:[ |
23743 | 2916 |
"/ the line as read is longer than 32k characters (boy - what a line) |
2917 |
"/ The exception raised below can be handled to ask the user |
|
2918 |
"/ and to read more and return the concatenation from the exception handler |
|
2919 |
"/ (the receiver and the partial line are passed as parameter) |
|
2920 |
"/ If unhandled, we do exactly that: read the rest and return the concatenation |
|
2921 |
"/ i.e. the full line - whatever its size is. |
|
2922 |
||
2923 |
LineTooLongErrorSignal isHandled ifTrue:[ |
|
2924 |
^ LineTooLongErrorSignal |
|
2925 |
raiseRequestWith:(Array with:self with:line) |
|
2926 |
errorString:('line too long read error') |
|
2927 |
]. |
|
2928 |
'ExternalStream [info]: very long line in nextLine' infoPrintCR. |
|
2929 |
^ line , super nextLine "use super to avoid recursion" |
|
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
2930 |
]. |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
2931 |
|
21139 | 2932 |
hitEOF ifTrue:[^ self pastEndRead]. |
16296 | 2933 |
error notNil ifTrue:[ |
23743 | 2934 |
lastErrorNumber := error. |
2935 |
^ self readError:error |
|
16296 | 2936 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2937 |
handle isNil ifTrue:[^ self errorNotOpen]. |
1 | 2938 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
21139 | 2939 |
binary ifTrue:[^ self errorBinary]. |
5431 | 2940 |
^ super nextLine |
23538 | 2941 |
|
2942 |
"Modified: / 22-11-2018 / 14:46:40 / Stefan Vogel" |
|
1 | 2943 |
! |
2944 |
||
2945 |
nextPutLine:aString |
|
2920 | 2946 |
"write the characters in aString and append an end-of-Line marker |
2947 |
(LF, CR or CRLF - depending in the setting of eolMode)" |
|
1 | 2948 |
|
16296 | 2949 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2950 |
%{ |
7875
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
2951 |
OBJ fp; |
1 | 2952 |
|
1133 | 2953 |
__INST(lastErrorNumber) = nil; |
12548 | 2954 |
if ((__INST(handleType) == nil) |
2955 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
2956 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2957 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 2958 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 2959 |
if (((fp = __INST(handle)) != nil) |
2960 |
&& (__INST(mode) != @symbol(readonly)) |
|
2961 |
&& (__INST(binary) != true) |
|
2962 |
&& __isStringLike(aString) |
|
2963 |
) { |
|
2964 |
int _buffered = (__INST(buffered) == true); |
|
2965 |
int len = __stringSize(aString); |
|
2966 |
int cnt, len1; |
|
2967 |
FILEPOINTER f = __FILEVal(fp); |
|
2968 |
char *cp; |
|
2969 |
int o_offs; |
|
2970 |
||
2971 |
if (_buffered) { |
|
2972 |
__WRITING__(f) |
|
2973 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
2974 |
#ifdef __win32__ |
23743 | 2975 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
2976 |
cnt = __win32_fwrite(__stringVal(aString), 1, len, f); |
|
2977 |
} else |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2978 |
#endif |
23743 | 2979 |
{ |
2980 |
o_offs = (char *)__stringVal(aString)-(char *)aString; |
|
2981 |
__WRITEBYTES_OBJ__(cnt, f, aString, o_offs, len, _buffered, __INST(handleType)); |
|
2982 |
} |
|
2983 |
if (cnt == len) { |
|
2984 |
OBJ mode = __INST(eolMode); |
|
2985 |
||
2986 |
len1 = len; |
|
2987 |
||
2988 |
if (mode == @symbol(cr)) { |
|
2989 |
cp = "\r"; len = 1; |
|
2990 |
} else if (mode == @symbol(crlf)) { |
|
2991 |
cp = "\r\n"; len = 2; |
|
2992 |
} else if (mode == @symbol(eot)) { |
|
2993 |
cp = "\004"; len = 1; |
|
2994 |
} else if (mode == @symbol(etx)) { |
|
2995 |
cp = "\003"; len = 1; |
|
2996 |
} else { |
|
2997 |
cp = "\n"; len = 1; |
|
2998 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
2999 |
#ifdef __win32__ |
23743 | 3000 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
3001 |
cnt = __win32_fwrite(cp, 1, len, f); |
|
3002 |
} else |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3003 |
#endif |
23743 | 3004 |
{ |
3005 |
__WRITEBYTES__(cnt, f, cp, len, _buffered, __INST(handleType)); |
|
3006 |
} |
|
3007 |
if (cnt > 0) { |
|
3008 |
if (__isSmallInteger(__INST(position))) { |
|
3009 |
INT np = __intVal(__INST(position)) + len1 + cnt; |
|
3010 |
OBJ t; |
|
3011 |
||
3012 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
3013 |
} else { |
|
3014 |
__INST(position) = nil; /* i.e. do not know */ |
|
3015 |
} |
|
3016 |
RETURN ( self ); |
|
3017 |
} |
|
3018 |
} |
|
23538 | 3019 |
# ifdef __win32__ |
23743 | 3020 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 3021 |
# endif |
23743 | 3022 |
error = __mkSmallInteger(__threadErrno); |
3023 |
} |
|
1 | 3024 |
} |
159 | 3025 |
%}. |
16296 | 3026 |
error notNil ifTrue:[ |
23743 | 3027 |
lastErrorNumber := error. |
3028 |
self writeError:error. |
|
3029 |
^ self |
|
16296 | 3030 |
]. |
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
3031 |
super nextPutLine:aString. |
23538 | 3032 |
|
3033 |
"Modified: / 22-11-2018 / 14:48:48 / Stefan Vogel" |
|
1 | 3034 |
! |
3035 |
||
3036 |
nextPutLinesFrom:aStream upToLineStartingWith:aStringOrNil |
|
68 | 3037 |
"read from aStream up to and including a line starting with aStringOrNil |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3038 |
and append all lines to self. |
159 | 3039 |
Can be used to copy/create large files or copy from a pipe/socket. |
68 | 3040 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3041 |
If aStringOrNil is nil or not matched, copy proceeds to the end." |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3042 |
|
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3043 |
|line| |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3044 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3045 |
[aStream atEnd] whileFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3046 |
line := aStream nextLine. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3047 |
line isNil ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3048 |
^ self. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3049 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3050 |
self nextPutLine:line. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3051 |
(aStringOrNil notNil and:[line startsWith:aStringOrNil]) ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3052 |
^ self |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3053 |
] |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3054 |
]. |
1 | 3055 |
! |
3056 |
||
3057 |
peekForLineStartingWith:aString |
|
3058 |
"read ahead for next line starting with aString; |
|
159 | 3059 |
return the line-string if found, or nil if EOF is encountered. |
7118 | 3060 |
If matched, do not advance position beyond that line |
159 | 3061 |
i.e. nextLine will read the matched line. |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
3062 |
If not matched, reposition to original position for further reading." |
1 | 3063 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3064 |
|firstPos lastPos line| |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3065 |
|
1 | 3066 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3067 |
handle isNil ifTrue:[^ self errorNotOpen]. |
2 | 3068 |
binary ifTrue:[^ self errorBinary]. |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3069 |
buffered ifFalse:[^ self errorNotBuffered]. |
12 | 3070 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3071 |
firstPos := self position. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3072 |
[self atEnd] whileFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3073 |
lastPos := self position. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3074 |
line := self nextLine. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3075 |
line isNil ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3076 |
self position:firstPos. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3077 |
^ nil |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3078 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3079 |
(line startsWith:aString) ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3080 |
self position:lastPos. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3081 |
^ line |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3082 |
] |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3083 |
]. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3084 |
self position:firstPos. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3085 |
^ nil |
1 | 3086 |
! |
3087 |
||
3088 |
peekForLineStartingWithAny:aCollectionOfStrings |
|
3089 |
"read ahead for next line starting with any of aCollectionOfStrings; |
|
3090 |
return the index in aCollection if found, nil otherwise.. |
|
3091 |
If no match, do not change position; otherwise advance right before the |
|
3092 |
matched line so that nextLine will return this line." |
|
3093 |
||
3094 |
|line startPos linePos index| |
|
3095 |
||
3096 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3097 |
handle isNil ifTrue:[^ self errorNotOpen]. |
2 | 3098 |
binary ifTrue:[^ self errorBinary]. |
3099 |
||
1 | 3100 |
startPos := self position. |
3101 |
[self atEnd] whileFalse:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3102 |
linePos := self position. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3103 |
line := self nextLine. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3104 |
line notNil ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3105 |
index := 1. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3106 |
aCollectionOfStrings do:[:prefix | |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3107 |
(line startsWith:prefix) ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3108 |
self position:linePos. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3109 |
^ index |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3110 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3111 |
index := index + 1 |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3112 |
] |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3113 |
] |
1 | 3114 |
]. |
3115 |
self position:startPos. |
|
3116 |
^ nil |
|
3117 |
! ! |
|
3118 |
||
612 | 3119 |
!ExternalStream methodsFor:'misc functions'! |
3120 |
||
3121 |
async:aBoolean |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3122 |
"set/clear the async attribute - if set, the availability of data on |
612 | 3123 |
the receiver will trigger an ioInterrupt. |
779 | 3124 |
If cleared (which is the default) no special notification is made. |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3125 |
Notice: |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3126 |
not every OS supports this |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3127 |
- check with OS>>supportsIOInterrupts before using" |
92 | 3128 |
|
3129 |
|fd| |
|
3130 |
||
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3131 |
OperatingSystem supportsIOInterrupts ifFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3132 |
^ self errorUnsupportedOperation |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3133 |
]. |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3134 |
|
92 | 3135 |
fd := self fileDescriptor. |
22195 | 3136 |
"self fileDescriptor may set handle to nil" |
3137 |
handle isNil ifTrue:[^ self errorNotOpen]. |
|
3138 |
||
612 | 3139 |
aBoolean ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3140 |
^ OperatingSystem enableIOInterruptsOn:fd |
612 | 3141 |
]. |
3142 |
^ OperatingSystem disableIOInterruptsOn:fd |
|
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3143 |
|
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3144 |
"Modified: 11.1.1997 / 17:50:21 / cg" |
92 | 3145 |
! |
3146 |
||
612 | 3147 |
blocking:aBoolean |
3148 |
"set/clear the blocking attribute - if set (which is the default) |
|
3149 |
a read (using next) on the receiver will block until data is available. |
|
3150 |
If cleared, a read operation will immediately return with a value of |
|
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3151 |
nil. |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3152 |
Turning off blocking is useful when reading from PipeStreams |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3153 |
or Sockets, and the amount of data to be read is not known |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3154 |
in advance. However, the data must then be read using #nextBytes: |
8616 | 3155 |
methods, in order to avoid other (pastEndRead) exceptions." |
92 | 3156 |
|
22195 | 3157 |
|fd| |
3158 |
||
3159 |
fd := self fileDescriptor. |
|
3160 |
"self fileDescriptor may set handle to nil" |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3161 |
handle isNil ifTrue:[^ self errorNotOpen]. |
22195 | 3162 |
^ OperatingSystem setBlocking:aBoolean on:fd. |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3163 |
|
3174 | 3164 |
"Modified: / 11.1.1997 / 17:48:01 / cg" |
3165 |
"Modified: / 15.1.1998 / 11:49:48 / stefan" |
|
612 | 3166 |
! |
3167 |
||
3168 |
ioctl:ioctlNumber |
|
3169 |
"to provide a simple ioctl facility - an ioctl is performed |
|
3170 |
on the underlying file; no arguments are passed." |
|
3171 |
||
2920 | 3172 |
^ self ioctl:ioctlNumber with:nil |
3173 |
! |
|
3174 |
||
3175 |
ioctl:ioctlNumber with:arg |
|
3176 |
"to provide a simple ioctl facility - an ioctl is performed |
|
3177 |
on the underlying file; the argument is passed as argument. |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3178 |
This is not used by ST/X, but provided for special situations |
2920 | 3179 |
- for example, to control proprietrary I/O devices. |
3180 |
||
3181 |
Since the type of the argument depends on the ioctl being |
|
3182 |
performed, different arg types are allowed here. |
|
3183 |
If the argument is nil, an ioctl without argument is performed. |
|
16508 | 3184 |
If the argument is an integral number, it's directly passed; |
3185 |
if it's a kind of ByteArray (ByteArray, String or Structure), |
|
2920 | 3186 |
or external data (ExternalBytes or ExternalAddress), |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3187 |
a pointer to the data is passed. |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3188 |
This allows performing most ioctls |
2920 | 3189 |
- however, it might be tricky to setup the buffer. |
3190 |
Be careful in what you pass - ST/X cannot validate its correctness." |
|
3191 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3192 |
|error| |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3193 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3194 |
%{ |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3195 |
#if !defined(MSDOS_LIKE) && !defined(__openVMS__) |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3196 |
int fd; |
10552
d52aa8e066e5
#ioctl:with: accept 32-bit integers as arguments
Stefan Vogel <sv@exept.de>
parents:
10469
diff
changeset
|
3197 |
int ret; |
d52aa8e066e5
#ioctl:with: accept 32-bit integers as arguments
Stefan Vogel <sv@exept.de>
parents:
10469
diff
changeset
|
3198 |
unsigned int ioNum; |
2920 | 3199 |
INT ioArg; |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3200 |
OBJ fp = __INST(handle); |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3201 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3202 |
if (fp == nil) |
23743 | 3203 |
goto out; |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3204 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3205 |
if (!__isInteger(ioctlNumber) |
23743 | 3206 |
|| (!__isInteger(arg) |
3207 |
&& (arg != nil) |
|
3208 |
&& !__isBytes(arg) |
|
3209 |
&& !__isExternalBytesLike(arg) |
|
3210 |
&& !__isExternalAddress(arg))) { |
|
3211 |
error = @symbol(badArgument); |
|
3212 |
goto out; |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3213 |
} |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3214 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3215 |
if (__INST(handleType) == @symbol(socketHandle)) { |
23743 | 3216 |
fd = (int)((SOCKET)(__FILEVal(fp))); |
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3217 |
} else |
23743 | 3218 |
if ((__INST(handleType) == nil) |
3219 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3220 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
3221 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
3222 |
fd = fileno(__FILEVal(fp)); |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3223 |
} else { |
23743 | 3224 |
error = @symbol(badHandleType); |
3225 |
goto out; |
|
612 | 3226 |
} |
16508 | 3227 |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3228 |
ioNum = __unsignedLongIntVal(ioctlNumber); |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3229 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3230 |
__BEGIN_INTERRUPTABLE__ |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3231 |
do { |
23743 | 3232 |
__threadErrno = 0; |
3233 |
if (arg == nil) { |
|
3234 |
ioArg = 0; |
|
3235 |
} else if (__isSmallInteger(arg)) { |
|
3236 |
ioArg = __intVal(arg); |
|
3237 |
} else if (__isInteger(arg)) { |
|
3238 |
ioArg = __unsignedLongIntVal(arg); |
|
3239 |
} else if (__isExternalBytesLike(arg)) { |
|
3240 |
ioArg = (INT)(__externalBytesAddress(arg)); |
|
3241 |
} else if (__isExternalAddress(arg)) { |
|
3242 |
ioArg = (INT)(__externalAddressVal(arg)); |
|
3243 |
} else { |
|
3244 |
ioArg = (INT)(__ByteArrayInstPtr(arg)->ba_element); |
|
3245 |
} |
|
3246 |
ret = ioctl(fd, ioNum, ioArg); |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3247 |
} while (ret < 0 && __threadErrno == EINTR); |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3248 |
__END_INTERRUPTABLE__ |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3249 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3250 |
if (ret >= 0) { |
23743 | 3251 |
RETURN ( __mkSmallInteger(ret) ); |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3252 |
} |
23538 | 3253 |
# ifdef __win32__ |
23743 | 3254 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 3255 |
# endif |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3256 |
error = __mkSmallInteger(__threadErrno); |
791 | 3257 |
#endif |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3258 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3259 |
out:; |
612 | 3260 |
%}. |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3261 |
error notNil ifTrue:[ |
23743 | 3262 |
lastErrorNumber := error. |
3263 |
^ self ioError:error. |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3264 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3265 |
handle isNil ifTrue:[^ self errorNotOpen]. |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3266 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3267 |
"/ the system does not support ioctl (MSDOS or VMS) |
2920 | 3268 |
^ self errorUnsupportedOperation |
23538 | 3269 |
|
3270 |
"Modified: / 22-11-2018 / 14:42:04 / Stefan Vogel" |
|
612 | 3271 |
! |
3272 |
||
16551 | 3273 |
reset |
3274 |
"set the read position to the beginning of the collection" |
|
3275 |
||
3276 |
self position:0 |
|
3277 |
! |
|
3278 |
||
3279 |
setToEnd |
|
3280 |
"redefined since it must be implemented differently" |
|
3281 |
||
3282 |
^ self subclassResponsibility |
|
3283 |
! |
|
3284 |
||
3285 |
sync |
|
3286 |
"make sure, that the OS writes cached data to the disk" |
|
3287 |
||
3288 |
|error| |
|
3289 |
||
3290 |
self flush. |
|
3291 |
||
3292 |
%{ |
|
3293 |
#if !defined(__openVMS__) |
|
3294 |
int fd; |
|
3295 |
int ret; |
|
3296 |
OBJ fp = __INST(handle); |
|
3297 |
||
3298 |
if (fp == nil) |
|
23743 | 3299 |
goto out; |
16551 | 3300 |
|
3301 |
if (__INST(handleType) == @symbol(socketHandle)) { |
|
23743 | 3302 |
// syncing a socket to disk ? |
3303 |
error = @symbol(badHandleType); |
|
3304 |
goto out; |
|
3305 |
// fd = __FILEVal(fp); |
|
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3306 |
} else |
23743 | 3307 |
if ((__INST(handleType) == nil) |
3308 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3309 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
3310 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
3311 |
fd = fileno(__FILEVal(fp)); |
|
16551 | 3312 |
} else { |
23743 | 3313 |
error = @symbol(badHandleType); |
3314 |
goto out; |
|
16551 | 3315 |
} |
3316 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
3317 |
#ifdef __win32__ |
16551 | 3318 |
__threadErrno = 0; |
3319 |
ret = __STX_API_NOINT_CALL1( "FlushFileBuffers", FlushFileBuffers, _get_osfhandle(fd)); |
|
3320 |
if (ret) { |
|
23743 | 3321 |
RETURN (self); |
16551 | 3322 |
} |
23538 | 3323 |
__threadErrno = __WIN32_ERR(GetLastError()); |
16551 | 3324 |
#else |
3325 |
__BEGIN_INTERRUPTABLE__ |
|
3326 |
do { |
|
23743 | 3327 |
ret = fsync(fd); |
16551 | 3328 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
3329 |
__END_INTERRUPTABLE__ |
|
3330 |
||
3331 |
if (ret >= 0) { |
|
23743 | 3332 |
RETURN (self); |
16551 | 3333 |
} |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
3334 |
#endif /* ! __win32__ */ |
16551 | 3335 |
error = __mkSmallInteger(__threadErrno); |
3336 |
#endif /* ! __openVMS__ */ |
|
3337 |
out:; |
|
3338 |
%}. |
|
3339 |
error notNil ifTrue:[ |
|
23743 | 3340 |
lastErrorNumber := error. |
3341 |
self ioError:error. |
|
3342 |
^ self. |
|
16551 | 3343 |
]. |
3344 |
handle isNil ifTrue:[self errorNotOpen]. |
|
3345 |
||
3346 |
" |
|
23743 | 3347 |
|f| |
3348 |
f := 'x' asFilename writeStream. |
|
3349 |
f nextPutAll:'hallo'; sync; syncData; close |
|
16551 | 3350 |
" |
23538 | 3351 |
|
3352 |
"Modified: / 22-11-2018 / 14:51:43 / Stefan Vogel" |
|
16551 | 3353 |
! |
3354 |
||
3355 |
syncData |
|
3356 |
"make sure, that the OS writes cached data to the disk. |
|
3357 |
In this case, metadata is only written, if it is |
|
3358 |
required to read the file's data (so metadata will not be written, |
|
3359 |
if only access/modification time has changed)." |
|
3360 |
|error| |
|
3361 |
||
3362 |
self flush. |
|
3363 |
||
3364 |
%{ |
|
3365 |
#if !defined(__openVMS__) |
|
3366 |
int fd; |
|
3367 |
int ret; |
|
3368 |
OBJ fp = __INST(handle); |
|
3369 |
||
3370 |
if (fp == nil) |
|
23743 | 3371 |
goto out; |
16551 | 3372 |
|
3373 |
if (__INST(handleType) == @symbol(socketHandle)) { |
|
23743 | 3374 |
// syncing a socket to disk ? |
3375 |
error = @symbol(badHandleType); |
|
3376 |
goto out; |
|
3377 |
// fd = __FILEVal(fp); |
|
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3378 |
} else |
23743 | 3379 |
if ((__INST(handleType) == nil) |
3380 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3381 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
3382 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
3383 |
fd = fileno(__FILEVal(fp)); |
|
16551 | 3384 |
} else { |
23743 | 3385 |
error = @symbol(badHandleType); |
3386 |
goto out; |
|
16551 | 3387 |
} |
3388 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
3389 |
#ifdef __win32__ |
16551 | 3390 |
__threadErrno = 0; |
3391 |
ret = __STX_API_NOINT_CALL1( "FlushFileBuffers", FlushFileBuffers, _get_osfhandle(fd)); |
|
3392 |
if (ret) { |
|
23743 | 3393 |
RETURN (self); |
16551 | 3394 |
} |
23538 | 3395 |
__threadErrno = __WIN32_ERR(GetLastError()); |
16551 | 3396 |
#else |
3397 |
__BEGIN_INTERRUPTABLE__ |
|
3398 |
do { |
|
23743 | 3399 |
ret = fdatasync(fd); |
16551 | 3400 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
3401 |
__END_INTERRUPTABLE__ |
|
3402 |
||
3403 |
if (ret >= 0) { |
|
23743 | 3404 |
RETURN (self); |
16551 | 3405 |
} |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
3406 |
#endif /* ! __win32__ */ |
16551 | 3407 |
error = __mkSmallInteger(__threadErrno); |
3408 |
#endif /* ! __openVMS__ */ |
|
3409 |
out:; |
|
3410 |
%}. |
|
3411 |
||
3412 |
error notNil ifTrue:[ |
|
23743 | 3413 |
lastErrorNumber := error. |
3414 |
self ioError:error. |
|
3415 |
^ self. |
|
16551 | 3416 |
]. |
3417 |
handle isNil ifTrue:[^ self errorNotOpen]. |
|
3418 |
||
3419 |
"if notdef HAS_DATASYNC, fall back" |
|
3420 |
self sync. |
|
3421 |
||
3422 |
" |
|
23743 | 3423 |
|f| |
3424 |
f := 'x' asFilename writeStream. |
|
3425 |
f nextPutAll:'hallo'; sync; syncData; close |
|
16551 | 3426 |
" |
23538 | 3427 |
|
3428 |
"Modified: / 22-11-2018 / 14:51:31 / Stefan Vogel" |
|
16551 | 3429 |
! |
3430 |
||
16508 | 3431 |
tcgetattr |
3432 |
"unix only: |
|
3433 |
provide the information of a tcgetattr call as a dictionary. |
|
3434 |
This provides terminal setting values of a tty or pty. |
|
3435 |
Used by terminal emulators. |
|
3436 |
On non-unix systems, an unsupported operation error is raised" |
|
3437 |
||
3438 |
|error ret |
|
3439 |
iflags "/ input flags |
|
3440 |
ignbrk brkint ignpar parmrk inpck istrip inlcr igncr |
|
16509
2cf139885242
Fixed ExternalStream>>tcgetattr
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16508
diff
changeset
|
3441 |
icrnl iuclc ixon ixoff ixany imaxbel iutf8 |
16508 | 3442 |
oflags "/ output flags |
3443 |
opost onlcr ocrnl olcuc onocr onlret oxtabs onoteot |
|
3444 |
cflags "/ control flags |
|
3445 |
csize cstopb cread parenb parodd hupcl clocal |
|
3446 |
lflags "/ local flags |
|
3447 |
echoke echoe echok echo echonl echoprt echoctl |
|
3448 |
isig icanon altwerase iexten extproc tostop |
|
3449 |
| |
|
3450 |
||
3451 |
%{ |
|
3452 |
#if !defined(MSDOS_LIKE) && !defined(__openVMS__) |
|
3453 |
int fd; |
|
3454 |
int _ret; |
|
3455 |
OBJ fp = __INST(handle); |
|
3456 |
struct termios t; |
|
3457 |
int sz; |
|
3458 |
||
3459 |
if (fp == nil) |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3460 |
goto out; |
16508 | 3461 |
|
3462 |
if (__INST(handleType) == @symbol(socketHandle)) { |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3463 |
// cg: termina attributes of a socket? |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3464 |
error = @symbol(badHandleType); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3465 |
goto out; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3466 |
// fd = __FILEVal(fp); |
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3467 |
} else |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3468 |
if ((__INST(handleType) == nil) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3469 |
|| (__INST(handleType) == @symbol(filePointer)) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3470 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3471 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3472 |
fd = fileno(__FILEVal(fp)); |
16508 | 3473 |
} else { |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3474 |
error = @symbol(badHandleType); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3475 |
goto out; |
16508 | 3476 |
} |
3477 |
||
3478 |
__BEGIN_INTERRUPTABLE__ |
|
3479 |
do { |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3480 |
__threadErrno = 0; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3481 |
_ret = tcgetattr(fd, &t); |
16508 | 3482 |
} while (_ret < 0 && __threadErrno == EINTR); |
3483 |
__END_INTERRUPTABLE__ |
|
3484 |
||
3485 |
if (_ret < 0) { |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3486 |
error = __mkSmallInteger(__threadErrno); |
16508 | 3487 |
} |
3488 |
ignbrk = t.c_iflag & IGNBRK ? true : false; |
|
3489 |
brkint = t.c_iflag & BRKINT ? true : false; |
|
3490 |
ignpar = t.c_iflag & IGNPAR ? true : false; |
|
3491 |
parmrk = t.c_iflag & PARMRK ? true : false; |
|
3492 |
inpck = t.c_iflag & INPCK ? true : false; |
|
3493 |
istrip = t.c_iflag & ISTRIP ? true : false; |
|
3494 |
inlcr = t.c_iflag & INLCR ? true : false; |
|
3495 |
ixon = t.c_iflag & IXON ? true : false; |
|
3496 |
ixoff = t.c_iflag & IXOFF ? true : false; |
|
3497 |
ixany = t.c_iflag & IXANY ? true : false; |
|
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3498 |
# ifdef IMAXBEL |
16508 | 3499 |
imaxbel = t.c_iflag & IMAXBEL ? true : false; |
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3500 |
# endif |
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3501 |
# ifdef IUCLC |
16508 | 3502 |
iuclc = t.c_iflag & IUCLC ? true : false; |
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3503 |
# endif |
16508 | 3504 |
|
3505 |
opost = t.c_oflag & OPOST ? true : false; |
|
3506 |
onlcr = t.c_oflag & ONLCR ? true : false; |
|
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3507 |
# ifdef OXTABS |
16508 | 3508 |
oxtabs = t.c_oflag & OXTABS ? true : false; |
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3509 |
# endif |
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3510 |
# ifdef ONOTEOT |
16508 | 3511 |
onoteot = t.c_oflag & ONOTEOT ? true : false; |
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3512 |
# endif |
16508 | 3513 |
ocrnl = t.c_oflag & OCRNL ? true : false; |
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3514 |
# ifdef OLCUC |
16508 | 3515 |
olcuc = t.c_oflag & OLCUC ? true : false; |
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3516 |
# endif |
16508 | 3517 |
onocr = t.c_oflag & ONOCR ? true : false; |
3518 |
onlret = t.c_oflag & ONLRET ? true : false; |
|
3519 |
||
3520 |
sz = t.c_cflag & CSIZE; |
|
3521 |
switch (sz) { |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3522 |
case CS5: |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3523 |
csize = @symbol(cs5); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3524 |
break; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3525 |
case CS6: |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3526 |
csize = @symbol(cs6); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3527 |
break; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3528 |
case CS7: |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3529 |
csize = @symbol(cs7); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3530 |
break; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3531 |
case CS8: |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3532 |
csize = @symbol(cs8); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3533 |
break; |
16508 | 3534 |
} |
3535 |
cstopb = t.c_cflag & CSTOPB ? true : false; |
|
3536 |
cread = t.c_cflag & CREAD ? true : false; |
|
3537 |
parenb = t.c_cflag & PARENB ? true : false; |
|
3538 |
parodd = t.c_cflag & PARODD ? true : false; |
|
3539 |
hupcl = t.c_cflag & HUPCL ? true : false; |
|
3540 |
clocal = t.c_cflag & CLOCAL ? true : false; |
|
3541 |
||
3542 |
echoke = t.c_lflag & ECHOKE ? true : false; |
|
3543 |
echoe = t.c_lflag & ECHOE ? true : false; |
|
3544 |
echo = t.c_lflag & ECHO ? true : false; |
|
3545 |
echonl = t.c_lflag & ECHONL ? true : false; |
|
3546 |
echoctl = t.c_lflag & ECHOCTL ? true : false; |
|
3547 |
isig = t.c_lflag & ISIG ? true : false; |
|
3548 |
icanon = t.c_lflag & ICANON ? true : false; |
|
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3549 |
# ifdef ALTWERASE |
16508 | 3550 |
altwerase = t.c_lflag & ALTWERASE ? true : false; |
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3551 |
# endif |
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3552 |
# ifdef IEXTEN |
16508 | 3553 |
iexten = t.c_lflag & IEXTEN ? true : false; |
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3554 |
# endif |
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3555 |
# ifdef EXTPROC |
16508 | 3556 |
extproc = t.c_lflag & EXTPROC ? true : false; |
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3557 |
# endif |
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3558 |
# ifdef TOSTOP |
16508 | 3559 |
tostop = t.c_lflag & TOSTOP ? true : false; |
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3560 |
# endif |
16508 | 3561 |
|
3562 |
#else |
|
3563 |
error = @symbol(unsupportedOperation); |
|
3564 |
#endif |
|
3565 |
||
3566 |
out:; |
|
3567 |
%}. |
|
3568 |
error notNil ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3569 |
error == #unsupportedOperation ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3570 |
"/ the system does not support tcgetattr |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3571 |
^ self errorUnsupportedOperation |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3572 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3573 |
lastErrorNumber := error. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3574 |
^ self ioError:error. |
16508 | 3575 |
]. |
3576 |
handle isNil ifTrue:[^ self errorNotOpen]. |
|
3577 |
||
3578 |
"/ construct a dictionary... |
|
3579 |
ret := Dictionary new. |
|
3580 |
ret at:#iflags put:(iflags := Dictionary new). |
|
3581 |
ret at:#oflags put:(oflags := Dictionary new). |
|
3582 |
ret at:#cflags put:(cflags := Dictionary new). |
|
3583 |
ret at:#lflags put:(lflags := Dictionary new). |
|
3584 |
iflags at:#ignbrk put:ignbrk. |
|
3585 |
iflags at:#brkint put:brkint. |
|
3586 |
iflags at:#ignpar put:ignpar. |
|
3587 |
iflags at:#parmrk put:parmrk. |
|
3588 |
iflags at:#inpck put:inpck. |
|
3589 |
iflags at:#istrip put:istrip. |
|
3590 |
iflags at:#inlcr put:inlcr. |
|
3591 |
iflags at:#igncr put:igncr. |
|
3592 |
iflags at:#icrnl put:icrnl. |
|
16509
2cf139885242
Fixed ExternalStream>>tcgetattr
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16508
diff
changeset
|
3593 |
iflags at:#uiclc put:iuclc. |
16508 | 3594 |
iflags at:#ixon put:ixon. |
3595 |
iflags at:#ixoff put:ixoff. |
|
3596 |
iflags at:#ixany put:ixany. |
|
3597 |
iflags at:#imaxbel put:imaxbel. |
|
3598 |
iflags at:#iutf8 put:iutf8. |
|
3599 |
||
3600 |
oflags at:#opost put:opost. |
|
3601 |
oflags at:#onlcr put:onlcr. |
|
3602 |
oflags at:#oxtabs put:oxtabs. |
|
3603 |
oflags at:#onoteot put:onoteot. |
|
3604 |
||
3605 |
cflags at:#csize put:csize. |
|
3606 |
cflags at:#cstopb put:cstopb. |
|
3607 |
cflags at:#cread put:cread. |
|
3608 |
cflags at:#parenb put:parenb. |
|
3609 |
cflags at:#parodd put:parodd. |
|
3610 |
cflags at:#hupcl put:hupcl. |
|
3611 |
cflags at:#clocal put:clocal. |
|
3612 |
||
3613 |
lflags at:#echoke put:echoke. |
|
3614 |
lflags at:#echoe put:echoe. |
|
3615 |
lflags at:#echok put:echok. |
|
3616 |
lflags at:#echo put:echo. |
|
3617 |
lflags at:#echonl put:echonl. |
|
3618 |
lflags at:#echoprt put:echoprt. |
|
3619 |
lflags at:#echoctl put:echoctl. |
|
3620 |
lflags at:#isig put:isig. |
|
3621 |
lflags at:#icanon put:icanon. |
|
3622 |
lflags at:#altwerase put:altwerase. |
|
3623 |
lflags at:#iexten put:iexten. |
|
3624 |
lflags at:#extproc put:extproc. |
|
3625 |
lflags at:#tostop put:tostop. |
|
3626 |
^ ret |
|
612 | 3627 |
! ! |
3628 |
||
3629 |
!ExternalStream methodsFor:'non homogenous reading'! |
|
3630 |
||
17609 | 3631 |
next:count into:aCollection startingAt:start |
20092 | 3632 |
"return the next count bytes or characters from the stream." |
3633 |
||
17609 | 3634 |
|readCount| |
3635 |
||
3636 |
readCount := self nextBytes:count into:aCollection startingAt:start. |
|
3637 |
readCount = count ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3638 |
^ aCollection. |
17609 | 3639 |
]. |
3640 |
^ aCollection copyFrom:1 to:start+readCount-1. |
|
15254 | 3641 |
! |
3642 |
||
3674 | 3643 |
nextAvailable:count |
3644 |
"return the next count elements of the stream as aCollection. |
|
3645 |
If the stream reaches the end before count elements have been read, |
|
3646 |
return what is available. (i.e. a shorter collection). |
|
3647 |
The type of collection is specified in #contentsSpecies." |
|
3648 |
||
3956
51f1a9a4d63f
changes for egcs (stdio uses __new / utsname)
Claus Gittinger <cg@exept.de>
parents:
3949
diff
changeset
|
3649 |
|buffer n| |
3674 | 3650 |
|
20092 | 3651 |
buffer := self contentsSpecies uninitializedNew:count. |
3674 | 3652 |
n := self nextAvailableBytes:count into:buffer startingAt:1. |
5202
e8130049b18f
#nextAvailableBytes:into:startingAt: may NOT set EOF flag,
Claus Gittinger <cg@exept.de>
parents:
5187
diff
changeset
|
3653 |
n == 0 ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3654 |
binary ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3655 |
^ #[] |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3656 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3657 |
^ '' |
5202
e8130049b18f
#nextAvailableBytes:into:startingAt: may NOT set EOF flag,
Claus Gittinger <cg@exept.de>
parents:
5187
diff
changeset
|
3658 |
]. |
3674 | 3659 |
|
3660 |
n ~~ count ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3661 |
^ buffer copyTo:n |
3674 | 3662 |
]. |
3663 |
^ buffer. |
|
3664 |
||
3665 |
" |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3666 |
(ReadStream on:#(1 2 3 4 5)) nextAvailable:3 |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3667 |
(ReadStream on:#(1 2 3 4 5)) nextAvailable:10 |
3674 | 3668 |
(ReadStream on:'hello') nextAvailable:3 |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3669 |
(ReadStream on:'hello') nextAvailable:10 |
3674 | 3670 |
" |
3671 |
||
3672 |
"Modified: / 16.6.1998 / 15:52:41 / cg" |
|
3673 |
! |
|
3674 |
||
17608 | 3675 |
nextAvailable:count into:aCollection startingAt:pos |
3676 |
"return the next count elements of the stream into aCollection at position pos." |
|
3677 |
||
3678 |
^ self nextAvailableBytes:count into:aCollection startingAt:pos. |
|
3679 |
! |
|
3680 |
||
24507 | 3681 |
nextAvailableBytes:count |
3682 |
"return the next count bytes of the stream as a byteArray. |
|
3683 |
If the stream reaches the end before count bytes have been read, |
|
3684 |
return what is available. (i.e. a shorter byteArray)." |
|
3685 |
||
3686 |
|buffer n| |
|
3687 |
||
3688 |
buffer := ByteArray uninitializedNew:count. |
|
3689 |
n := self nextAvailableBytes:count into:buffer startingAt:1. |
|
3690 |
n == 0 ifTrue:[ |
|
25136 | 3691 |
^ #[] |
24507 | 3692 |
]. |
3693 |
||
3694 |
n ~~ count ifTrue:[ |
|
25136 | 3695 |
^ buffer copyTo:n |
24507 | 3696 |
]. |
3697 |
^ buffer. |
|
3698 |
||
3699 |
" |
|
3700 |
(ReadStream on:#(1 2 3 4 5)) nextAvailable:3 |
|
3701 |
(ReadStream on:#(1 2 3 4 5)) nextAvailable:10 |
|
3702 |
(ReadStream on:'hello') nextAvailable:3 |
|
3703 |
(ReadStream on:'hello') nextAvailable:10 |
|
3704 |
" |
|
3705 |
||
3706 |
"Modified: / 16.6.1998 / 15:52:41 / cg" |
|
3707 |
! |
|
3708 |
||
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3709 |
nextAvailableBytes:count into:anObject startingAt:start |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3710 |
"read the next count bytes into an object and return the number of |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3711 |
bytes read or the number of bytes read, if EOF is encountered before, |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3712 |
or no more bytes are available for reading (from the pipe/socket). |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3713 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3714 |
If the receiver is some socket/pipe-like stream, an exception |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3715 |
is raised if the connection is broken. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3716 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3717 |
Notice, that in contrast to other methods, |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3718 |
this does NOT return nil on EOF, but the actual count. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3719 |
Thus allowing read of partial blocks. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3720 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3721 |
The object must have non-pointer indexed instvars |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3722 |
(i.e. it must be a ByteArray, String, Float- or DoubleArray). |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3723 |
If anObject is a string or byteArray and reused, this provides the |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3724 |
fastest possible physical I/O (since no new objects are allocated). |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3725 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3726 |
Use with care - non object oriented I/O. |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3727 |
Warning: in general, you cannot use this method to pass data from other |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3728 |
architectures since it does not care for byte order or float representation." |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3729 |
|
16296 | 3730 |
|error| |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3731 |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3732 |
%{ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3733 |
FILEPOINTER f; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3734 |
int cnt, offs, ret, _buffered; |
15987 | 3735 |
int objSize, nInstBytes; |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3736 |
char *cp; |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3737 |
char *extPtr; |
7195
755c46f9b774
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
7118
diff
changeset
|
3738 |
OBJ fp; |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3739 |
int o_offs; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3740 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3741 |
__INST(lastErrorNumber) = nil; |
12548 | 3742 |
if ((__INST(handleType) == nil) |
3743 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3744 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3745 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 3746 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
25136 | 3747 |
if (((fp = __INST(handle)) != nil) |
3748 |
&& (__INST(mode) != @symbol(writeonly)) |
|
3749 |
&& __bothSmallInteger(count, start) |
|
3750 |
) { |
|
3751 |
f = __FILEVal(fp); |
|
3752 |
||
3753 |
cnt = __intVal(count); |
|
3754 |
offs = __intVal(start) - 1; |
|
3755 |
||
3756 |
if (__isExternalBytesLike(anObject)) { |
|
3757 |
OBJ sz; |
|
3758 |
||
3759 |
nInstBytes = 0; |
|
3760 |
extPtr = (char *)(__externalBytesAddress(anObject)); |
|
3761 |
if (extPtr == NULL) goto bad; |
|
3762 |
sz = __externalBytesSize(anObject); |
|
3763 |
if (__isSmallInteger(sz)) { |
|
3764 |
objSize = __intVal(sz); |
|
3765 |
} else { |
|
3766 |
objSize = 0; /* unknown */ |
|
3767 |
} |
|
3768 |
} else { |
|
3769 |
OBJ oClass = __Class(anObject); |
|
3770 |
int nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
3771 |
||
3772 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
3773 |
||
3774 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
|
3775 |
case BYTEARRAY: |
|
3776 |
case WORDARRAY: |
|
3777 |
case LONGARRAY: |
|
3778 |
case SWORDARRAY: |
|
3779 |
case SLONGARRAY: |
|
3780 |
case FLOATARRAY: |
|
3781 |
break; |
|
3782 |
case DOUBLEARRAY: |
|
15987 | 3783 |
#ifdef __NEED_DOUBLE_ALIGN |
25136 | 3784 |
nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1); |
15987 | 3785 |
#endif |
25136 | 3786 |
break; |
3787 |
case LONGLONGARRAY: |
|
3788 |
case SLONGLONGARRAY: |
|
16296 | 3789 |
#ifdef __NEED_LONGLONG_ALIGN |
25136 | 3790 |
nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1); |
5202
e8130049b18f
#nextAvailableBytes:into:startingAt: may NOT set EOF flag,
Claus Gittinger <cg@exept.de>
parents:
5187
diff
changeset
|
3791 |
#endif |
25136 | 3792 |
break; |
3793 |
default: |
|
3794 |
goto bad; |
|
3795 |
} |
|
3796 |
extPtr = (char *)0; |
|
3797 |
objSize = __Size(anObject) - nInstBytes; |
|
3798 |
} |
|
3799 |
||
3800 |
if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) { |
|
3801 |
_buffered = (__INST(buffered) == true); |
|
3802 |
if (_buffered) { |
|
3803 |
__READING__(f); |
|
3804 |
} |
|
3805 |
||
3806 |
if (extPtr) { |
|
3807 |
__READAVAILBYTES__(ret, f, extPtr+offs, cnt, _buffered, __INST(handleType)); |
|
3808 |
} else { |
|
3809 |
/* |
|
3810 |
* on interrupt, anObject may be moved to another location. |
|
3811 |
* So we pass (char *)__InstPtr(anObject) + nInstBytes + offs to the macro __READ_BYTES__, |
|
3812 |
* to get a new address. |
|
3813 |
*/ |
|
3814 |
offs += nInstBytes; |
|
3815 |
__READAVAILBYTES_OBJ__(ret, f, anObject, offs, cnt, _buffered, __INST(handleType)); |
|
3816 |
} |
|
3817 |
/* 0 is NOT an EOF condition here ... */ |
|
3818 |
if (ret >= 0) { |
|
3819 |
if (__isSmallInteger(__INST(position))) { |
|
3820 |
INT np = __intVal(__INST(position)) + ret; |
|
3821 |
OBJ t; |
|
3822 |
||
3823 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
3824 |
} else { |
|
3825 |
__INST(position) = nil; /* i.e. do not know */ |
|
3826 |
} |
|
3827 |
RETURN (__mkSmallInteger(ret)); |
|
3828 |
} |
|
3829 |
__INST(position) = nil; |
|
23538 | 3830 |
# ifdef __win32__ |
25136 | 3831 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 3832 |
# endif |
25136 | 3833 |
error = __mkSmallInteger(__threadErrno); |
3834 |
} |
|
3835 |
} |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3836 |
} |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3837 |
bad: ; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3838 |
%}. |
20092 | 3839 |
hitEOF ifTrue:[^ 0]. |
16296 | 3840 |
error notNil ifTrue:[ |
25136 | 3841 |
lastErrorNumber := error. |
3842 |
^ self readError:error |
|
16296 | 3843 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3844 |
handle isNil ifTrue:[^ self errorNotOpen]. |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3845 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3846 |
" |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3847 |
count not integer or arg not bit-like (String, ByteArray etc) |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3848 |
" |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3849 |
^ self primitiveFailed |
23538 | 3850 |
|
23897 | 3851 |
"Modified: / 13-03-2019 / 17:07:07 / Stefan Vogel" |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3852 |
! |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3853 |
|
612 | 3854 |
nextByte |
3855 |
"read the next byte and return it as an Integer; return nil on error. |
|
3856 |
This is allowed in both text and binary modes, always returning the |
|
3857 |
bytes binary value as an integer in 0..255." |
|
3858 |
||
16296 | 3859 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3860 |
%{ |
18364 | 3861 |
#ifdef __SCHTEAM__ |
3862 |
STObject handle = self.instVarAt(I_handle); |
|
3863 |
||
3864 |
if (handle != STObject.Nil) { |
|
23743 | 3865 |
STObject next; |
3866 |
||
3867 |
next = handle.nextByte(); |
|
3868 |
if (next != STObject.EOF) { |
|
3869 |
self.instVarAt_put(I_position, STObject.Nil); |
|
3870 |
return __c__._RETURN( next ); |
|
3871 |
} |
|
3872 |
self.instVarAt_put(I_hitEOF, STObject.True); |
|
18364 | 3873 |
} |
3874 |
#else |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3875 |
FILEPOINTER f; |
612 | 3876 |
unsigned char byte; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3877 |
int ret, _buffered; |
612 | 3878 |
OBJ fp; |
3879 |
||
1133 | 3880 |
__INST(lastErrorNumber) = nil; |
12548 | 3881 |
if ((__INST(handleType) == nil) |
3882 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3883 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3884 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 3885 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 3886 |
if (((fp = __INST(handle)) != nil) |
3887 |
&& (__INST(mode) != @symbol(writeonly))) { |
|
3888 |
f = __FILEVal(fp); |
|
3889 |
||
3890 |
_buffered = (__INST(buffered) == true); |
|
3891 |
if (_buffered) { |
|
3892 |
__READING__(f) |
|
3893 |
} |
|
3894 |
__READBYTE__(ret, f, &byte, _buffered, __INST(handleType)); |
|
3895 |
if (ret > 0) { |
|
3896 |
if (__isSmallInteger(__INST(position))) { |
|
3897 |
INT np = __intVal(__INST(position)) + 1; |
|
3898 |
OBJ t; |
|
3899 |
||
3900 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
3901 |
} else { |
|
3902 |
__INST(position) = nil; /* i.e. do not know */ |
|
3903 |
} |
|
3904 |
RETURN (__mkSmallInteger(byte)); |
|
3905 |
} |
|
3906 |
||
3907 |
if (ret == 0) { |
|
3908 |
__INST(hitEOF) = true; |
|
3909 |
} else /* ret < 0 */ { |
|
3910 |
__INST(position) = nil; |
|
23538 | 3911 |
# ifdef __win32__ |
23743 | 3912 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 3913 |
# endif |
23743 | 3914 |
error = __mkSmallInteger(__threadErrno); |
3915 |
} |
|
3916 |
} |
|
612 | 3917 |
} |
18364 | 3918 |
#endif /* not SCHTEAM */ |
612 | 3919 |
%}. |
8614 | 3920 |
hitEOF ifTrue:[^ self pastEndRead]. |
16296 | 3921 |
error notNil ifTrue:[ |
23743 | 3922 |
lastErrorNumber := error. |
3923 |
^ self readError:error |
|
16296 | 3924 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3925 |
handle isNil ifTrue:[^ self errorNotOpen]. |
612 | 3926 |
^ self errorWriteOnly |
23538 | 3927 |
|
3928 |
"Modified: / 22-11-2018 / 14:45:15 / Stefan Vogel" |
|
612 | 3929 |
! |
3930 |
||
3931 |
nextBytes:count into:anObject startingAt:start |
|
3932 |
"read the next count bytes into an object and return the number of |
|
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3933 |
bytes read or the number of bytes read, if EOF is encountered before. |
612 | 3934 |
If the receiver is some socket/pipe-like stream, an exception |
3935 |
is raised if the connection is broken. |
|
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3936 |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3937 |
Warning: if used with a pipe/socket, this blocks until the requested number |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3938 |
of bytes have been read. See #nextAvailableBytes:into:startingAt: |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3939 |
to only read whats there. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3940 |
|
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3941 |
Notice, that in contrast to other methods, |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3942 |
this does NOT return nil on EOF, but the actual count. |
612 | 3943 |
Thus allowing read of partial blocks. |
3944 |
||
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3945 |
The object must have non-pointer indexed instvars |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3946 |
(i.e. it must be a ByteArray, String, Float- or DoubleArray), |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3947 |
or an externalBytes object (with known size). |
612 | 3948 |
If anObject is a string or byteArray and reused, this provides the |
3949 |
fastest possible physical I/O (since no new objects are allocated). |
|
3950 |
||
3951 |
Use with care - non object oriented I/O. |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3952 |
Warning: in general, you cannot use this method to pass data from other |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3953 |
architectures (unless you prepared the buffer with care), |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3954 |
since it does not care for byte order or float representation." |
612 | 3955 |
|
16296 | 3956 |
|error| |
612 | 3957 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3958 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3959 |
int cnt, offs, ret, _buffered; |
15987 | 3960 |
int objSize, nInstBytes; |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3961 |
char *extPtr; |
7195
755c46f9b774
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
7118
diff
changeset
|
3962 |
OBJ fp; |
612 | 3963 |
|
1133 | 3964 |
__INST(lastErrorNumber) = nil; |
12548 | 3965 |
if ((__INST(handleType) == nil) |
3966 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3967 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3968 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 3969 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 3970 |
if (((fp = __INST(handle)) != nil) |
3971 |
&& (__INST(mode) != @symbol(writeonly)) |
|
3972 |
&& __bothSmallInteger(count, start) |
|
3973 |
) { |
|
3974 |
f = __FILEVal(fp); |
|
3975 |
||
3976 |
cnt = __intVal(count); |
|
3977 |
offs = __intVal(start) - 1; |
|
3978 |
||
3979 |
if (__isExternalBytesLike(anObject)) { |
|
3980 |
OBJ sz; |
|
3981 |
||
3982 |
nInstBytes = 0; |
|
3983 |
extPtr = (char *)(__externalBytesAddress(anObject)); |
|
3984 |
if (extPtr == NULL) goto bad; |
|
3985 |
sz = __externalBytesSize(anObject); |
|
3986 |
if (__isSmallInteger(sz)) { |
|
3987 |
objSize = __intVal(sz); |
|
3988 |
} else { |
|
3989 |
objSize = 0; /* unknown */ |
|
3990 |
} |
|
3991 |
} else { |
|
3992 |
OBJ oClass = __Class(anObject); |
|
3993 |
int nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
3994 |
||
3995 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
3996 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
|
3997 |
case BYTEARRAY: |
|
3998 |
case WORDARRAY: |
|
3999 |
case LONGARRAY: |
|
4000 |
case SWORDARRAY: |
|
4001 |
case SLONGARRAY: |
|
4002 |
case FLOATARRAY: |
|
4003 |
break; |
|
4004 |
case DOUBLEARRAY: |
|
15987 | 4005 |
#ifdef __NEED_DOUBLE_ALIGN |
23743 | 4006 |
nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1); |
15987 | 4007 |
#endif |
23743 | 4008 |
break; |
4009 |
case LONGLONGARRAY: |
|
4010 |
case SLONGLONGARRAY: |
|
16296 | 4011 |
#ifdef __NEED_LONGLONG_ALIGN |
23743 | 4012 |
nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1); |
16296 | 4013 |
#endif |
23743 | 4014 |
break; |
4015 |
default: |
|
4016 |
goto bad; |
|
4017 |
} |
|
4018 |
extPtr = (char *)0; |
|
4019 |
objSize = __Size(anObject) - nInstBytes; |
|
4020 |
} |
|
4021 |
if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) { |
|
4022 |
_buffered = (__INST(buffered) == true); |
|
4023 |
if (_buffered) { |
|
4024 |
__READING__(f); |
|
4025 |
} |
|
4026 |
||
4027 |
if (extPtr) { |
|
4028 |
__READBYTES__(ret, f, extPtr+offs, cnt, _buffered, __INST(handleType)); |
|
4029 |
} else { |
|
4030 |
/* |
|
4031 |
* on interrupt, anObject may be moved to another location. |
|
4032 |
* So we pass anObject, and the offset to the __READBYTES_OBJ__ macro. |
|
4033 |
*/ |
|
4034 |
offs += nInstBytes; |
|
4035 |
__READBYTES_OBJ__(ret, f, anObject, offs, cnt, _buffered, __INST(handleType)); |
|
4036 |
} |
|
4037 |
||
4038 |
if (ret > 0) { |
|
4039 |
if (__isSmallInteger(__INST(position))) { |
|
4040 |
INT np = __intVal(__INST(position)) + ret; |
|
4041 |
OBJ t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4042 |
} else { |
|
4043 |
__INST(position) = nil; /* i.e. do not know */ |
|
4044 |
} |
|
4045 |
RETURN (__mkSmallInteger(ret)); |
|
4046 |
} |
|
4047 |
if (ret == 0) { |
|
4048 |
__INST(hitEOF) = true; |
|
4049 |
} else /* ret < 0 */ { |
|
4050 |
__INST(position) = nil; |
|
23538 | 4051 |
# ifdef __win32__ |
23743 | 4052 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4053 |
# endif |
23743 | 4054 |
error = __mkSmallInteger(__threadErrno); |
4055 |
} |
|
4056 |
} |
|
4057 |
} |
|
612 | 4058 |
} |
4059 |
bad: ; |
|
4060 |
%}. |
|
20092 | 4061 |
hitEOF ifTrue:[^ 0]. |
16296 | 4062 |
error notNil ifTrue:[ |
23743 | 4063 |
lastErrorNumber := error. |
4064 |
^ self readError:error |
|
16296 | 4065 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4066 |
handle isNil ifTrue:[^ self errorNotOpen]. |
612 | 4067 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
4068 |
" |
|
4069 |
count not integer or arg not bit-like (String, ByteArray etc) |
|
4070 |
" |
|
4071 |
^ self primitiveFailed |
|
23538 | 4072 |
|
4073 |
"Modified: / 22-11-2018 / 14:45:28 / Stefan Vogel" |
|
92 | 4074 |
! |
4075 |
||
19219 | 4076 |
nextInt16MSB:msbFlag |
4077 |
"Read two bytes and return the value as a 16-bit signed Integer. |
|
4078 |
If msbFlag is true, value is read with most-significant byte first, |
|
4079 |
otherwise least-significant byte comes first. |
|
4080 |
A nil is returned if EOF is reached (also when EOF is hit after the first byte). |
|
4081 |
Works in both binary and text modes." |
|
4082 |
||
4083 |
|error| |
|
4084 |
%{ |
|
4085 |
OBJ fp; |
|
4086 |
||
4087 |
__INST(lastErrorNumber) = nil; |
|
4088 |
if ((__INST(handleType) == nil) |
|
4089 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4090 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
4091 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
4092 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
23743 | 4093 |
if (((fp = __INST(handle)) != nil) |
4094 |
&& (__INST(mode) != @symbol(writeonly)) |
|
4095 |
) { |
|
4096 |
FILEPOINTER f; |
|
4097 |
int ret, _buffered; |
|
4098 |
short value; |
|
4099 |
union { |
|
4100 |
unsigned char buffer[2]; |
|
4101 |
short shortVal; |
|
4102 |
} u; |
|
4103 |
||
4104 |
f = __FILEVal(fp); |
|
4105 |
_buffered = (__INST(buffered) == true); |
|
4106 |
if (_buffered) { |
|
4107 |
__READING__(f) |
|
4108 |
} |
|
4109 |
__READBYTES__(ret, f, u.buffer, 2, _buffered, __INST(handleType)); |
|
4110 |
||
4111 |
if (ret == 2) { |
|
4112 |
if (__isSmallInteger(__INST(position))) { |
|
4113 |
INT np = __intVal(__INST(position)) + 2; |
|
4114 |
OBJ t; |
|
4115 |
||
4116 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4117 |
} else { |
|
4118 |
__INST(position) = nil; /* i.e. do not know */ |
|
4119 |
} |
|
4120 |
if (msbFlag == true) { |
|
19219 | 4121 |
#if defined(__MSBFIRST__) |
23743 | 4122 |
value = u.shortVal; |
19219 | 4123 |
#else |
23743 | 4124 |
value = ((u.buffer[0] & 0xFF) << 8) | (u.buffer[1] & 0xFF); |
19219 | 4125 |
#endif |
23743 | 4126 |
} else { |
19219 | 4127 |
#if defined(__LSBFIRST__) |
23743 | 4128 |
value = u.shortVal; |
19219 | 4129 |
#else |
23743 | 4130 |
value = ((u.buffer[1] & 0xFF) << 8) | (u.buffer[0] & 0xFF); |
19219 | 4131 |
#endif |
23743 | 4132 |
} |
4133 |
RETURN (__mkSmallInteger(value)); |
|
4134 |
} |
|
4135 |
||
4136 |
if (ret < 0) { |
|
4137 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 4138 |
# ifdef __win32__ |
23743 | 4139 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4140 |
# endif |
23743 | 4141 |
error = __mkSmallInteger(__threadErrno); |
4142 |
} else /* ret == 0 */ { |
|
4143 |
__INST(hitEOF) = true; |
|
4144 |
} |
|
4145 |
} |
|
19219 | 4146 |
} |
4147 |
%}. |
|
4148 |
hitEOF ifTrue:[^ self pastEndRead]. |
|
4149 |
handle isNil ifTrue:[^ self errorNotOpen]. |
|
4150 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
4151 |
lastErrorNumber := error. |
|
4152 |
^ self readError:error. |
|
23538 | 4153 |
|
4154 |
"Modified: / 22-11-2018 / 14:45:57 / Stefan Vogel" |
|
612 | 4155 |
! |
4156 |
||
19213
b990f28738b2
refactored to get rid of implizit sizeinnextPutXX:MSM:methods
Claus Gittinger <cg@exept.de>
parents:
19072
diff
changeset
|
4157 |
nextInt32MSB:msbFlag |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
4158 |
"Read four bytes and return the value as a 32-bit signed Integer, |
612 | 4159 |
which may be a LargeInteger. |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
4160 |
If msbFlag is true, value is read with most-significant byte first, |
612 | 4161 |
otherwise least-significant byte comes first. |
4162 |
A nil is returned, if EOF is hit before all 4 bytes have been read. |
|
4163 |
Works in both binary and text modes." |
|
4164 |
||
16296 | 4165 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4166 |
%{ |
612 | 4167 |
OBJ fp; |
4168 |
||
1133 | 4169 |
__INST(lastErrorNumber) = nil; |
12548 | 4170 |
if ((__INST(handleType) == nil) |
4171 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4172 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4173 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 4174 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 4175 |
if (((fp = __INST(handle)) != nil) |
4176 |
&& (__INST(mode) != @symbol(writeonly)) |
|
4177 |
) { |
|
4178 |
FILEPOINTER f; |
|
4179 |
int ret, _buffered; |
|
4180 |
int value; |
|
4181 |
union { |
|
4182 |
unsigned char buffer[4]; |
|
4183 |
int intVal; |
|
4184 |
} u; |
|
4185 |
||
4186 |
f = __FILEVal(fp); |
|
4187 |
_buffered = (__INST(buffered) == true); |
|
4188 |
if (_buffered) { |
|
4189 |
__READING__(f) |
|
4190 |
} |
|
4191 |
__READBYTES__(ret, f, u.buffer, 4, _buffered, __INST(handleType)); |
|
4192 |
||
4193 |
if (ret == 4) { |
|
4194 |
if (__isSmallInteger(__INST(position))) { |
|
4195 |
INT np = __intVal(__INST(position)) + 4; |
|
4196 |
OBJ t; |
|
4197 |
||
4198 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4199 |
} else { |
|
4200 |
__INST(position) = nil; /* i.e. do not know */ |
|
4201 |
} |
|
4202 |
if (msbFlag == true) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4203 |
#if defined(__MSBFIRST__) |
23743 | 4204 |
value = u.intVal; |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4205 |
#else |
23743 | 4206 |
value = (u.buffer[0] & 0xFF); |
4207 |
value = (value << 8) | (u.buffer[1] & 0xFF); |
|
4208 |
value = (value << 8) | (u.buffer[2] & 0xFF); |
|
4209 |
value = (value << 8) | (u.buffer[3] & 0xFF); |
|
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4210 |
#endif |
23743 | 4211 |
} else { |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4212 |
#if defined(__LSBFIRST__) |
23743 | 4213 |
value = u.intVal; |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4214 |
#else |
23743 | 4215 |
value = (u.buffer[3] & 0xFF); |
4216 |
value = (value << 8) | (u.buffer[2] & 0xFF); |
|
4217 |
value = (value << 8) | (u.buffer[1] & 0xFF); |
|
4218 |
value = (value << 8) | (u.buffer[0] & 0xFF); |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4219 |
#endif |
23743 | 4220 |
} |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4221 |
#if __POINTER_SIZE__ == 8 |
23743 | 4222 |
RETURN ( __mkSmallInteger(value)); |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4223 |
#else |
23743 | 4224 |
RETURN ( __MKINT(value) ); |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4225 |
#endif |
23743 | 4226 |
} |
4227 |
||
4228 |
if (ret < 0) { |
|
4229 |
__INST(position) = nil; |
|
23538 | 4230 |
# ifdef __win32__ |
23743 | 4231 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4232 |
# endif |
23743 | 4233 |
error = __mkSmallInteger(__threadErrno); |
4234 |
} else /* ret == 0 */ { |
|
4235 |
__INST(hitEOF) = true; |
|
4236 |
} |
|
4237 |
} |
|
612 | 4238 |
} |
4239 |
%}. |
|
8614 | 4240 |
hitEOF ifTrue:[^ self pastEndRead]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4241 |
handle isNil ifTrue:[^ self errorNotOpen]. |
612 | 4242 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
16296 | 4243 |
lastErrorNumber := error. |
4244 |
^ self readError:error. |
|
23538 | 4245 |
|
4246 |
"Modified: / 22-11-2018 / 14:46:05 / Stefan Vogel" |
|
362 | 4247 |
! |
4248 |
||
19219 | 4249 |
nextUnsignedInt16MSB:msbFlag |
4250 |
"Read two bytes and return the value as a 16-bit unsigned Integer. |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
4251 |
If msbFlag is true, value is read with most-significant byte first, |
612 | 4252 |
otherwise least-significant byte comes first. |
4253 |
A nil is returned if EOF is reached (also when EOF is hit after the first byte). |
|
4254 |
Works in both binary and text modes." |
|
4255 |
||
16296 | 4256 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4257 |
%{ |
612 | 4258 |
OBJ fp; |
4259 |
||
1133 | 4260 |
__INST(lastErrorNumber) = nil; |
12548 | 4261 |
if ((__INST(handleType) == nil) |
4262 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4263 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4264 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 4265 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 4266 |
if (((fp = __INST(handle)) != nil) |
4267 |
&& (__INST(mode) != @symbol(writeonly)) |
|
4268 |
) { |
|
4269 |
FILEPOINTER f; |
|
4270 |
int ret, _buffered; |
|
4271 |
unsigned int value; |
|
4272 |
union { |
|
4273 |
unsigned char buffer[2]; |
|
4274 |
unsigned short shortVal; |
|
4275 |
} u; |
|
4276 |
||
4277 |
f = __FILEVal(fp); |
|
4278 |
_buffered = (__INST(buffered) == true); |
|
4279 |
if (_buffered) { |
|
4280 |
__READING__(f) |
|
4281 |
} |
|
4282 |
__READBYTES__(ret, f, u.buffer, 2, _buffered, __INST(handleType)); |
|
4283 |
||
4284 |
if (ret == 2) { |
|
4285 |
if (__isSmallInteger(__INST(position))) { |
|
4286 |
INT np = __intVal(__INST(position)) + 2; |
|
4287 |
OBJ t; |
|
4288 |
||
4289 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4290 |
} else { |
|
4291 |
__INST(position) = nil; /* i.e. do not know */ |
|
4292 |
} |
|
4293 |
if (msbFlag == true) { |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4294 |
#if defined(__MSBFIRST__) |
23743 | 4295 |
value = u.shortVal; |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4296 |
#else |
23743 | 4297 |
value = (u.buffer[0] << 8) | u.buffer[1]; |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4298 |
#endif |
23743 | 4299 |
} else { |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4300 |
#if defined(__LSBFIRST__) |
23743 | 4301 |
value = u.shortVal; |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4302 |
#else |
23743 | 4303 |
value = (u.buffer[1] << 8) | u.buffer[0]; |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4304 |
#endif |
23743 | 4305 |
} |
4306 |
RETURN (__mkSmallInteger(value)); |
|
4307 |
} |
|
4308 |
||
4309 |
if (ret < 0) { |
|
4310 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 4311 |
# ifdef __win32__ |
23743 | 4312 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4313 |
# endif |
23743 | 4314 |
error = __mkSmallInteger(__threadErrno); |
4315 |
} else /* ret == 0 */ { |
|
4316 |
__INST(hitEOF) = true; |
|
4317 |
} |
|
4318 |
} |
|
612 | 4319 |
} |
4320 |
%}. |
|
8614 | 4321 |
hitEOF ifTrue:[^ self pastEndRead]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4322 |
handle isNil ifTrue:[^ self errorNotOpen]. |
612 | 4323 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
16296 | 4324 |
lastErrorNumber := error. |
4325 |
^ self readError:error. |
|
23538 | 4326 |
|
4327 |
"Modified: / 22-11-2018 / 14:49:05 / Stefan Vogel" |
|
612 | 4328 |
! |
4329 |
||
19213
b990f28738b2
refactored to get rid of implizit sizeinnextPutXX:MSM:methods
Claus Gittinger <cg@exept.de>
parents:
19072
diff
changeset
|
4330 |
nextUnsignedInt32MSB:msbFlag |
612 | 4331 |
"Read four bytes and return the value as a 32-bit unsigned Integer, which may be |
4332 |
a LargeInteger. |
|
4333 |
If msbFlag is true, value is read with most-significant byte first, otherwise |
|
4334 |
least-significant byte comes first. |
|
4335 |
A nil is returned, if endOfFile occurs before all 4 bytes have been read. |
|
4336 |
Works in both binary and text modes." |
|
4337 |
||
16296 | 4338 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4339 |
%{ |
612 | 4340 |
OBJ fp; |
4341 |
||
1133 | 4342 |
__INST(lastErrorNumber) = nil; |
12548 | 4343 |
if ((__INST(handleType) == nil) |
4344 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4345 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4346 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 4347 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 4348 |
if (((fp = __INST(handle)) != nil) |
4349 |
&& (__INST(mode) != @symbol(writeonly)) |
|
4350 |
) { |
|
4351 |
FILEPOINTER f; |
|
4352 |
int ret, _buffered; |
|
4353 |
unsigned INT value; |
|
4354 |
union { |
|
4355 |
unsigned char buffer[4]; |
|
4356 |
unsigned int intVal; |
|
4357 |
} u; |
|
4358 |
||
4359 |
f = __FILEVal(fp); |
|
4360 |
_buffered = (__INST(buffered) == true); |
|
4361 |
if (_buffered) { |
|
4362 |
__READING__(f) |
|
4363 |
} |
|
4364 |
__READBYTES__(ret, f, u.buffer, 4, _buffered, __INST(handleType)); |
|
4365 |
||
4366 |
if (ret == 4) { |
|
4367 |
if (__isSmallInteger(__INST(position))) { |
|
4368 |
INT np = __intVal(__INST(position)) + 4; |
|
4369 |
OBJ t; |
|
4370 |
||
4371 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4372 |
} else { |
|
4373 |
__INST(position) = nil; /* i.e. do not know */ |
|
4374 |
} |
|
4375 |
if (msbFlag == true) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4376 |
#if defined(__MSBFIRST__) |
23743 | 4377 |
value = u.intVal; |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4378 |
#else |
23743 | 4379 |
value = u.buffer[0]; |
4380 |
value = (value << 8) | u.buffer[1]; |
|
4381 |
value = (value << 8) | u.buffer[2]; |
|
4382 |
value = (value << 8) | u.buffer[3]; |
|
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4383 |
#endif |
23743 | 4384 |
} else { |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4385 |
#if defined(__LSBFIRST__) |
23743 | 4386 |
value = u.intVal; |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4387 |
#else |
23743 | 4388 |
value = u.buffer[3]; |
4389 |
value = (value << 8) | u.buffer[2]; |
|
4390 |
value = (value << 8) | u.buffer[1]; |
|
4391 |
value = (value << 8) | u.buffer[0]; |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4392 |
#endif |
23743 | 4393 |
} |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4394 |
#if __POINTER_SIZE__ == 8 |
23743 | 4395 |
value &= 0xFFFFFFFF; |
4396 |
RETURN (__mkSmallInteger(value)); |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4397 |
#else |
23743 | 4398 |
if (value <= _MAX_INT) { |
4399 |
RETURN (__mkSmallInteger(value)); |
|
4400 |
} |
|
4401 |
RETURN (__MKULARGEINT(value) ); |
|
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4402 |
#endif |
23743 | 4403 |
} |
4404 |
||
4405 |
if (ret < 0) { |
|
4406 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 4407 |
# ifdef __win32__ |
23743 | 4408 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4409 |
# endif |
23743 | 4410 |
error = __mkSmallInteger(__threadErrno); |
4411 |
} else /* ret == 0 */ { |
|
4412 |
__INST(hitEOF) = true; |
|
4413 |
} |
|
4414 |
} |
|
612 | 4415 |
} |
4416 |
%}. |
|
8614 | 4417 |
hitEOF ifTrue:[^ self pastEndRead]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4418 |
handle isNil ifTrue:[^ self errorNotOpen]. |
612 | 4419 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
16296 | 4420 |
lastErrorNumber := error. |
4421 |
^ self readError:error. |
|
23538 | 4422 |
|
4423 |
"Modified: / 22-11-2018 / 14:49:23 / Stefan Vogel" |
|
612 | 4424 |
! |
4425 |
||
4426 |
nextWord |
|
15452 | 4427 |
<resource: #obsolete> |
612 | 4428 |
"in text-mode: |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4429 |
read the alphaNumeric next word (i.e. up to non letter-or-digit). |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4430 |
return a string containing those characters. |
612 | 4431 |
in binary-mode: |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4432 |
read two bytes (msb-first) and return the value as a 16-bit |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4433 |
unsigned Integer (for compatibility with other smalltalks)" |
612 | 4434 |
|
4435 |
binary ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4436 |
self obsoleteMethodWarning:'use #nextUnsignedInt16MSB:true'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4437 |
^ self nextUnsignedInt16MSB:true |
92 | 4438 |
]. |
14518 | 4439 |
self obsoleteMethodWarning:'use #nextAlphaNumericWord'. |
612 | 4440 |
^ self nextAlphaNumericWord |
4441 |
! ! |
|
4442 |
||
4443 |
!ExternalStream methodsFor:'non homogenous writing'! |
|
4444 |
||
4445 |
nextPutByte:aByteValue |
|
4446 |
"write a byte. |
|
4447 |
Works in both binary and text modes." |
|
4448 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4449 |
|error| |
16296 | 4450 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4451 |
%{ |
7875
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
4452 |
OBJ fp; |
612 | 4453 |
|
1133 | 4454 |
__INST(lastErrorNumber) = nil; |
12548 | 4455 |
if ((__INST(handleType) == nil) |
4456 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4457 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4458 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 4459 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 4460 |
if (((fp = __INST(handle)) != nil) |
4461 |
&& (__INST(mode) != @symbol(readonly)) |
|
4462 |
&& __isSmallInteger(aByteValue) |
|
4463 |
||
4464 |
) { |
|
4465 |
int _buffered = (__INST(buffered) == true); |
|
4466 |
FILEPOINTER f = __FILEVal(fp); |
|
4467 |
char c = __intVal(aByteValue); |
|
4468 |
int cnt; |
|
4469 |
||
4470 |
if (_buffered) { |
|
4471 |
__WRITING__(f) |
|
4472 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4473 |
#ifdef __win32__ |
23743 | 4474 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
4475 |
cnt = __win32_fwrite(&c, 1, 1, f); |
|
4476 |
} else |
|
9053
f3f3d48d6f44
fix writing to stdout/stderr for winstx non-console operation
Claus Gittinger <cg@exept.de>
parents:
9024
diff
changeset
|
4477 |
#endif |
23743 | 4478 |
{ |
4479 |
__WRITEBYTE__(cnt, f, &c, _buffered, __INST(handleType)); |
|
4480 |
} |
|
4481 |
if (cnt == 1) { |
|
4482 |
if (__isSmallInteger(__INST(position))) { |
|
4483 |
INT np = __intVal(__INST(position)) + 1; |
|
4484 |
OBJ t; |
|
4485 |
||
4486 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4487 |
} else { |
|
4488 |
__INST(position) = nil; /* i.e. do not know */ |
|
4489 |
} |
|
4490 |
RETURN (self); |
|
4491 |
} |
|
4492 |
if (cnt < 0) { |
|
4493 |
__INST(position) = nil; /* i.e. do not know */ |
|
4494 |
} |
|
23538 | 4495 |
# ifdef __win32__ |
23743 | 4496 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4497 |
# endif |
23743 | 4498 |
error = __mkSmallInteger(__threadErrno); |
4499 |
} |
|
612 | 4500 |
} |
4501 |
%}. |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4502 |
handle isNil ifTrue:[self errorNotOpen. ^ self]. |
7801
d930c353588d
writeError: care for EWOULDBLOCK in nonBlocking case.
penk
parents:
7737
diff
changeset
|
4503 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
16296 | 4504 |
lastErrorNumber := error. |
4505 |
self writeError:error. |
|
23538 | 4506 |
|
4507 |
"Modified: / 22-11-2018 / 14:47:34 / Stefan Vogel" |
|
612 | 4508 |
! |
4509 |
||
19219 | 4510 |
nextPutInt16:anIntegerOrCharacter MSB:msbFlag |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4511 |
"Write the argument, anIntegerOrCharacter as a short (two bytes). |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4512 |
If msbFlag is true, data is written most-significant byte first; |
19615 | 4513 |
otherwise least first. |
22266 | 4514 |
Notice that integers in the range 16r-8000 to +16rFFFF can be written |
19615 | 4515 |
(i.e. both signed and unsigned int32 values can be written. |
19219 | 4516 |
Works in both binary and text modes." |
4517 |
||
4518 |
|error| |
|
4519 |
%{ |
|
4520 |
int num; |
|
4521 |
union { |
|
23743 | 4522 |
char bytes[2]; |
4523 |
short shortVal; |
|
19219 | 4524 |
} u; |
4525 |
OBJ fp; |
|
4526 |
||
4527 |
__INST(lastErrorNumber) = nil; |
|
4528 |
if ((__INST(handleType) == nil) |
|
4529 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4530 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
4531 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
4532 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
23743 | 4533 |
if (((fp = __INST(handle)) != nil) |
4534 |
&& (__INST(mode) != @symbol(readonly)) |
|
4535 |
) { |
|
4536 |
FILEPOINTER f = __FILEVal(fp); |
|
4537 |
int _buffered = (__INST(buffered) == true); |
|
4538 |
int cnt; |
|
4539 |
||
4540 |
if (__isSmallInteger(anIntegerOrCharacter)) { |
|
4541 |
num = __intVal(anIntegerOrCharacter); |
|
4542 |
} else if (__isCharacter(anIntegerOrCharacter)) { |
|
4543 |
num = __smallIntegerVal(__characterVal(anIntegerOrCharacter)); |
|
4544 |
} else |
|
4545 |
goto out; |
|
4546 |
||
4547 |
if (msbFlag == true) { |
|
19219 | 4548 |
#if defined(__MSBFIRST__) |
23743 | 4549 |
u.shortVal = num; |
19219 | 4550 |
#else |
23743 | 4551 |
u.bytes[0] = (num >> 8) & 0xFF; |
4552 |
u.bytes[1] = num & 0xFF; |
|
19219 | 4553 |
#endif |
23743 | 4554 |
} else { |
19219 | 4555 |
#if defined(__LSBFIRST__) |
23743 | 4556 |
u.shortVal = num; |
19219 | 4557 |
#else |
23743 | 4558 |
u.bytes[1] = (num >> 8) & 0xFF; |
4559 |
u.bytes[0] = num & 0xFF; |
|
19219 | 4560 |
#endif |
23743 | 4561 |
} |
4562 |
||
4563 |
if (_buffered) { |
|
4564 |
__WRITING__(f) |
|
4565 |
} |
|
4566 |
__WRITEBYTES__(cnt, f, u.bytes, 2, _buffered, __INST(handleType)); |
|
4567 |
||
4568 |
if (cnt == 2) { |
|
4569 |
if (__isSmallInteger(__INST(position))) { |
|
4570 |
INT np = __intVal(__INST(position)) + 2; |
|
4571 |
OBJ t; |
|
4572 |
||
4573 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4574 |
} else { |
|
4575 |
__INST(position) = nil; /* i.e. do not know */ |
|
4576 |
} |
|
4577 |
RETURN ( self ); |
|
4578 |
} |
|
4579 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 4580 |
# ifdef __win32__ |
23743 | 4581 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4582 |
# endif |
23743 | 4583 |
error = __mkSmallInteger(__threadErrno); |
4584 |
} |
|
19219 | 4585 |
} |
4586 |
out:; |
|
4587 |
%}. |
|
4588 |
error notNil ifTrue:[ |
|
23743 | 4589 |
lastErrorNumber := error. |
4590 |
self writeError:error. |
|
4591 |
^ self |
|
19219 | 4592 |
]. |
4593 |
handle isNil ifTrue:[self errorNotOpen. ^ self]. |
|
4594 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
|
4595 |
self argumentMustBeInteger |
|
22266 | 4596 |
|
4597 |
"Modified: / 19-09-2017 / 16:32:29 / stefan" |
|
23538 | 4598 |
"Modified: / 22-11-2018 / 14:48:14 / Stefan Vogel" |
19219 | 4599 |
! |
4600 |
||
19615 | 4601 |
nextPutInt16LSB:anIntegerOrCharacter |
4602 |
"do not remove. |
|
4603 |
See #patchByteOrderOptimizedMethods" |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4604 |
|
19615 | 4605 |
self nextPutInt16:anIntegerOrCharacter MSB:false |
4606 |
! |
|
4607 |
||
4608 |
nextPutInt16MSB:anIntegerOrCharacter |
|
4609 |
"do not remove. |
|
4610 |
See #patchByteOrderOptimizedMethods" |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4611 |
|
19615 | 4612 |
self nextPutInt16:anIntegerOrCharacter MSB:true |
4613 |
! |
|
4614 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4615 |
nextPutInt16NATIVE:anIntegerOrCharacter |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4616 |
"Write the argument, anIntegerOrCharacter as a short (two bytes) in native byte order. |
23934 | 4617 |
This is the CPU-specific byte order (LSB on x86 and VAX, MSB on sparc, and possibly on ARM). |
22266 | 4618 |
Notice that integers in the range 16r-8000 to +16rFFFF can be written |
19615 | 4619 |
(i.e. both signed and unsigned int32 values can be written. |
4620 |
Works in both binary and text modes." |
|
4621 |
||
4622 |
|error| |
|
4623 |
%{ |
|
4624 |
int num; |
|
4625 |
union { |
|
25136 | 4626 |
char bytes[2]; |
4627 |
short shortVal; |
|
19615 | 4628 |
} u; |
4629 |
OBJ fp; |
|
4630 |
||
4631 |
__INST(lastErrorNumber) = nil; |
|
4632 |
if ((__INST(handleType) == nil) |
|
4633 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4634 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
4635 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
4636 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
25136 | 4637 |
if (((fp = __INST(handle)) != nil) |
4638 |
&& (__INST(mode) != @symbol(readonly)) |
|
4639 |
) { |
|
4640 |
FILEPOINTER f = __FILEVal(fp); |
|
4641 |
int _buffered = (__INST(buffered) == true); |
|
4642 |
int cnt; |
|
4643 |
||
4644 |
if (__isSmallInteger(anIntegerOrCharacter)) { |
|
4645 |
num = __intVal(anIntegerOrCharacter); |
|
4646 |
} else if (__isCharacter(anIntegerOrCharacter)) { |
|
4647 |
num = __smallIntegerVal(__characterVal(anIntegerOrCharacter)); |
|
4648 |
} else |
|
4649 |
goto out; |
|
4650 |
||
4651 |
u.shortVal = num; |
|
4652 |
||
4653 |
if (_buffered) { |
|
4654 |
__WRITING__(f) |
|
4655 |
} |
|
4656 |
__WRITEBYTES__(cnt, f, u.bytes, 2, _buffered, __INST(handleType)); |
|
4657 |
||
4658 |
if (cnt == 2) { |
|
4659 |
if (__isSmallInteger(__INST(position))) { |
|
4660 |
INT np = __intVal(__INST(position)) + 2; |
|
4661 |
OBJ t; |
|
4662 |
||
4663 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4664 |
} else { |
|
4665 |
__INST(position) = nil; /* i.e. do not know */ |
|
4666 |
} |
|
4667 |
RETURN ( self ); |
|
4668 |
} |
|
4669 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 4670 |
# ifdef __win32__ |
25136 | 4671 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4672 |
# endif |
25136 | 4673 |
error = __mkSmallInteger(__threadErrno); |
4674 |
} |
|
19615 | 4675 |
} |
4676 |
out:; |
|
4677 |
%}. |
|
4678 |
self nextPutInt16:anIntegerOrCharacter MSB:(UninterpretedBytes isBigEndian). |
|
22266 | 4679 |
|
4680 |
"Modified: / 19-09-2017 / 16:32:40 / stefan" |
|
23538 | 4681 |
"Modified: / 22-11-2018 / 14:48:23 / Stefan Vogel" |
23934 | 4682 |
"Modified: / 17-03-2019 / 14:52:06 / Claus Gittinger" |
19615 | 4683 |
! |
4684 |
||
19213
b990f28738b2
refactored to get rid of implizit sizeinnextPutXX:MSM:methods
Claus Gittinger <cg@exept.de>
parents:
19072
diff
changeset
|
4685 |
nextPutInt32:aNumber MSB:msbFlag |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4686 |
"Write the argument, aNumber as a long (four bytes). |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4687 |
If msbFlag is true, data is written most-significant byte first; |
19615 | 4688 |
otherwise least first. |
22266 | 4689 |
Notice that integers in the range 16r-80000000 to +16rFFFFFFFF can be written |
19615 | 4690 |
(i.e. both signed and unsigned int32 values can be written. |
612 | 4691 |
Works in both binary and text modes." |
4692 |
||
16296 | 4693 |
|error| |
4694 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4695 |
%{ |
612 | 4696 |
int num; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4697 |
union { |
23743 | 4698 |
char bytes[4]; |
4699 |
int intVal; |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4700 |
} u; |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4701 |
OBJ fp; |
612 | 4702 |
|
1133 | 4703 |
__INST(lastErrorNumber) = nil; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4704 |
if (__isSmallInteger(aNumber)) { |
23743 | 4705 |
num = __intVal(aNumber); |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4706 |
} else { |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4707 |
#if __POINTER_SIZE__ == 8 |
23743 | 4708 |
// always more than 4-bytes |
4709 |
goto badArg; |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4710 |
#else |
23743 | 4711 |
num = __longIntVal(aNumber); |
4712 |
if (num == 0) { |
|
4713 |
num = __signedLongIntVal(aNumber); |
|
4714 |
if (num == 0) { |
|
4715 |
/* bad arg or out-of-range integer |
|
4716 |
* (handled by the fallBack code) |
|
4717 |
*/ |
|
4718 |
goto badArg; |
|
4719 |
} |
|
4720 |
} |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4721 |
#endif |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4722 |
} |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4723 |
|
12548 | 4724 |
if ((__INST(handleType) == nil) |
4725 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4726 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4727 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 4728 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 4729 |
if (((fp = __INST(handle)) != nil) |
4730 |
&& (__INST(mode) != @symbol(readonly)) |
|
4731 |
) { |
|
4732 |
int _buffered = (__INST(buffered) == true); |
|
4733 |
FILEPOINTER f = __FILEVal(fp); |
|
4734 |
int cnt; |
|
4735 |
||
4736 |
if (msbFlag == true) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4737 |
#if defined(__MSBFIRST__) |
23743 | 4738 |
u.intVal = num; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4739 |
#else |
23743 | 4740 |
u.bytes[0] = (num >> 24) & 0xFF; |
4741 |
u.bytes[1] = (num >> 16) & 0xFF; |
|
4742 |
u.bytes[2] = (num >> 8) & 0xFF; |
|
4743 |
u.bytes[3] = num & 0xFF; |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4744 |
#endif |
23743 | 4745 |
} else { |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4746 |
#if defined(__LSBFIRST__) |
23743 | 4747 |
u.intVal = num; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4748 |
#else |
23743 | 4749 |
u.bytes[3] = (num >> 24) & 0xFF; |
4750 |
u.bytes[2] = (num >> 16) & 0xFF; |
|
4751 |
u.bytes[1] = (num >> 8) & 0xFF; |
|
4752 |
u.bytes[0] = num & 0xFF; |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4753 |
#endif |
23743 | 4754 |
} |
4755 |
||
4756 |
if (_buffered) { |
|
4757 |
__WRITING__(f) |
|
4758 |
} |
|
4759 |
__WRITEBYTES__(cnt, f, u.bytes, 4, _buffered, __INST(handleType)); |
|
4760 |
||
4761 |
if (cnt == 4) { |
|
4762 |
if (__isSmallInteger(__INST(position))) { |
|
4763 |
INT np = __intVal(__INST(position)) + 4; |
|
4764 |
OBJ t; |
|
4765 |
||
4766 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4767 |
} else { |
|
4768 |
__INST(position) = nil; /* i.e. do not know */ |
|
4769 |
} |
|
4770 |
RETURN ( self ); |
|
4771 |
} |
|
4772 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 4773 |
# ifdef __win32__ |
23743 | 4774 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4775 |
# endif |
23743 | 4776 |
error = __mkSmallInteger(__threadErrno); |
4777 |
} |
|
612 | 4778 |
} |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4779 |
badArg: ; |
612 | 4780 |
%}. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4781 |
handle isNil ifTrue:[self errorNotOpen. ^ self]. |
7801
d930c353588d
writeError: care for EWOULDBLOCK in nonBlocking case.
penk
parents:
7737
diff
changeset
|
4782 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
16296 | 4783 |
error notNil ifTrue:[ |
23743 | 4784 |
lastErrorNumber := error. |
4785 |
self writeError:error. |
|
4786 |
^ self |
|
16296 | 4787 |
]. |
612 | 4788 |
|
4789 |
aNumber isInteger ifTrue:[ |
|
23743 | 4790 |
^ super nextPutInt32:aNumber MSB:msbFlag |
92 | 4791 |
]. |
612 | 4792 |
self argumentMustBeInteger |
22266 | 4793 |
|
4794 |
"Modified: / 19-09-2017 / 16:32:50 / stefan" |
|
23538 | 4795 |
"Modified: / 22-11-2018 / 14:48:29 / Stefan Vogel" |
19615 | 4796 |
! |
4797 |
||
4798 |
nextPutInt32LSB:anIntegerOrCharacter |
|
4799 |
"do not remove. |
|
4800 |
See #patchByteOrderOptimizedMethods" |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4801 |
|
19615 | 4802 |
self nextPutInt32:anIntegerOrCharacter MSB:false |
4803 |
! |
|
4804 |
||
4805 |
nextPutInt32MSB:anIntegerOrCharacter |
|
4806 |
"do not remove. |
|
4807 |
See #patchByteOrderOptimizedMethods" |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4808 |
|
19615 | 4809 |
self nextPutInt32:anIntegerOrCharacter MSB:true |
4810 |
! |
|
4811 |
||
4812 |
nextPutInt32NATIVE:anInteger |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4813 |
"Write the argument, anInteger as a long (four bytes) in native byte order. |
23934 | 4814 |
This is the CPU-specific byte order (LSB on x86 and VAX, MSB on sparc and possibly on ARM). |
22266 | 4815 |
Notice that integers in the range 16r-80000000 to +16rFFFFFFFF can be written |
19615 | 4816 |
(i.e. both signed and unsigned int32 values can be written. |
4817 |
Works in both binary and text modes. |
|
4818 |
Notice: this message should not be sent explicitly by ANY program. |
|
25136 | 4819 |
the following implementation replaces the code of either nextPutInt32MSB or LSB |
4820 |
dynamically (see #initialize on the class side)" |
|
19615 | 4821 |
|
4822 |
|error| |
|
4823 |
||
4824 |
%{ |
|
4825 |
int num; |
|
4826 |
union { |
|
25136 | 4827 |
char bytes[4]; |
4828 |
int intVal; |
|
19615 | 4829 |
} u; |
4830 |
OBJ fp; |
|
4831 |
||
4832 |
__INST(lastErrorNumber) = nil; |
|
4833 |
if (__isSmallInteger(anInteger)) { |
|
25136 | 4834 |
num = __intVal(anInteger); |
19615 | 4835 |
} else { |
4836 |
#if __POINTER_SIZE__ == 8 |
|
25136 | 4837 |
// always more than 4-bytes |
4838 |
goto badArg; |
|
19615 | 4839 |
#else |
25136 | 4840 |
num = __longIntVal(anInteger); |
4841 |
if (num == 0) { |
|
4842 |
num = __signedLongIntVal(anInteger); |
|
4843 |
if (num == 0) { |
|
4844 |
/* bad arg or out-of-range integer |
|
4845 |
* (handled by the fallBack code) |
|
4846 |
*/ |
|
4847 |
goto badArg; |
|
4848 |
} |
|
4849 |
} |
|
19615 | 4850 |
#endif |
4851 |
} |
|
4852 |
||
4853 |
if ((__INST(handleType) == nil) |
|
4854 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4855 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
4856 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
4857 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
25136 | 4858 |
if (((fp = __INST(handle)) != nil) |
4859 |
&& (__INST(mode) != @symbol(readonly)) |
|
4860 |
) { |
|
4861 |
int _buffered = (__INST(buffered) == true); |
|
4862 |
FILEPOINTER f = __FILEVal(fp); |
|
4863 |
int cnt; |
|
4864 |
||
4865 |
u.intVal = num; |
|
4866 |
if (_buffered) { |
|
4867 |
__WRITING__(f) |
|
4868 |
} |
|
4869 |
__WRITEBYTES__(cnt, f, u.bytes, 4, _buffered, __INST(handleType)); |
|
4870 |
||
4871 |
if (cnt == 4) { |
|
4872 |
if (__isSmallInteger(__INST(position))) { |
|
4873 |
INT np = __intVal(__INST(position)) + 4; |
|
4874 |
OBJ t; |
|
4875 |
||
4876 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4877 |
} else { |
|
4878 |
__INST(position) = nil; /* i.e. do not know */ |
|
4879 |
} |
|
4880 |
RETURN ( self ); |
|
4881 |
} |
|
4882 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 4883 |
# ifdef __win32__ |
25136 | 4884 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4885 |
# endif |
25136 | 4886 |
error = __mkSmallInteger(__threadErrno); |
4887 |
} |
|
19615 | 4888 |
} |
4889 |
badArg: ; |
|
4890 |
%}. |
|
4891 |
self nextPutInt32:anInteger MSB:(UninterpretedBytes isBigEndian) |
|
22266 | 4892 |
|
4893 |
"Modified: / 19-09-2017 / 16:32:59 / stefan" |
|
23538 | 4894 |
"Modified: / 22-11-2018 / 14:48:41 / Stefan Vogel" |
23934 | 4895 |
"Modified: / 17-03-2019 / 14:52:23 / Claus Gittinger" |
20092 | 4896 |
! |
4897 |
||
4898 |
nextPutUtf16:aCharacter |
|
4899 |
"append my UTF-16 MSB representation to the argument, aStream. |
|
4900 |
UTF-16 can encode only characters with code points between 0 to 16r10FFFF." |
|
4901 |
||
4902 |
self nextPutUtf16Bytes:aCharacter MSB:true |
|
4903 |
||
4904 |
" |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4905 |
(FileStream newTemporary |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4906 |
nextPutUtf16:$B; |
25134 | 4907 |
nextPutUtf16:$Ä; |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4908 |
nextPutUtf16:(Character codePoint:16r10CCCC); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4909 |
reset; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4910 |
binary; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4911 |
contents) |
20092 | 4912 |
" |
4913 |
! |
|
4914 |
||
4915 |
nextPutUtf16:aCharacter MSB:msbFlag |
|
4916 |
"append my UTF-16 MSB representation to the argument, aStream. |
|
4917 |
UTF-16 can encode only characters with code points between 0 to 16r10FFFF." |
|
4918 |
||
4919 |
self nextPutUtf16Bytes:aCharacter MSB:msbFlag |
|
10 | 4920 |
! ! |
612 | 4921 |
|
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4922 |
!ExternalStream methodsFor:'positioning'! |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4923 |
|
15619 | 4924 |
position |
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4925 |
self subclassResponsibility |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4926 |
! |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4927 |
|
15619 | 4928 |
position:index0Based |
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4929 |
self subclassResponsibility |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4930 |
! ! |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4931 |
|
12631 | 4932 |
!ExternalStream methodsFor:'printing & storing'! |
4933 |
||
4934 |
printOn:aStream |
|
14068 | 4935 |
aStream |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4936 |
nextPutAll:self className; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4937 |
nextPut:$(. |
22245 | 4938 |
handleType printOn:aStream. |
4939 |
aStream nextPutAll:':('. |
|
12631 | 4940 |
handle printOn:aStream. |
4941 |
aStream nextPutAll:'))' |
|
4942 |
! ! |
|
4943 |
||
612 | 4944 |
!ExternalStream methodsFor:'private'! |
4945 |
||
4946 |
clearEOF |
|
4947 |
hitEOF := false |
|
20987 | 4948 |
! |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4949 |
|
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4950 |
closeFile |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4951 |
"low level close - may be redefined in subclasses |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4952 |
Don't send this message, send #close instead" |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4953 |
|
12674 | 4954 |
|fp error| |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4955 |
|
20679 | 4956 |
handle isNil ifTrue:[ |
23743 | 4957 |
^ self. |
20679 | 4958 |
]. |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4959 |
fp := handle. |
19767 | 4960 |
"/ (didWrite==true and:[binary ~~ true and:[eolMode = #crlf]]) ifTrue: [ self breakPoint:#sr ]. |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4961 |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4962 |
%{ |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4963 |
int rslt; |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4964 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4965 |
if (__INST(handleType) == @symbol(socketHandle)) { |
23743 | 4966 |
SOCKET sock = (SOCKET)(__FILEVal(fp)); |
4967 |
||
23879 | 4968 |
// whether the close() will be successful or not - the handle is invalid now! |
4969 |
__INST(handle) = nil; |
|
4970 |
||
23743 | 4971 |
if (@global(FileOpenTrace) == true) { |
4972 |
fprintf(stderr, "close socket [ExternalStream] %"_lx_"\n", (INT)sock); |
|
4973 |
} |
|
4974 |
||
4975 |
do { |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4976 |
#ifdef __win32__ |
23743 | 4977 |
rslt = __STX_WSA_NOINT_CALL1("closesocket", closesocket, sock); |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4978 |
#else |
23743 | 4979 |
__threadErrno = 0; |
4980 |
__BEGIN_INTERRUPTABLE__ |
|
4981 |
rslt = close(sock); |
|
4982 |
__END_INTERRUPTABLE__ |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4983 |
#endif |
23743 | 4984 |
} while((rslt < 0) && (__threadErrno == EINTR)); |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4985 |
} else if ((__INST(handleType) == nil) |
23743 | 4986 |
|| (__INST(handleType) == @symbol(filePointer)) |
4987 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
4988 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4989 |
{ |
23743 | 4990 |
FILEPOINTER f = __FILEVal(fp); |
4991 |
||
23879 | 4992 |
// whether the close() will be successful or not - the handle is invalid now! |
4993 |
__INST(handle) = nil; |
|
4994 |
||
23743 | 4995 |
if (@global(FileOpenTrace) == true) { |
4996 |
fprintf(stderr, "fclose [ExternalStream] %"_lx_"\n", (INT)f); |
|
4997 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4998 |
|
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4999 |
#ifdef __win32__ |
23743 | 5000 |
if (__INST(mode) != @symbol(readonly) && __INST(buffered) != false) { |
5001 |
// do a fflush() first, so that fclose() doesn't block |
|
5002 |
// we suspect, that EINTR causes problems in fclose() |
|
5003 |
do { |
|
5004 |
__threadErrno = 0; |
|
5005 |
rslt = __STX_C_CALL1("fflush", fflush, f); |
|
5006 |
} while((rslt < 0) && (__threadErrno == EINTR)); |
|
5007 |
if (rslt < 0) |
|
5008 |
goto err; |
|
5009 |
} |
|
5010 |
do { |
|
5011 |
__threadErrno = 0; |
|
5012 |
rslt = __STX_C_NOINT_CALL1("fclose", fclose, f); |
|
5013 |
} while((rslt < 0) && (__threadErrno == EINTR)); |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5014 |
#else |
23743 | 5015 |
// cg: not sure why, but on osx, I get blocked occasionally in fclose |
5016 |
// lets try this: |
|
5017 |
if ((__INST(mode) != @symbol(readonly)) && (__INST(buffered) != false)) { |
|
5018 |
// do a fflush() first, so that fclose() doesn't block |
|
5019 |
// we suspect, that EINTR causes problems in fclose() |
|
5020 |
do { |
|
5021 |
clearerr(f); |
|
5022 |
__threadErrno = 0; |
|
5023 |
__BEGIN_INTERRUPTABLE__ |
|
5024 |
rslt = fflush(f); |
|
5025 |
__END_INTERRUPTABLE__ |
|
5026 |
} while((rslt < 0) && (__threadErrno == EINTR)); |
|
5027 |
if (rslt < 0) |
|
5028 |
goto err; |
|
5029 |
} |
|
5030 |
do { |
|
5031 |
clearerr(f); |
|
5032 |
__threadErrno = 0; |
|
5033 |
__BEGIN_INTERRUPTABLE__ |
|
5034 |
rslt = fclose(f); |
|
5035 |
__END_INTERRUPTABLE__ |
|
5036 |
} while((rslt < 0) && (__threadErrno == EINTR)); |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5037 |
#endif |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5038 |
} else { |
23743 | 5039 |
error = @symbol(badHandleType); |
5040 |
goto out; |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5041 |
} |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5042 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5043 |
if (rslt < 0) { |
23538 | 5044 |
err: |
5045 |
# ifdef __win32__ |
|
23743 | 5046 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5047 |
# endif |
23743 | 5048 |
error = __mkSmallInteger(__threadErrno); |
5049 |
goto out; |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5050 |
} |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5051 |
RETURN (self); |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5052 |
|
12674 | 5053 |
out:; |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5054 |
%}. |
12674 | 5055 |
|
5056 |
error notNil ifTrue:[ |
|
23743 | 5057 |
error isInteger ifTrue:[ |
5058 |
lastErrorNumber := error. |
|
5059 |
mode == #readonly ifTrue:[ |
|
5060 |
self ioError:error. |
|
5061 |
] ifFalse:[ |
|
5062 |
self writeError:error. |
|
5063 |
]. |
|
5064 |
^ self. |
|
5065 |
]. |
|
5066 |
self primitiveFailed:error. |
|
5067 |
^ self. |
|
12674 | 5068 |
]. |
5069 |
||
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5070 |
"/ fallback for rel5 |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5071 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5072 |
fp := handle. |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5073 |
fp notNil ifTrue:[ |
23743 | 5074 |
handle := nil. |
5075 |
self closeFile:fp |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5076 |
] |
22681 | 5077 |
|
5078 |
"Modified: / 19-04-2018 / 10:57:54 / stefan" |
|
23538 | 5079 |
"Modified: / 22-11-2018 / 12:18:22 / Stefan Vogel" |
23737 | 5080 |
"Modified: / 14-02-2019 / 15:42:44 / Claus Gittinger" |
20987 | 5081 |
! |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5082 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5083 |
closeFile:handle |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5084 |
"for rel5 only" |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5085 |
|
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5086 |
self primitiveFailed |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5087 |
! |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5088 |
|
12706 | 5089 |
connectTo:aFileDescriptor withMode:modeSymbol handleType:handleTypeSymbol |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5090 |
"connect a fileDescriptor; openmode is the string defining the way to open. |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5091 |
This can be used to connect an externally provided fileDescriptor (from |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5092 |
primitive code) or a pipeFileDescriptor (as returned by makePipe) to |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5093 |
a Stream object. |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5094 |
The openMode ('r', 'w' etc.) must match the mode in which |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5095 |
the fileDescriptor was originally opened (otherwise i/o errors will be reported later)." |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5096 |
|
21224 | 5097 |
|error openmode| |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5098 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5099 |
handle notNil ifTrue:[^ self errorAlreadyOpen]. |
12706 | 5100 |
mode := modeSymbol. |
5101 |
openmode := self fopenMode. |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5102 |
%{ |
12683 | 5103 |
FILEPOINTER f = 0; |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5104 |
OBJ fp; |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5105 |
FILE *fdopen(); |
12683 | 5106 |
int fd = -2; |
5107 |
||
5108 |
if (__isStringLike(openmode)) { |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5109 |
#ifdef __win32__ |
23743 | 5110 |
__stxWrapApiEnterCritical(); |
12688 | 5111 |
#endif |
23743 | 5112 |
if (__isSmallInteger(aFileDescriptor)) { |
5113 |
fd = __intVal(aFileDescriptor); |
|
5114 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5115 |
#ifdef __win32__ |
23743 | 5116 |
else if (__isExternalAddressLike(aFileDescriptor)) { |
5117 |
fd = _open_osfhandle((long)__externalAddressVal(aFileDescriptor), O_BINARY); |
|
5118 |
if (fd < 0) { |
|
5119 |
if (__threadErrno == 0) { |
|
5120 |
// no more file descriptors |
|
5121 |
__threadErrno = EMFILE; |
|
5122 |
} |
|
5123 |
error = __mkSmallInteger(__WIN32_ERR(GetLastError())); |
|
5124 |
__stxWrapApiLeaveCritical(); |
|
5125 |
goto out; |
|
5126 |
} |
|
5127 |
} |
|
12683 | 5128 |
#endif |
23743 | 5129 |
f = (FILEPOINTER) fdopen(fd, (char *)__stringVal(openmode)); |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5130 |
#ifdef __win32__ |
23743 | 5131 |
__stxWrapApiLeaveCritical(); |
12688 | 5132 |
#endif |
23743 | 5133 |
if (f == NULL) { |
23538 | 5134 |
# ifdef __win32__ |
23743 | 5135 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5136 |
# endif |
23743 | 5137 |
error =__mkSmallInteger(__threadErrno); |
5138 |
} else { |
|
5139 |
if (@global(FileOpenTrace) == true) { |
|
5140 |
fprintf(stderr, "fdopen [ExternalStream] %"_ld_" (%"_lx_") -> %"_lx_"\n", (INT)fd, (INT)fd, (INT)f); |
|
5141 |
} |
|
5142 |
||
5143 |
fp = __MKFILEPOINTER(f); __INST(handle) = fp; __STORE(self, fp); |
|
5144 |
} |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5145 |
} |
12688 | 5146 |
out:; |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5147 |
%}. |
21224 | 5148 |
error notNil ifTrue:[ |
23743 | 5149 |
" |
5150 |
the open failed for some reason ... |
|
5151 |
" |
|
5152 |
OperatingSystem closeFd:aFileDescriptor. |
|
5153 |
lastErrorNumber := error. |
|
5154 |
position := nil. |
|
5155 |
^ self openError:error |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5156 |
]. |
21224 | 5157 |
|
5158 |
position := 0. |
|
5159 |
buffered isNil ifTrue:[ |
|
23743 | 5160 |
buffered := true. "default is buffered" |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5161 |
]. |
21224 | 5162 |
handleType := handleTypeSymbol. |
5163 |
self registerForFinalization. |
|
23538 | 5164 |
|
5165 |
"Modified: / 22-11-2018 / 14:39:27 / Stefan Vogel" |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5166 |
! |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5167 |
|
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5168 |
dupFd |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5169 |
"duplicate my file descriptor" |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5170 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5171 |
|fd dupFd| |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5172 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5173 |
fd := self fileHandle. |
22578 | 5174 |
fd isNil ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5175 |
^ self errorNotOpen. |
20690 | 5176 |
]. |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5177 |
dupFd := OperatingSystem dup:fd. |
10989 | 5178 |
self setFileHandle:dupFd mode:self fopenMode. |
10995 | 5179 |
! |
10989 | 5180 |
|
5181 |
fopenMode |
|
5182 |
"answer the mode for fopen. |
|
5183 |
Only used internally" |
|
5184 |
||
5185 |
mode == #readonly ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5186 |
^ ReadMode |
10989 | 5187 |
]. |
5188 |
mode == #writeonly ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5189 |
^ WriteMode |
10989 | 5190 |
]. |
5191 |
mode == #readWrite ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5192 |
^ ReadWriteMode |
10989 | 5193 |
]. |
5194 |
mode == #append ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5195 |
^ AppendMode |
10989 | 5196 |
]. |
5197 |
^ ReadWriteMode |
|
10995 | 5198 |
! |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5199 |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5200 |
open:aPath withMode:openModeString |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5201 |
"low level open; opens the file/device and sets the handle instance |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5202 |
variable. Careful: this does not care for any other state." |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5203 |
|
16296 | 5204 |
|ok error| |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5205 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5206 |
ok := false. |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5207 |
%{ |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5208 |
FILE *f; |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5209 |
OBJ fp; |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5210 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5211 |
if (__isStringLike(aPath) && __isStringLike(openModeString)) { |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5212 |
#ifdef __win32__ |
10339 | 5213 |
# if 1 |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5214 |
f = fopen((char *) __stringVal(aPath), (char *) __stringVal(openModeString)); |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5215 |
# else |
23743 | 5216 |
__BEGIN_INTERRUPTABLE__ |
5217 |
do { |
|
5218 |
f = fopen((char *) __stringVal(aPath), (char *) __stringVal(openModeString)); |
|
5219 |
} while ((f == NULL) && (__threadErrno == EINTR)); |
|
5220 |
__END_INTERRUPTABLE__ |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5221 |
# endif |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5222 |
#else /* UNIX */ |
23743 | 5223 |
__BEGIN_INTERRUPTABLE__ |
5224 |
do { |
|
5225 |
f = fopen((char *) __stringVal(aPath), (char *) __stringVal(openModeString)); |
|
5226 |
} while ((f == NULL) && (__threadErrno == EINTR)); |
|
5227 |
__END_INTERRUPTABLE__ |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5228 |
#endif /* UNIX */ |
23743 | 5229 |
if (f == NULL) { |
23538 | 5230 |
# ifdef __win32__ |
23743 | 5231 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5232 |
# endif |
23743 | 5233 |
error = __mkSmallInteger(__threadErrno); |
5234 |
} else { |
|
5235 |
if (@global(FileOpenTrace) == true) { |
|
5236 |
fprintf(stderr, "fopen %s [ExternalStream] -> %"_lx_"\n", __stringVal(aPath), (INT)f); |
|
5237 |
} |
|
5238 |
fp = __MKFILEPOINTER(f); __INST(handle) = fp; __STORE(self, fp); |
|
5239 |
__INST(handleType) = @symbol(filePointer); |
|
5240 |
ok = true; |
|
5241 |
} |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5242 |
} |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5243 |
%}. |
16296 | 5244 |
ok ifTrue:[ |
23743 | 5245 |
position := 0. |
5246 |
self registerForFinalization. |
|
5247 |
^ self. |
|
16296 | 5248 |
]. |
5249 |
error notNil ifTrue:[ |
|
23743 | 5250 |
" |
5251 |
the open failed for some reason ... |
|
5252 |
" |
|
5253 |
lastErrorNumber := error. |
|
5254 |
self openError:error. |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5255 |
]. |
16296 | 5256 |
self primitiveFailed. |
23538 | 5257 |
|
5258 |
"Modified: / 22-11-2018 / 14:49:56 / Stefan Vogel" |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5259 |
! |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5260 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5261 |
reOpen |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5262 |
"USERS WILL NEVER INVOKE THIS METHOD |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5263 |
sent after snapin to reopen streams. |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5264 |
cannot reopen here since I am abstract and have no device knowledge" |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5265 |
|
24383 | 5266 |
self className errorPrint. ' [warning]: automatic reOpen not supported - stream closed' errorPrintCR. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5267 |
handle := nil. |
18779 | 5268 |
self unregisterForFinalization. |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5269 |
|
24383 | 5270 |
"Modified: / 10-01-1997 / 17:50:44 / cg" |
5271 |
"Modified: / 28-06-2019 / 08:43:21 / Claus Gittinger" |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5272 |
! |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5273 |
|
12398 | 5274 |
setAccessor:what to:something |
5275 |
"set the filePointer/fileHandle to the given one; |
|
5276 |
low level private & friend interface; may also be used to connect to some |
|
5277 |
externally provided handle." |
|
5278 |
||
5279 |
handle := something. |
|
5280 |
handleType := what. |
|
5281 |
! |
|
5282 |
||
5283 |
setFileHandle:something |
|
5284 |
"set the fileHandle to the given one; |
|
5285 |
low level private & friend interface; may also be used to connect to some |
|
5286 |
externally provided file handle." |
|
5287 |
||
5288 |
self setAccessor:#fileHandle to:something |
|
5289 |
! |
|
5290 |
||
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5291 |
setFileHandle:anIntegerOrExternalAddress mode:openMode |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5292 |
"set the handle based upon a given fileHandle - |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5293 |
notice: this one is based on the underlying OSs fileDescriptor - |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5294 |
this is a fileDescriptor (Integer) on Unix and Windows, or an Handle (ExternalAddres) on Windows only. |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5295 |
It may not be available on all platforms." |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5296 |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5297 |
%{ |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5298 |
FILEPOINTER f; |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5299 |
OBJ fp; |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5300 |
FILE *fdopen(); |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5301 |
int fd; |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5302 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5303 |
if (!__isStringLike(openMode)) |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5304 |
goto err; |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5305 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5306 |
#ifdef __win32__ |
12688 | 5307 |
__stxWrapApiEnterCritical(); |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5308 |
if (__isExternalAddressLike(anIntegerOrExternalAddress) ) { |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5309 |
HANDLE __fileHandle = (HANDLE)__externalAddressVal(anIntegerOrExternalAddress); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5310 |
fd = _open_osfhandle((long)__fileHandle, O_BINARY); /* should we handle readonly, append or text mode? */ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5311 |
if (fd < 0) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5312 |
__stxWrapApiLeaveCritical(); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5313 |
CloseHandle(__fileHandle); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5314 |
goto err; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5315 |
} |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5316 |
} else |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5317 |
#endif |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5318 |
if (__isSmallInteger(anIntegerOrExternalAddress)) { |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5319 |
fd = __smallIntegerVal(anIntegerOrExternalAddress); |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5320 |
} else { |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5321 |
#ifdef __win32__ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5322 |
__stxWrapApiLeaveCritical(); |
12688 | 5323 |
#endif |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5324 |
goto err; |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5325 |
} |
10997 | 5326 |
f = fdopen(fd, __stringVal(openMode)); |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5327 |
#ifdef __win32__ |
12688 | 5328 |
__stxWrapApiLeaveCritical(); |
5329 |
#endif |
|
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5330 |
if (f != NULL) { |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5331 |
if (@global(FileOpenTrace) == true) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5332 |
fprintf(stderr, "fdopen [ExternalStream] %d -> %"_lx_"\n", fd, (INT)f); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5333 |
} |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5334 |
fp = __MKFILEPOINTER(f); __INST(handle) = fp; __STORE(self, fp); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5335 |
__INST(handleType) = @symbol(filePointer); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5336 |
RETURN (self); |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5337 |
} |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5338 |
err:; |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5339 |
%}. |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5340 |
^ self primitiveFailed |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5341 |
! |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5342 |
|
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5343 |
setFilePointer:something |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5344 |
"set the filePointer to the given one; |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5345 |
low level private & friend interface; may also be used to connect to some |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5346 |
externally provided file." |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5347 |
|
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5348 |
self setAccessor:#filePointer to:something |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5349 |
! |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5350 |
|
12398 | 5351 |
setLastError:aNumber |
5352 |
lastErrorNumber := aNumber |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5353 |
! |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5354 |
|
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5355 |
setSocketHandle:something |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5356 |
"set the socketHandle to the given one; |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5357 |
low level private & friend interface; may also be used to connect to some |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5358 |
externally provided socket handle." |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5359 |
|
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5360 |
self setAccessor:#socketHandle to:something |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5361 |
! ! |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5362 |
|
612 | 5363 |
!ExternalStream methodsFor:'queries'! |
5364 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5365 |
nextError |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5366 |
"return the error by trying to read something. |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5367 |
Should only be used, when we know, that a read operation |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5368 |
will return an error (otherwise a character may be lost). |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5369 |
Return an integer (error number), 0 (EOF) or nil (no error)" |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5370 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5371 |
%{ /*NOCONTEXT*/ |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5372 |
FILEPOINTER f; |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5373 |
int ret, _buffered; |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5374 |
OBJ fp; |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5375 |
unsigned char ch; |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5376 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5377 |
if ((__INST(handleType) == nil) |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5378 |
|| (__INST(handleType) == @symbol(filePointer)) |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5379 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5380 |
|| (__INST(handleType) == @symbol(socketHandle)) |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5381 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 5382 |
if (((fp = __INST(handle)) != nil) |
5383 |
&& (__INST(mode) != @symbol(writeonly)) |
|
5384 |
) { |
|
5385 |
f = __FILEVal(fp); |
|
5386 |
||
5387 |
_buffered = (__INST(buffered) == true); |
|
5388 |
if (_buffered) { |
|
5389 |
__READING__(f) |
|
5390 |
} |
|
5391 |
__READBYTE__(ret, f, &ch, _buffered, __INST(handleType)); |
|
5392 |
||
5393 |
if (ret > 0) { |
|
5394 |
RETURN(nil) |
|
5395 |
} |
|
5396 |
if (ret < 0) { |
|
23538 | 5397 |
# ifdef __win32__ |
23743 | 5398 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5399 |
# endif |
23743 | 5400 |
RETURN(__mkSmallInteger(__threadErrno)); |
5401 |
} else /* ret == 0 */ { |
|
5402 |
RETURN(__mkSmallInteger(0)); /* EOF */ |
|
5403 |
} |
|
5404 |
} |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5405 |
} |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5406 |
%}. |
23538 | 5407 |
|
5408 |
"Modified: / 22-11-2018 / 15:07:16 / Stefan Vogel" |
|
612 | 5409 |
! |
5410 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5411 |
numAvailable |
21130 | 5412 |
<resource: #obsolete> |
5413 |
^ self numAvailableForRead |
|
612 | 5414 |
! ! |
5415 |
||
5416 |
!ExternalStream methodsFor:'reading'! |
|
5417 |
||
5418 |
next |
|
5419 |
"return the next element; advance read position. |
|
5420 |
In binary mode, an integer is returned, otherwise a character. |
|
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5421 |
If there are no more elements, either an exception is thrown or nil is returned |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5422 |
- see #pastEndRead." |
1 | 5423 |
|
16296 | 5424 |
|c error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
5425 |
%{ |
18364 | 5426 |
#ifdef __SCHTEAM__ |
5427 |
STObject handle = self.instVarAt(I_handle); |
|
5428 |
||
5429 |
if (handle != STObject.Nil) { |
|
23743 | 5430 |
STObject next; |
5431 |
||
5432 |
if (self.instVarAt(I_binary) == STObject.True) { |
|
5433 |
next = handle.nextByte(); |
|
5434 |
} else { |
|
5435 |
next = handle.nextChar(); |
|
5436 |
} |
|
5437 |
if (next != STObject.EOF) { |
|
5438 |
self.instVarAt_put(I_position, STObject.Nil); |
|
5439 |
return __c__._RETURN( next ); |
|
5440 |
} |
|
5441 |
self.instVarAt_put(I_hitEOF, STObject.True); |
|
18364 | 5442 |
} |
5443 |
#else |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
5444 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5445 |
int ret, _buffered; |
612 | 5446 |
OBJ pos, fp; |
5447 |
unsigned char ch; |
|
5448 |
||
1133 | 5449 |
__INST(lastErrorNumber) = nil; |
12548 | 5450 |
if ((__INST(handleType) == nil) |
5451 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
5452 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5453 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 5454 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 5455 |
if (((fp = __INST(handle)) != nil) |
5456 |
&& (__INST(mode) != @symbol(writeonly)) |
|
5457 |
) { |
|
5458 |
f = __FILEVal(fp); |
|
5459 |
||
5460 |
_buffered = (__INST(buffered) == true); |
|
5461 |
if (_buffered) { |
|
5462 |
__READING__(f) |
|
5463 |
} |
|
5464 |
__READBYTE__(ret, f, &ch, _buffered, __INST(handleType)); |
|
5465 |
||
5466 |
if (ret > 0) { |
|
5467 |
pos = __INST(position); |
|
5468 |
if (__isSmallInteger(pos)) { |
|
5469 |
OBJ t; |
|
5470 |
||
5471 |
t = __MKINT(__intVal(pos) + 1); __INST(position) = t; __STORE(self, t); |
|
5472 |
} else { |
|
5473 |
__INST(position) = nil; /* i.e. do not know */ |
|
5474 |
} |
|
5475 |
if (__INST(binary) == true) { |
|
5476 |
RETURN ( __mkSmallInteger(ch) ); |
|
5477 |
} |
|
5478 |
RETURN ( __MKCHARACTER(ch) ); |
|
5479 |
} |
|
5480 |
||
5481 |
__INST(position) = nil; |
|
5482 |
if (ret < 0) { |
|
23538 | 5483 |
# ifdef __win32__ |
23743 | 5484 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5485 |
# endif |
23743 | 5486 |
error = __mkSmallInteger(__threadErrno); |
5487 |
} else /* ret == 0 */ { |
|
5488 |
__INST(hitEOF) = true; |
|
5489 |
} |
|
5490 |
} |
|
612 | 5491 |
} |
18364 | 5492 |
#endif /* not SCHTEAM */ |
612 | 5493 |
%}. |
21139 | 5494 |
hitEOF ifTrue:[^ self pastEndRead]. |
16296 | 5495 |
error notNil ifTrue:[ |
23743 | 5496 |
lastErrorNumber := error. |
5497 |
^ self readError:error |
|
16296 | 5498 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5499 |
handle isNil ifTrue:[^ self errorNotOpen]. |
5420 | 5500 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
5501 |
||
5502 |
readAhead notNil ifTrue:[ |
|
23743 | 5503 |
c := readAhead. |
5504 |
readAhead := nil. |
|
5505 |
^ c. |
|
5420 | 5506 |
]. |
20679 | 5507 |
|
5508 |
"unknown handleType - future" |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5509 |
c := self nextByteFromFile:handle. |
5430 | 5510 |
c isNil ifTrue:[ |
23743 | 5511 |
^ self pastEndRead. |
5430 | 5512 |
]. |
21139 | 5513 |
binary ifTrue:[ |
23743 | 5514 |
^ c |
5420 | 5515 |
]. |
5516 |
^ Character value:c |
|
23538 | 5517 |
|
5518 |
"Modified: / 22-11-2018 / 14:44:30 / Stefan Vogel" |
|
612 | 5519 |
! |
5520 |
||
5521 |
next:count |
|
5522 |
"return the next count elements of the stream as a collection. |
|
5523 |
Redefined to return a String or ByteArray instead of the default: Array." |
|
5524 |
||
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
5525 |
|coll nRead| |
612 | 5526 |
|
20092 | 5527 |
coll := self contentsSpecies uninitializedNew:count. |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
5528 |
nRead := self nextBytes:count into:coll startingAt:1. |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
5529 |
|
20092 | 5530 |
nRead ~~ count ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5531 |
"/ for readStream protocol compatibility, |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5532 |
"/ we must raise an exception here. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5533 |
^ self pastEndRead |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
5534 |
]. |
612 | 5535 |
^ coll |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
5536 |
|
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
5537 |
"Modified: 11.1.1997 / 17:44:17 / cg" |
612 | 5538 |
! |
5539 |
||
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5540 |
nextOrNil |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5541 |
"return the next element; advance read position. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5542 |
In binary mode, an integer is returned, otherwise a character. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5543 |
If there are no more elements, nil is returned. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5544 |
This is #atEnd and #next in a single operation - to speed up some code" |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5545 |
|
16296 | 5546 |
|c error| |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5547 |
%{ |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5548 |
FILEPOINTER f; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5549 |
int ret, _buffered; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5550 |
OBJ pos, fp; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5551 |
unsigned char ch; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5552 |
|
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5553 |
__INST(lastErrorNumber) = nil; |
12548 | 5554 |
if ((__INST(handleType) == nil) |
5555 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
5556 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5557 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 5558 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 5559 |
if (((fp = __INST(handle)) != nil) |
5560 |
&& (__INST(mode) != @symbol(writeonly)) |
|
5561 |
) { |
|
5562 |
f = __FILEVal(fp); |
|
5563 |
||
5564 |
_buffered = (__INST(buffered) == true); |
|
5565 |
if (_buffered) { |
|
5566 |
__READING__(f) |
|
5567 |
} |
|
5568 |
__READBYTE__(ret, f, &ch, _buffered, __INST(handleType)); |
|
5569 |
||
5570 |
if (ret > 0) { |
|
5571 |
pos = __INST(position); |
|
5572 |
if (__isSmallInteger(pos)) { |
|
5573 |
OBJ t; |
|
5574 |
||
5575 |
t = __MKINT(__intVal(pos) + 1); __INST(position) = t; __STORE(self, t); |
|
5576 |
} else { |
|
5577 |
__INST(position) = nil; /* i.e. do not know */ |
|
5578 |
} |
|
5579 |
if (__INST(binary) == true) { |
|
5580 |
RETURN ( __mkSmallInteger(ch) ); |
|
5581 |
} |
|
5582 |
RETURN ( __MKCHARACTER(ch) ); |
|
5583 |
} |
|
5584 |
||
5585 |
__INST(position) = nil; |
|
5586 |
if (ret < 0) { |
|
23538 | 5587 |
# ifdef __win32__ |
23743 | 5588 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5589 |
# endif |
23743 | 5590 |
error = __mkSmallInteger(__threadErrno); |
5591 |
} else /* ret == 0 */ { |
|
5592 |
__INST(hitEOF) = true; |
|
5593 |
} |
|
5594 |
} |
|
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5595 |
} |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5596 |
%}. |
21139 | 5597 |
hitEOF ifTrue:[^ nil]. |
16296 | 5598 |
error notNil ifTrue:[ |
23743 | 5599 |
lastErrorNumber := error. |
5600 |
^ self readError:error. |
|
16296 | 5601 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5602 |
handle isNil ifTrue:[^ self errorNotOpen]. |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5603 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5604 |
|
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5605 |
readAhead notNil ifTrue:[ |
23743 | 5606 |
c := readAhead. |
5607 |
readAhead := nil. |
|
5608 |
^ c. |
|
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5609 |
]. |
20679 | 5610 |
|
5611 |
"unknown handleType - future" |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5612 |
c := self nextByteFromFile:handle. |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5613 |
c isNil ifTrue:[ |
23743 | 5614 |
^ nil. |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5615 |
]. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5616 |
binary == true ifTrue:[ |
23743 | 5617 |
^ c |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5618 |
]. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5619 |
^ Character value:c |
23538 | 5620 |
|
5621 |
"Modified: / 22-11-2018 / 14:46:49 / Stefan Vogel" |
|
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5622 |
! |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5623 |
|
612 | 5624 |
peek |
5625 |
"return the element to be read next without advancing read position. |
|
5626 |
In binary mode, an integer is returned, otherwise a character. |
|
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5627 |
If there are no more elements, either an exception is thrown or nil is returned |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5628 |
- see #pastEndRead." |
612 | 5629 |
|
16296 | 5630 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
5631 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
5632 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5633 |
unsigned char c; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
5634 |
int ret, _buffered; |
216 | 5635 |
OBJ fp; |
3672
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
5636 |
OBJ ra; |
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
5637 |
|
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
5638 |
if ((ra = __INST(readAhead)) != nil) { |
23743 | 5639 |
if (__INST(binary) == true) { |
5640 |
RETURN ( ra ); |
|
5641 |
} |
|
5642 |
c = __intVal(ra); |
|
5643 |
RETURN ( __MKCHARACTER(c) ); |
|
3029
aa14768e0e6a
larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents:
3016
diff
changeset
|
5644 |
} |
aa14768e0e6a
larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents:
3016
diff
changeset
|
5645 |
|
1133 | 5646 |
__INST(lastErrorNumber) = nil; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
5647 |
|
12548 | 5648 |
if ((__INST(handleType) == nil) |
5649 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
5650 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5651 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 5652 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 5653 |
if (((fp = __INST(handle)) != nil) |
5654 |
&& (__INST(mode) != @symbol(writeonly)) |
|
5655 |
) { |
|
5656 |
f = __FILEVal(fp); |
|
5657 |
_buffered = (__INST(buffered) == true); |
|
5658 |
if (_buffered) { |
|
5659 |
__READING__(f) |
|
5660 |
} |
|
5661 |
__READBYTE__(ret, f, &c, _buffered, __INST(handleType)); |
|
5662 |
||
5663 |
if (ret > 0) { |
|
5664 |
__UNGETC__(c, f, _buffered); |
|
5665 |
||
5666 |
if (__INST(binary) == true) { |
|
5667 |
RETURN ( __mkSmallInteger(c) ); |
|
5668 |
} |
|
5669 |
RETURN ( __MKCHARACTER(c) ); |
|
5670 |
} |
|
5671 |
if (ret < 0) { |
|
23538 | 5672 |
# ifdef __win32__ |
23743 | 5673 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5674 |
# endif |
23743 | 5675 |
error = __mkSmallInteger(__threadErrno); |
5676 |
} else /* ret == 0 */ { |
|
5677 |
__INST(hitEOF) = true; |
|
5678 |
} |
|
5679 |
} |
|
1 | 5680 |
} |
159 | 5681 |
%}. |
21139 | 5682 |
hitEOF ifTrue:[^ self pastEndRead]. |
16296 | 5683 |
error notNil ifTrue:[ |
23743 | 5684 |
lastErrorNumber := error. |
5685 |
^ self readError:error. |
|
16296 | 5686 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5687 |
handle isNil ifTrue:[^ self errorNotOpen]. |
5420 | 5688 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
5689 |
||
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5690 |
readAhead isNil ifTrue:[ |
23743 | 5691 |
readAhead := self nextOrNil. |
5692 |
readAhead isNil ifTrue:[ |
|
5693 |
^ self pastEndRead. |
|
5694 |
]. |
|
5420 | 5695 |
]. |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5696 |
^ readAhead |
23538 | 5697 |
|
5698 |
"Modified: / 22-11-2018 / 14:50:10 / Stefan Vogel" |
|
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5699 |
! |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5700 |
|
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5701 |
peekOrNil |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5702 |
"return the element to be read next without advancing read position. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5703 |
In binary mode, an integer is returned, otherwise a character. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5704 |
If there are no more elements, nil is returned. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5705 |
Same as #atEnd and #peek in a single operation - speeding up some code" |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5706 |
|
16296 | 5707 |
|error| |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5708 |
%{ |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5709 |
FILEPOINTER f; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5710 |
unsigned char c; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5711 |
int ret, _buffered; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5712 |
OBJ fp; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5713 |
OBJ ra; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5714 |
|
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5715 |
if ((ra = __INST(readAhead)) != nil) { |
23743 | 5716 |
if (__INST(binary) == true) { |
5717 |
RETURN ( ra ); |
|
5718 |
} |
|
5719 |
c = __intVal(ra); |
|
5720 |
RETURN ( __MKCHARACTER(c) ); |
|
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5721 |
} |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5722 |
|
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5723 |
__INST(lastErrorNumber) = nil; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5724 |
|
12548 | 5725 |
if ((__INST(handleType) == nil) |
5726 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
5727 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5728 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 5729 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 5730 |
if (((fp = __INST(handle)) != nil) |
5731 |
&& (__INST(mode) != @symbol(writeonly)) |
|
5732 |
) { |
|
5733 |
f = __FILEVal(fp); |
|
5734 |
_buffered = (__INST(buffered) == true); |
|
5735 |
if (_buffered) { |
|
5736 |
__READING__(f) |
|
5737 |
} |
|
5738 |
__READBYTE__(ret, f, &c, _buffered, __INST(handleType)); |
|
5739 |
||
5740 |
if (ret > 0) { |
|
5741 |
__UNGETC__(c, f, _buffered); |
|
5742 |
||
5743 |
if (__INST(binary) == true) { |
|
5744 |
RETURN ( __mkSmallInteger(c) ); |
|
5745 |
} |
|
5746 |
RETURN ( __MKCHARACTER(c) ); |
|
5747 |
} |
|
5748 |
if (ret < 0) { |
|
23538 | 5749 |
# ifdef __win32__ |
23743 | 5750 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5751 |
# endif |
23743 | 5752 |
error = __mkSmallInteger(__threadErrno); |
5753 |
} else /* ret == 0 */ { |
|
5754 |
__INST(hitEOF) = true; |
|
5755 |
} |
|
5756 |
} |
|
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5757 |
} |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5758 |
%}. |
21139 | 5759 |
hitEOF ifTrue:[^ nil]. |
16296 | 5760 |
error notNil ifTrue:[ |
23743 | 5761 |
lastErrorNumber := error. |
5762 |
^ self readError:error. |
|
16296 | 5763 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5764 |
handle isNil ifTrue:[^ self errorNotOpen]. |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5765 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5766 |
|
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5767 |
readAhead isNil ifTrue:[ |
23743 | 5768 |
readAhead := self nextOrNil. |
5420 | 5769 |
]. |
5770 |
^ readAhead |
|
23538 | 5771 |
|
5772 |
"Modified: / 22-11-2018 / 14:50:22 / Stefan Vogel" |
|
1295 | 5773 |
! |
5774 |
||
5775 |
upToEnd |
|
5776 |
"return a collection of the elements up-to the end. |
|
20092 | 5777 |
Return an empty collection, if the stream-end is already at the end." |
5778 |
||
22849 | 5779 |
|chunkSize chunksAndCounts byteCount data offset contentsSpecies| |
20092 | 5780 |
|
5781 |
"adding to a ByteArray produces quadratic time-space |
|
5782 |
behavior - therefore we allocate chunks, and concatenate them |
|
5783 |
at the end." |
|
5784 |
||
5785 |
chunkSize := 4096. |
|
5786 |
byteCount := 0. |
|
22849 | 5787 |
contentsSpecies := self contentsSpecies. |
5788 |
||
1295 | 5789 |
[self atEnd] whileFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5790 |
|chunk cnt| |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5791 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5792 |
chunk := contentsSpecies uninitializedNew:chunkSize. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5793 |
cnt := self nextBytes:chunkSize into:chunk startingAt:1. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5794 |
cnt ~~ 0 ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5795 |
chunksAndCounts isNil ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5796 |
(cnt < chunkSize and:[self atEnd]) ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5797 |
"all data is in a single chunk, so we are done" |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5798 |
^ chunk copyFrom:1 to:cnt. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5799 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5800 |
chunksAndCounts := OrderedCollection new. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5801 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5802 |
chunksAndCounts add:chunk; add:cnt. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5803 |
byteCount := byteCount + cnt. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5804 |
] |
1295 | 5805 |
]. |
20092 | 5806 |
|
5807 |
"now, create one big array" |
|
22849 | 5808 |
data := contentsSpecies uninitializedNew:byteCount. |
20092 | 5809 |
offset := 1. |
22849 | 5810 |
1 to:chunksAndCounts size by:2 do:[:index | |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5811 |
|chunk cnt| |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5812 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5813 |
chunk := chunksAndCounts at:index. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5814 |
cnt := chunksAndCounts at:index+1. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5815 |
data replaceFrom:offset to:(offset + cnt - 1) with:chunk startingAt:1. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5816 |
offset := offset + cnt |
20092 | 5817 |
]. |
5818 |
^ data |
|
5819 |
||
1295 | 5820 |
|
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
5821 |
" |
20092 | 5822 |
'/dev/null' asFilename readStream upToEnd |
5823 |
'/proc/self/stat' asFilename readStream upToEnd |
|
22849 | 5824 |
'librun.so' asFilename readStream binary upToEnd |
20092 | 5825 |
|
20241 | 5826 |
self assert:('smalltalk.rc' asFilename readStream upToEnd size) |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5827 |
= ('smalltalk.rc' asFilename readStream size) |
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
5828 |
" |
22849 | 5829 |
|
5830 |
"Modified (format): / 09-05-2018 / 20:09:31 / stefan" |
|
612 | 5831 |
! ! |
5832 |
||
5420 | 5833 |
!ExternalStream methodsFor:'rel5 protocol'! |
5834 |
||
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5835 |
atEndFile:handle |
5420 | 5836 |
"for migration to rel5 only" |
5837 |
||
5838 |
self primitiveFailed |
|
5839 |
! |
|
5840 |
||
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5841 |
nextByteFromFile:handle |
5420 | 5842 |
"for migration to rel5 only" |
5843 |
||
5844 |
self primitiveFailed |
|
5845 |
! |
|
5846 |
||
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5847 |
nextPutByte:aByte toFile:handle |
5420 | 5848 |
"for migration to rel5 only" |
5849 |
||
5850 |
self primitiveFailed |
|
5851 |
! ! |
|
5852 |
||
612 | 5853 |
!ExternalStream methodsFor:'testing'! |
5854 |
||
5855 |
atEnd |
|
20675 | 5856 |
"return true, if position is at end. |
21032 | 5857 |
If a stream is at the end, the next read operation |
5858 |
would return or raise an exception immediately without waiting. |
|
5859 |
If a stream is not at the end, this may be a blocking operation |
|
5860 |
(see NonPositionableExternalStream)" |
|
612 | 5861 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
5862 |
%{ |
21221 | 5863 |
OBJ fp, lim; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5864 |
char c; |
612 | 5865 |
|
1133 | 5866 |
if (__INST(hitEOF) == true) { |
23743 | 5867 |
RETURN (true); |
3906
7f2d4a3b63e2
oops - readLimit was not handled in #atEnd
Claus Gittinger <cg@exept.de>
parents:
3878
diff
changeset
|
5868 |
} |
7875
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
5869 |
lim = __INST(readLimit); |
21221 | 5870 |
if (lim != nil && __signedLongIntVal(__INST(position)) >= __signedLongIntVal(lim)) { |
23743 | 5871 |
RETURN (true); |
612 | 5872 |
} |
5873 |
||
1133 | 5874 |
__INST(lastErrorNumber) = nil; |
5875 |
||
12548 | 5876 |
if ((__INST(handleType) == nil) |
5877 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
5878 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5879 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 5880 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 5881 |
if ((fp = __INST(handle)) != nil) { |
5882 |
int _buffered = (__INST(buffered) == true); |
|
5883 |
int ret; |
|
5884 |
FILEPOINTER f = __FILEVal(fp); |
|
5885 |
||
5886 |
if (_buffered) { |
|
5887 |
__READING__(f); |
|
5888 |
} else if (__INST(readAhead) != nil) { |
|
5889 |
RETURN (false); |
|
5890 |
} |
|
5891 |
||
5892 |
/* |
|
5893 |
* read ahead ... |
|
5894 |
*/ |
|
5895 |
do { |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5896 |
#ifdef __win32__ |
23743 | 5897 |
__READBYTE__(ret, f, &c, _buffered, __INST(handleType)); |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5898 |
#else /* not __win32__ */ |
23743 | 5899 |
__BEGIN_INTERRUPTABLE__ |
5900 |
__READBYTE__(ret, f, &c, _buffered, __INST(handleType)); |
|
5901 |
__END_INTERRUPTABLE__ |
|
21221 | 5902 |
#endif /* not __win32__ */ |
23743 | 5903 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
5904 |
if (ret > 0) { |
|
5905 |
__UNGETC__(c&0xff, f, _buffered); |
|
5906 |
RETURN (false); |
|
5907 |
} |
|
5908 |
if (ret == 0) { |
|
5909 |
__INST(hitEOF) = true; |
|
5910 |
RETURN (true); |
|
5911 |
} |
|
5912 |
/* ret < 0 -> error */ |
|
23538 | 5913 |
# ifdef __win32__ |
23743 | 5914 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5915 |
# endif |
23743 | 5916 |
__INST(lastErrorNumber) = __mkSmallInteger(__threadErrno); |
5917 |
} |
|
5918 |
// we do not raise an error here - the next read operation will raise the error. |
|
5919 |
RETURN(false); |
|
612 | 5920 |
} |
5921 |
%}. |
|
20675 | 5922 |
|
22578 | 5923 |
"/ we come here if the handle type is unknown |
5420 | 5924 |
"/ migration support |
20675 | 5925 |
^ self atEndFile:handle |
3906
7f2d4a3b63e2
oops - readLimit was not handled in #atEnd
Claus Gittinger <cg@exept.de>
parents:
3878
diff
changeset
|
5926 |
|
23538 | 5927 |
"Modified: / 30-10-1998 / 20:16:06 / cg" |
5928 |
"Modified: / 22-11-2018 / 14:39:54 / Stefan Vogel" |
|
612 | 5929 |
! |
5930 |
||
10995 | 5931 |
gotErrorOrEOF |
20675 | 5932 |
"answer true, if amn error or eof has been occurred on the stream" |
10995 | 5933 |
|
21139 | 5934 |
^ hitEOF or:[lastErrorNumber notNil] |
10995 | 5935 |
! |
5936 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5937 |
isBinary |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5938 |
"return true, if the stream is in binary (as opposed to text-) mode. |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5939 |
The default when created is false." |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5940 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5941 |
^ binary |
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
5942 |
! |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
5943 |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5944 |
isBlocking |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5945 |
"return true, if O_NONBLOCK is NOT set in the fileDescriptor (probably UNIX specific)" |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
5946 |
|
22195 | 5947 |
|fd| |
5948 |
||
5949 |
fd := self fileDescriptor. |
|
5950 |
"self fileDescriptor may set handle to nil" |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5951 |
handle isNil ifTrue:[^ self errorNotOpen]. |
22195 | 5952 |
^ OperatingSystem isBlockingOn:fd |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5953 |
! |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5954 |
|
22694 | 5955 |
isExecutor |
5956 |
"am I an executor and no real stream object?" |
|
5957 |
||
5958 |
^ mode == #executor. |
|
5959 |
||
5960 |
"Created: / 23-04-2018 / 18:17:40 / stefan" |
|
5961 |
! |
|
5962 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5963 |
isExternalStream |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5964 |
"return true, if the receiver is some kind of externalStream; |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5965 |
true is returned here - the method redefined from Object." |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5966 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5967 |
^ true |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5968 |
! |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5969 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5970 |
isOpen |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5971 |
"return true, if this stream is open" |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5972 |
|
22694 | 5973 |
"executors are only used to finalize - they are not really open and are closed with #closeFile, |
5974 |
which does not check for #isOpen" |
|
5975 |
^ handle notNil and:[self isExecutor not] |
|
5976 |
||
5977 |
"Modified: / 23-04-2018 / 18:28:07 / stefan" |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5978 |
! |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5979 |
|
22978 | 5980 |
isPipeStream |
5981 |
"return true, if this stream is a pipe" |
|
5982 |
||
5983 |
^ false |
|
5984 |
! |
|
5985 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5986 |
isReadable |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5987 |
"return true, if this stream can be read from" |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5988 |
|
21139 | 5989 |
^ mode ~~ #writeonly |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5990 |
! |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5991 |
|
22978 | 5992 |
isSocket |
5993 |
"return true, if this stream is a socket" |
|
5994 |
||
5995 |
^ false |
|
5996 |
! |
|
5997 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5998 |
isWritable |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5999 |
"return true, if this stream can be written to" |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
6000 |
|
21139 | 6001 |
^ mode ~~ #readonly |
612 | 6002 |
! ! |
6003 |
||
6004 |
!ExternalStream methodsFor:'waiting for I/O'! |
|
6005 |
||
5101 | 6006 |
canBeSelected |
6007 |
"return true, if this stream can be selected upon" |
|
6008 |
||
6009 |
^ OperatingSystem supportsSelect |
|
6010 |
! |
|
6011 |
||
20104 | 6012 |
numAvailableForRead |
20241 | 6013 |
"answer the number of bytes available for reading" |
6014 |
||
20104 | 6015 |
|available| |
6016 |
||
6017 |
handle isNil ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
6018 |
^ self errorNotOpen |
20104 | 6019 |
]. |
6020 |
mode == #writeonly ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
6021 |
^ self errorWriteOnly |
20104 | 6022 |
]. |
21238 | 6023 |
available := OperatingSystem numAvailableForReadOn:self fileHandle. |
20104 | 6024 |
readAhead notNil ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
6025 |
available := available + 1 |
20104 | 6026 |
]. |
6027 |
^ available. |
|
6028 |
||
6029 |
" |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
6030 |
'/etc/hosts' asFilename readStream numAvailableForRead |
21130 | 6031 |
" |
20104 | 6032 |
! |
6033 |
||
18327 | 6034 |
readWaitWithTimeoutMs:timeoutOrNil |
612 | 6035 |
"suspend the current process, until the receiver |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
6036 |
becomes ready for reading or a timeout (in milliseconds) expired. |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
6037 |
If data is already available, return immediate. |
20259 | 6038 |
Return true if a timeout occurred (i.e. false, if data is available). |
612 | 6039 |
The other threads are not affected by the wait." |
6040 |
||
16480 | 6041 |
|fd inputSema hasTimedout wasBlocked| |
612 | 6042 |
|
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
6043 |
readAhead notNil ifTrue:[^ false]. |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
6044 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
6045 |
handle isNil ifTrue:[^ self errorNotOpen]. |
612 | 6046 |
mode == #writeonly ifTrue:[^ self errorWriteOnly]. |
6047 |
||
21238 | 6048 |
fd := self fileHandle. |
612 | 6049 |
(OperatingSystem readCheck:fd) ifTrue:[^ false]. |
6050 |
||
20104 | 6051 |
"cannot do a readWait (which means possible suspend), |
6052 |
if the processor is not yet initialized; i.e. if a read is attempted |
|
6053 |
during early startup. |
|
6054 |
This may happen, for example, if a MiniDebugger is entered, before |
|
6055 |
process scheduling has been setup. |
|
6056 |
In this case, all I/O operations here will be blocking." |
|
6057 |
||
23726 | 6058 |
Smalltalk isInitialized ifFalse:[ |
25142
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
6059 |
^ false |
23726 | 6060 |
]. |
20104 | 6061 |
|
612 | 6062 |
wasBlocked := OperatingSystem blockInterrupts. |
25134 | 6063 |
(OperatingSystem readCheck:fd) ifTrue:[ |
25142
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
6064 |
hasTimedout := false |
25134 | 6065 |
] ifFalse:[ |
25142
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
6066 |
inputSema := Semaphore name:'readWait'. |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
6067 |
hasTimedout := [ |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
6068 |
Processor signal:inputSema onInput:fd. |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
6069 |
(inputSema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil. |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
6070 |
] ifCurtailed:[ |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
6071 |
Processor disableSemaphore:inputSema. |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
6072 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
6073 |
]. |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
6074 |
hasTimedout ifTrue:[ |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
6075 |
Processor disableSemaphore:inputSema. |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
6076 |
]. |
16480 | 6077 |
]. |
612 | 6078 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
16480 | 6079 |
^ hasTimedout |
22177 | 6080 |
|
6081 |
"Modified: / 09-08-2017 / 11:53:58 / cg" |
|
23726 | 6082 |
"Modified: / 12-02-2019 / 20:56:53 / Stefan Vogel" |
612 | 6083 |
! |
6084 |
||
22683 | 6085 |
readWriteWaitWithTimeoutMs:timeoutOrNil |
6086 |
"suspend the current process, until the receiver |
|
6087 |
becomes ready for reading or writing or a timeout (in milliseconds) expired. |
|
6088 |
Return true if a timeout occurred (i.e. false, if data is available). |
|
6089 |
Return immediate if the receiver is already ready. |
|
6090 |
The other threads are not affected by the wait." |
|
6091 |
||
6092 |
|fd sema hasTimedout wasBlocked| |
|
6093 |
||
6094 |
readAhead notNil ifTrue:[^ false]. |
|
6095 |
handle isNil ifTrue:[ |
|
23743 | 6096 |
^ self errorNotOpen |
22683 | 6097 |
]. |
6098 |
||
6099 |
fd := self fileHandle. |
|
6100 |
(OperatingSystem readWriteCheck:fd) ifTrue:[^ false]. |
|
6101 |
||
6102 |
wasBlocked := OperatingSystem blockInterrupts. |
|
6103 |
sema := Semaphore name:'readWriteWait'. |
|
23726 | 6104 |
hasTimedout := [ |
23743 | 6105 |
Processor |
6106 |
signal:sema onOutput:fd; |
|
6107 |
signal:sema onInput:fd. |
|
6108 |
(sema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil. |
|
22683 | 6109 |
] ifCurtailed:[ |
23743 | 6110 |
Processor disableSemaphore:sema. |
6111 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
22683 | 6112 |
]. |
6113 |
hasTimedout ifTrue:[ |
|
23743 | 6114 |
Processor disableSemaphore:sema. |
22683 | 6115 |
]. |
6116 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
6117 |
^ hasTimedout |
|
6118 |
||
6119 |
"Modified: / 09-08-2017 / 11:54:03 / cg" |
|
23726 | 6120 |
"Modified: / 12-02-2019 / 20:23:41 / Stefan Vogel" |
22683 | 6121 |
! |
6122 |
||
6123 |
writeExceptionWaitWithTimeoutMs:timeoutOrNil |
|
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
6124 |
"suspend the current process, until the receiver |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
6125 |
becomes ready for reading or writing or a timeout (in milliseconds) expired. |
20259 | 6126 |
Return true if a timeout occurred (i.e. false, if data is available). |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
6127 |
Return immediate if the receiver is already ready. |
5506 | 6128 |
The other threads are not affected by the wait." |
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
6129 |
|
16480 | 6130 |
|fd sema hasTimedout wasBlocked| |
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
6131 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
6132 |
handle isNil ifTrue:[ |
23743 | 6133 |
^ self errorNotOpen |
18956 | 6134 |
]. |
6135 |
||
21238 | 6136 |
fd := self fileHandle. |
18956 | 6137 |
(OperatingSystem writeExceptionCheck:fd) ifTrue:[^ false]. |
6138 |
||
6139 |
wasBlocked := OperatingSystem blockInterrupts. |
|
22177 | 6140 |
sema := Semaphore name:'writeExceptionWait'. |
23726 | 6141 |
hasTimedout := [ |
23743 | 6142 |
Processor |
6143 |
signal:sema onOutput:fd; |
|
6144 |
signal:sema onException:fd. |
|
6145 |
(sema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil. |
|
18956 | 6146 |
] ifCurtailed:[ |
23743 | 6147 |
Processor disableSemaphore:sema. |
6148 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
18956 | 6149 |
]. |
22683 | 6150 |
hasTimedout ifTrue:[ |
23743 | 6151 |
Processor disableSemaphore:sema. |
18956 | 6152 |
]. |
6153 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
6154 |
^ hasTimedout |
|
22177 | 6155 |
|
6156 |
"Modified: / 09-08-2017 / 11:54:10 / cg" |
|
23726 | 6157 |
"Modified: / 12-02-2019 / 20:24:03 / Stefan Vogel" |
18956 | 6158 |
! |
6159 |
||
22683 | 6160 |
writeWaitWithTimeoutMs:timeoutOrNil |
612 | 6161 |
"suspend the current process, until the receiver |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
6162 |
becomes ready for writing or a timeout (in milliseconds) expired. |
20259 | 6163 |
Return true if a timeout occurred (i.e. false, if data is available). |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
6164 |
Return immediate if the receiver is already ready. |
612 | 6165 |
The other threads are not affected by the wait." |
6166 |
||
16480 | 6167 |
|fd outputSema hasTimedout wasBlocked| |
612 | 6168 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
6169 |
handle isNil ifTrue:[ |
25142
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
6170 |
^ self errorNotOpen |
612 | 6171 |
]. |
6172 |
mode == #readonly ifTrue:[ |
|
25142
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
6173 |
^ self errorReadOnly |
612 | 6174 |
]. |
25136 | 6175 |
%{ |
6176 |
#ifdef __win32__ |
|
6177 |
{ |
|
25142
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
6178 |
FILEPOINTER f = __FILEVal(__INST(handle)); |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
6179 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
6180 |
RETURN(false); |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
6181 |
} |
25136 | 6182 |
} |
6183 |
#endif |
|
6184 |
%}. |
|
612 | 6185 |
|
21238 | 6186 |
fd := self fileHandle. |
612 | 6187 |
(OperatingSystem writeCheck:fd) ifTrue:[^ false]. |
6188 |
||
6189 |
wasBlocked := OperatingSystem blockInterrupts. |
|
24778 | 6190 |
"/ check again - now inside lock |
25134 | 6191 |
(OperatingSystem writeCheck:fd) ifTrue:[ |
25142
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
6192 |
hasTimedout := false. |
25134 | 6193 |
] ifFalse:[ |
25142
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
6194 |
outputSema := Semaphore name:'writeWait'. |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
6195 |
hasTimedout := [ |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
6196 |
Processor signal:outputSema onOutput:fd. |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
6197 |
(outputSema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil. |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
6198 |
] ifCurtailed:[ |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
6199 |
Processor disableSemaphore:outputSema. |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
6200 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
6201 |
]. |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
6202 |
hasTimedout ifTrue:[ |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
6203 |
Processor disableSemaphore:outputSema. |
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
6204 |
]. |
16480 | 6205 |
]. |
612 | 6206 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
16480 | 6207 |
^ hasTimedout |
22177 | 6208 |
|
6209 |
"Modified: / 09-08-2017 / 11:54:14 / cg" |
|
23726 | 6210 |
"Modified: / 12-02-2019 / 20:25:09 / Stefan Vogel" |
612 | 6211 |
! ! |
6212 |
||
6213 |
!ExternalStream methodsFor:'writing'! |
|
6214 |
||
6215 |
cr |
|
6216 |
"append an end-of-line character (or CRLF if in crlf mode). |
|
6217 |
reimplemented for speed" |
|
6218 |
||
23538 | 6219 |
|error| |
6220 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
6221 |
%{ |
12548 | 6222 |
if ((__INST(handleType) == nil) |
6223 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
6224 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 6225 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
6226 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
23743 | 6227 |
OBJ fp; |
6228 |
||
6229 |
__INST(lastErrorNumber) = nil; |
|
6230 |
if (((fp = __INST(handle)) != nil) |
|
6231 |
&& (__INST(mode) != @symbol(readonly)) |
|
6232 |
&& (__INST(binary) != true) |
|
6233 |
) { |
|
6234 |
FILEPOINTER f = __FILEVal(fp); |
|
6235 |
int _buffered = (__INST(buffered) == true); |
|
6236 |
int len, cnt; |
|
6237 |
char *cp; |
|
6238 |
||
6239 |
if (_buffered) { |
|
6240 |
__WRITING__(f) |
|
6241 |
} |
|
6242 |
{ |
|
6243 |
OBJ mode = __INST(eolMode); |
|
6244 |
||
6245 |
if (mode == @symbol(cr)) { |
|
6246 |
cp = "\r"; len = 1; |
|
6247 |
} else if (mode == @symbol(crlf)) { |
|
6248 |
cp = "\r\n"; len = 2; |
|
6249 |
} else if (mode == @symbol(eot)) { |
|
6250 |
cp = "\004"; len = 1; |
|
6251 |
} else if (mode == @symbol(etx)) { |
|
6252 |
cp = "\003"; len = 1; |
|
6253 |
} else { |
|
6254 |
cp = "\n"; len = 1; |
|
6255 |
} |
|
6256 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6257 |
#ifdef __win32__ |
23743 | 6258 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6259 |
cnt = __win32_fwrite(cp, 1, len, f); |
|
6260 |
} else |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
6261 |
#endif |
23743 | 6262 |
{ |
6263 |
__WRITEBYTES__(cnt, f, cp, len, _buffered, __INST(handleType)); |
|
6264 |
} |
|
6265 |
if (cnt == len) { |
|
6266 |
if (__isSmallInteger(__INST(position))) { |
|
6267 |
INT np = __intVal(__INST(position)) + len; |
|
6268 |
OBJ t; |
|
6269 |
||
6270 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
6271 |
} else { |
|
6272 |
__INST(position) = nil; /* i.e: don't know */ |
|
6273 |
} |
|
6274 |
RETURN ( self ); |
|
6275 |
} |
|
23538 | 6276 |
# ifdef __win32__ |
23743 | 6277 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 6278 |
# endif |
23743 | 6279 |
error = __mkSmallInteger(__threadErrno); |
6280 |
} |
|
612 | 6281 |
} |
6282 |
%}. |
|
23538 | 6283 |
error notNil ifTrue:[ |
23743 | 6284 |
lastErrorNumber := error. |
6285 |
self writeError:error. |
|
6286 |
^ self |
|
23538 | 6287 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
6288 |
handle isNil ifTrue:[self errorNotOpen. ^ self]. |
2326 | 6289 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
21139 | 6290 |
binary ifTrue:[self errorBinary. ^ self]. |
5414 | 6291 |
|
17426
6e49243ce4e0
fix: code treated everything but nl,cr,crnl symbols als cr (by accident).
Claus Gittinger <cg@exept.de>
parents:
17420
diff
changeset
|
6292 |
(eolMode == #cr) ifTrue:[ |
23743 | 6293 |
self nextPut:(Character return). |
6294 |
^ self |
|
17426
6e49243ce4e0
fix: code treated everything but nl,cr,crnl symbols als cr (by accident).
Claus Gittinger <cg@exept.de>
parents:
17420
diff
changeset
|
6295 |
]. |
6e49243ce4e0
fix: code treated everything but nl,cr,crnl symbols als cr (by accident).
Claus Gittinger <cg@exept.de>
parents:
17420
diff
changeset
|
6296 |
(eolMode == #crlf) ifTrue:[ |
23743 | 6297 |
self nextPut:(Character return). |
17426
6e49243ce4e0
fix: code treated everything but nl,cr,crnl symbols als cr (by accident).
Claus Gittinger <cg@exept.de>
parents:
17420
diff
changeset
|
6298 |
]. |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
6299 |
self nextPut:(Character nl). |
5414 | 6300 |
^ self |
23538 | 6301 |
|
6302 |
"Modified: / 22-11-2018 / 14:41:46 / Stefan Vogel" |
|
612 | 6303 |
! |
6304 |
||
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6305 |
flush |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6306 |
"write all buffered data - ignored if unbuffered" |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6307 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6308 |
%{ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6309 |
__INST(lastErrorNumber) = nil; |
12548 | 6310 |
if ((__INST(handleType) == nil) |
6311 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
6312 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
6313 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
25136 | 6314 |
OBJ fp; |
6315 |
int _buffered = (__INST(buffered) == true); |
|
6316 |
||
6317 |
if ((fp = __INST(handle)) != nil) { |
|
6318 |
if (__INST(mode) != @symbol(readonly)) { |
|
6319 |
if (1 /* _buffered */) { |
|
6320 |
FILEPOINTER f = __FILEVal(fp); |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6321 |
#ifdef __win32__ |
25136 | 6322 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6323 |
__win32_fflush(f); |
|
6324 |
} else { |
|
6325 |
int rslt; |
|
6326 |
||
6327 |
do { |
|
6328 |
__threadErrno = 0; |
|
6329 |
rslt = __STX_C_CALL1("fflush", fflush, f); |
|
6330 |
} while((rslt < 0) && (__threadErrno == EINTR)); |
|
6331 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6332 |
#else /* ! __win32__ */ |
25136 | 6333 |
__BEGIN_INTERRUPTABLE__ |
6334 |
FFLUSH(f); |
|
6335 |
__END_INTERRUPTABLE__ |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6336 |
#endif /* ! __win32__ */ |
25136 | 6337 |
} |
6338 |
} |
|
6339 |
} |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6340 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6341 |
%} |
24045 | 6342 |
|
6343 |
"Modified: / 03-04-2019 / 16:15:11 / Claus Gittinger" |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6344 |
! |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6345 |
|
612 | 6346 |
nextPut:aCharacter |
24628 | 6347 |
"write the argument, aCharacter - raise an error if failed. |
24654 | 6348 |
Answer aCharacter. |
6349 |
Only single-byte characters are supported here" |
|
612 | 6350 |
|
16296 | 6351 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
6352 |
%{ |
18364 | 6353 |
#ifdef __SCHTEAM__ |
6354 |
STObject handle = self.instVarAt(I_handle); |
|
6355 |
||
6356 |
if ((handle != STObject.Nil) |
|
6357 |
&& (aCharacter.isSTCharacter())) { |
|
25136 | 6358 |
handle.writeChar( aCharacter ); |
6359 |
self.instVarAt_put(I_position, STObject.Nil); |
|
6360 |
return __c__._RETURN(aCharacter); |
|
18364 | 6361 |
} |
6362 |
#else |
|
17332 | 6363 |
__INST(lastErrorNumber) = nil; |
6364 |
if ((__INST(handleType) == nil) |
|
6365 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
6366 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
6367 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
6368 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
25136 | 6369 |
OBJ fp; |
6370 |
||
6371 |
if (((fp = __INST(handle)) != nil) |
|
6372 |
&& (__INST(mode) != @symbol(readonly)) |
|
6373 |
) { |
|
6374 |
FILEPOINTER f = __FILEVal(fp); |
|
6375 |
int _buffered = (__INST(buffered) == true); |
|
6376 |
int cnt; |
|
6377 |
char buff[2]; |
|
6378 |
int nBytes = 1; |
|
6379 |
||
6380 |
if (__INST(binary) != true) { |
|
6381 |
if (__isCharacter(aCharacter)) { |
|
6382 |
unsigned int codePoint = __intVal(__characterVal(aCharacter)); |
|
6383 |
if (codePoint <= 0xFF) { |
|
6384 |
unsigned char c = codePoint; |
|
6385 |
buff[0] = c; nBytes = 1; |
|
6386 |
||
6387 |
if (c == '\n') { |
|
6388 |
OBJ mode = __INST(eolMode); |
|
6389 |
if (mode == @symbol(nl)) { |
|
6390 |
// no EOL translation |
|
6391 |
} else if (mode == nil) { |
|
6392 |
// no EOL translation |
|
6393 |
} else if (mode == @symbol(cr)) { |
|
6394 |
buff[0] = '\r'; |
|
6395 |
} else if (mode == @symbol(eot)) { |
|
6396 |
buff[0] = '\004'; |
|
6397 |
} else if (mode == @symbol(etx)) { |
|
6398 |
buff[0] = '\003'; |
|
6399 |
} else if (mode == @symbol(crlf)) { |
|
6400 |
buff[0] = '\r'; |
|
6401 |
buff[1] = '\n'; |
|
6402 |
nBytes = 2; |
|
6403 |
} |
|
6404 |
} |
|
17332 | 6405 |
doWrite: |
25136 | 6406 |
if (! f) { |
6407 |
fprintf(stderr, "oops - fileHandle is NULL in nextPut:\n"); |
|
6408 |
__INST(handle) = nil; |
|
6409 |
goto out; |
|
6410 |
} |
|
6411 |
||
6412 |
if (_buffered) { |
|
6413 |
__WRITING__(f) |
|
6414 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6415 |
# ifdef __win32__ |
25136 | 6416 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6417 |
cnt = __win32_fwrite(buff, 1, nBytes, f); |
|
6418 |
} else |
|
18364 | 6419 |
# endif |
25136 | 6420 |
{ |
6421 |
__WRITEBYTES__(cnt, f, buff, nBytes, _buffered, __INST(handleType)); |
|
6422 |
} |
|
6423 |
if (cnt == nBytes) { |
|
6424 |
if (__isSmallInteger(__INST(position))) { |
|
6425 |
INT np = __intVal(__INST(position)) + nBytes; |
|
6426 |
OBJ t; |
|
6427 |
||
6428 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
6429 |
} else { |
|
6430 |
__INST(position) = nil; /* i.e. do not know */ |
|
6431 |
} |
|
6432 |
RETURN ( aCharacter ); |
|
6433 |
} |
|
23538 | 6434 |
# ifdef __win32__ |
25136 | 6435 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 6436 |
# endif |
25136 | 6437 |
error = __mkSmallInteger(__threadErrno); |
6438 |
} |
|
6439 |
} |
|
6440 |
} else { |
|
6441 |
if (__isSmallInteger(aCharacter)) { |
|
6442 |
unsigned char c = __intVal(aCharacter); |
|
6443 |
buff[0] = c; nBytes = 1; |
|
6444 |
goto doWrite; |
|
6445 |
} |
|
6446 |
} |
|
6447 |
} |
|
17332 | 6448 |
} |
6449 |
out: ; |
|
18364 | 6450 |
#endif /* not SCHTEAM */ |
17332 | 6451 |
%}. |
6452 |
error notNil ifTrue:[ |
|
25136 | 6453 |
lastErrorNumber := error. |
6454 |
self writeError:error. |
|
6455 |
^ aCharacter |
|
17332 | 6456 |
]. |
6457 |
handle isNil ifTrue:[self errorNotOpen. ^ self]. |
|
6458 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
|
21139 | 6459 |
binary == true ifTrue:[ |
25136 | 6460 |
aCharacter isInteger ifFalse:[ |
6461 |
self argumentMustBeInteger. |
|
6462 |
^ aCharacter. |
|
6463 |
]. |
|
21139 | 6464 |
] ifFalse:[ |
25136 | 6465 |
(aCharacter isCharacter not |
6466 |
or:[aCharacter codePoint > 16rFF]) ifTrue:[ |
|
6467 |
self argumentMustBeCharacter. |
|
6468 |
^ aCharacter. |
|
6469 |
]. |
|
17332 | 6470 |
]. |
6471 |
"/ migration support |
|
6472 |
self |
|
25136 | 6473 |
nextPutByte:aCharacter asInteger |
6474 |
toFile:handle. |
|
24646 | 6475 |
^ aCharacter |
23538 | 6476 |
|
6477 |
"Modified: / 22-11-2018 / 14:47:13 / Stefan Vogel" |
|
17332 | 6478 |
! |
6479 |
||
17418 | 6480 |
nextPutAll:aCollection |
6481 |
"write all elements of the argument, aCollection. |
|
24640 | 6482 |
Answer the receiver. |
17418 | 6483 |
Reimplemented for speed when writing strings or byteArrays. |
6484 |
For others, falls back to general method in superclass." |
|
6485 |
||
6486 |
|error| |
|
6487 |
%{ |
|
18364 | 6488 |
#ifdef __SCHTEAM__ |
6489 |
STObject handle = self.instVarAt(I_handle); |
|
6490 |
||
6491 |
if ((handle != STObject.Nil) |
|
6492 |
&& (aCollection.isSTString())) { |
|
25136 | 6493 |
handle.writeCharacters( aCollection.asSTString().characters ); |
6494 |
self.instVarAt_put(I_position, STObject.Nil); |
|
6495 |
return __c__._RETURN_self(); |
|
18364 | 6496 |
} |
6497 |
#else |
|
17418 | 6498 |
|
6499 |
__INST(lastErrorNumber) = nil; |
|
6500 |
||
6501 |
if ((__INST(handleType) == nil) |
|
6502 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
6503 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
6504 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
6505 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
25136 | 6506 |
OBJ fp; |
6507 |
||
6508 |
if (((fp = __INST(handle)) != nil) |
|
6509 |
&& (__INST(mode) != @symbol(readonly)) |
|
6510 |
) { |
|
6511 |
INT len, cnt; |
|
6512 |
INT o_offs; |
|
6513 |
FILEPOINTER f = __FILEVal(fp); |
|
6514 |
int _buffered = (__INST(buffered) == true); |
|
6515 |
||
6516 |
if (! f) { |
|
6517 |
fprintf(stderr, "oops - fileHandle is NULL in nextPutAll:\n"); |
|
6518 |
__INST(handle) = nil; |
|
6519 |
goto out; |
|
6520 |
} |
|
6521 |
if (_buffered) { |
|
6522 |
__WRITING__(f) |
|
6523 |
} |
|
6524 |
||
6525 |
if (__isStringLike(aCollection)) { |
|
6526 |
OBJ mode = __INST(eolMode); |
|
6527 |
char *stringP = __stringVal(aCollection); |
|
6528 |
len = __stringSize(aCollection); |
|
6529 |
||
6530 |
if (__INST(binary) != true |
|
6531 |
&& ((mode == @symbol(cr)) |
|
6532 |
|| (mode == @symbol(etx)) |
|
6533 |
|| (mode == @symbol(eot)) |
|
6534 |
|| (mode == @symbol(crlf))) |
|
6535 |
&& memchr(stringP, '\n', len) != NULL) |
|
6536 |
{ |
|
6537 |
// there is a '\n' to be translated, replace it into a buffer |
|
6538 |
||
6539 |
char *end; |
|
6540 |
char sep[2]; |
|
6541 |
int sepLen = 1; |
|
6542 |
int bufLen; |
|
6543 |
char *buf, *endBuf, *sp, *dp; |
|
6544 |
||
6545 |
sep[0] = '\n'; |
|
6546 |
if (mode == @symbol(crlf)) { |
|
6547 |
sep[0] = '\r'; sep[1] = '\n'; sepLen = 2; |
|
6548 |
} else if (mode == @symbol(cr)) { |
|
6549 |
sep[0] = '\r'; |
|
6550 |
} else if (mode == @symbol(eot)) { |
|
6551 |
sep[0] = '\004'; |
|
6552 |
} else if (mode == @symbol(etx)) { |
|
6553 |
sep[0] = '\003'; |
|
6554 |
} |
|
6555 |
||
6556 |
// estimate size of buffer - assume every 4th char is a separator |
|
6557 |
bufLen = (sepLen == 1) ? len : (len + ((len/4) + 1) * sepLen); |
|
6558 |
buf = (char *)malloc(bufLen); |
|
6559 |
if (buf == NULL) { |
|
6560 |
error = __mkSmallInteger(ENOMEM); |
|
6561 |
goto out; |
|
6562 |
} |
|
6563 |
||
6564 |
endBuf = buf + bufLen; |
|
6565 |
end = stringP + len; |
|
6566 |
for (sp = stringP, dp = buf; sp < end; sp++) { |
|
6567 |
char c; |
|
6568 |
||
6569 |
if ((dp+sepLen) >= endBuf) { |
|
6570 |
char *newBuf; |
|
6571 |
||
6572 |
bufLen = bufLen * 2; |
|
6573 |
newBuf = (char *)realloc(buf, bufLen); |
|
6574 |
if (newBuf == NULL) { |
|
6575 |
free(buf); |
|
6576 |
error = __mkSmallInteger(ENOMEM); |
|
6577 |
goto out; |
|
6578 |
} |
|
6579 |
endBuf = newBuf + bufLen; |
|
6580 |
dp = newBuf + (dp-buf); |
|
6581 |
buf = newBuf; |
|
6582 |
} |
|
6583 |
||
6584 |
if ((c = *sp) != '\n') { |
|
6585 |
*dp++ = c; |
|
6586 |
} else { |
|
6587 |
*dp++ = sep[0]; |
|
6588 |
if (sepLen == 2) { |
|
6589 |
*dp++ = sep[1]; |
|
6590 |
}; |
|
6591 |
} |
|
6592 |
} |
|
6593 |
||
6594 |
len = dp - buf; |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6595 |
# ifdef __win32__ |
25136 | 6596 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6597 |
cnt = __win32_fwrite(buf, 1, len, f); |
|
6598 |
} else |
|
18364 | 6599 |
# endif |
25136 | 6600 |
{ |
6601 |
__WRITEBYTES__(cnt, f, buf, len, _buffered, __INST(handleType)); |
|
6602 |
} |
|
6603 |
free(buf); |
|
6604 |
} else { // No EOL conversion needed |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6605 |
# ifdef __win32__ |
25136 | 6606 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6607 |
cnt = __win32_fwrite(stringP, 1, len, f); |
|
6608 |
} else |
|
18364 | 6609 |
# endif |
25136 | 6610 |
{ |
6611 |
o_offs = stringP - (char *)__InstPtr(aCollection); |
|
6612 |
__WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs, len, _buffered, __INST(handleType)); |
|
6613 |
} |
|
6614 |
} |
|
6615 |
} else { // Not a String |
|
6616 |
if (__INST(binary) == true) { |
|
6617 |
INT offs; |
|
6618 |
||
6619 |
if (__isByteArrayLike(aCollection)) { |
|
6620 |
offs = 0; |
|
6621 |
len = __byteArraySize(aCollection); |
|
6622 |
} else if (__isBytes(aCollection)) { |
|
6623 |
offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars)); |
|
6624 |
len = __byteArraySize(aCollection) - offs; |
|
6625 |
} else |
|
6626 |
goto out; |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6627 |
# ifdef __win32__ |
25136 | 6628 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6629 |
cnt = __win32_fwrite(__stringVal(aCollection), 1, len, f); |
|
6630 |
} else |
|
18364 | 6631 |
# endif |
25136 | 6632 |
{ |
6633 |
o_offs = (char *)(__ByteArrayInstPtr(aCollection)->ba_element) - (char *)__InstPtr(aCollection); |
|
6634 |
o_offs += offs; |
|
6635 |
__WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs, len, _buffered, __INST(handleType)); |
|
6636 |
} |
|
6637 |
} else // Not binary mode |
|
6638 |
goto out; |
|
6639 |
} |
|
6640 |
||
6641 |
// Now check for errors |
|
6642 |
if (cnt == len) { |
|
6643 |
if (__isSmallInteger(__INST(position))) { |
|
6644 |
INT np = __intVal(__INST(position)) + len; |
|
6645 |
OBJ t; |
|
6646 |
||
6647 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
6648 |
} else { |
|
6649 |
__INST(position) = nil; /* i.e. do not know */ |
|
6650 |
} |
|
6651 |
RETURN (self); |
|
6652 |
} |
|
23538 | 6653 |
# ifdef __win32__ |
25136 | 6654 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 6655 |
# endif |
25136 | 6656 |
error = __mkSmallInteger(__threadErrno); |
6657 |
fprintf(stderr, "cnt=%"_ld_" len=%"_ld_"\n", (INT)cnt, (INT)len); |
|
6658 |
} |
|
17418 | 6659 |
} |
6660 |
out: ; |
|
18364 | 6661 |
#endif /* not SCHTEAM */ |
17418 | 6662 |
%}. |
6663 |
error notNil ifTrue:[ |
|
25136 | 6664 |
lastErrorNumber := error. |
6665 |
self writeError:error. |
|
6666 |
^ self |
|
17418 | 6667 |
]. |
6668 |
handle isNil ifTrue:[self errorNotOpen. ^ self]. |
|
6669 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
|
6670 |
||
24628 | 6671 |
super nextPutAll:aCollection |
23538 | 6672 |
|
6673 |
"Modified: / 22-11-2018 / 11:16:12 / Stefan Vogel" |
|
17418 | 6674 |
! |
6675 |
||
17608 | 6676 |
nextPutAll:initialWriteCount from:buffer startingAt:initialOffset |
22232 | 6677 |
"append count elements with index starting at initialOffset |
6678 |
of the argument, buffer onto the receiver. |
|
6679 |
This is only allowed, if the receiver supports writing. |
|
6680 |
Answer the number of elements that were appended. |
|
6681 |
Buffer should be a byte collection. |
|
20270 | 6682 |
I don't know how to write non-bytes to an external stream, but let superclass handle this." |
17608 | 6683 |
|
22234 | 6684 |
buffer isSingleByteCollection ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
6685 |
^ self nextPutBytes:initialWriteCount from:buffer startingAt:initialOffset. |
17608 | 6686 |
]. |
6687 |
||
6688 |
^ super nextPutAll:initialWriteCount from:buffer startingAt:initialOffset |
|
6689 |
! |
|
6690 |
||
17418 | 6691 |
nextPutAll:aCollection startingAt:start to:stop |
6692 |
"write a range of elements of the argument, aCollection. |
|
6693 |
Reimplemented for speed when writing strings or byteArrays. |
|
6694 |
For others, falls back to general method in superclass." |
|
6695 |
||
6696 |
|error| |
|
6697 |
||
6698 |
%{ |
|
6699 |
__INST(lastErrorNumber) = nil; |
|
6700 |
if ((__INST(handleType) == nil) |
|
6701 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
6702 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
6703 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
6704 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
23743 | 6705 |
OBJ fp = __INST(handle); |
6706 |
||
6707 |
if ((fp != nil) |
|
6708 |
&& (__INST(mode) != @symbol(readonly)) |
|
6709 |
&& __bothSmallInteger(start, stop) |
|
6710 |
) { |
|
6711 |
int _buffered = (__INST(buffered) == true); |
|
6712 |
FILEPOINTER f = __FILEVal(fp); |
|
6713 |
int offs, len, cnt; |
|
6714 |
int iStart = __intVal(start); |
|
6715 |
int iStop = __intVal(stop); |
|
6716 |
int o_offs; |
|
6717 |
||
6718 |
if (_buffered ) { |
|
6719 |
__WRITING__(f) |
|
6720 |
} |
|
6721 |
||
6722 |
if ((iStart < 1) || (iStop < iStart)) { |
|
6723 |
RETURN(self); |
|
6724 |
} |
|
6725 |
if (__isStringLike(aCollection)) { |
|
6726 |
char *stringP; |
|
6727 |
OBJ mode = __INST(eolMode); |
|
6728 |
||
6729 |
len = __stringSize(aCollection); |
|
6730 |
if (iStop > len) { |
|
6731 |
RETURN(self); |
|
6732 |
} |
|
6733 |
if (iStop > len) |
|
6734 |
iStop = len; |
|
6735 |
len = iStop - iStart + 1; |
|
6736 |
stringP = __stringVal(aCollection) + iStart - 1; |
|
6737 |
||
6738 |
if (__INST(binary) != true |
|
6739 |
&& ((mode == @symbol(cr)) |
|
6740 |
|| (mode == @symbol(etx)) |
|
6741 |
|| (mode == @symbol(eot)) |
|
6742 |
|| (mode == @symbol(crlf))) |
|
6743 |
&& memchr(stringP, '\n', len) != NULL) |
|
6744 |
{ |
|
6745 |
// see if there is a \n which needs to be translated, replace it |
|
6746 |
||
6747 |
char *end = stringP + len; |
|
6748 |
char sep[2]; |
|
6749 |
int sepLen = 1; |
|
6750 |
int bufLen; |
|
6751 |
char *buf, *endBuf, *sp, *dp; |
|
6752 |
||
6753 |
sep[0] = '\n'; |
|
6754 |
if (mode == @symbol(crlf)) { |
|
6755 |
sep[0] = '\r'; sep[1] = '\n'; sepLen = 2; |
|
6756 |
} else if (mode == @symbol(cr)) { |
|
6757 |
sep[0] = '\r'; |
|
6758 |
} else if (mode == @symbol(eot)) { |
|
6759 |
sep[0] = '\004'; |
|
6760 |
} else if (mode == @symbol(etx)) { |
|
6761 |
sep[0] = '\003'; |
|
6762 |
} |
|
6763 |
||
6764 |
// estimate size of buffer - assume every 4th char is a separator |
|
6765 |
bufLen = (sepLen == 1) ? len : (len + ((len/4) + 1) * sepLen); |
|
6766 |
buf = (char *)malloc(bufLen); |
|
6767 |
if (buf == NULL) { |
|
6768 |
error = __mkSmallInteger(ENOMEM); |
|
6769 |
goto out; |
|
6770 |
} |
|
6771 |
||
6772 |
endBuf = buf + bufLen; |
|
6773 |
||
6774 |
for (sp = stringP, dp = buf; sp < end; sp++) { |
|
6775 |
char c; |
|
6776 |
||
6777 |
if ((dp+sepLen) >= endBuf) { |
|
6778 |
char *newBuf; |
|
6779 |
||
6780 |
bufLen = bufLen * 2; |
|
6781 |
newBuf = (char *)realloc(buf, bufLen); |
|
6782 |
if (newBuf == NULL) { |
|
6783 |
free(buf); |
|
6784 |
error = __mkSmallInteger(ENOMEM); |
|
6785 |
goto out; |
|
6786 |
} |
|
6787 |
endBuf = newBuf + bufLen; |
|
6788 |
dp = newBuf + (dp-buf); |
|
6789 |
buf = newBuf; |
|
6790 |
} |
|
6791 |
||
6792 |
if ((c = *sp) == '\n') { |
|
6793 |
*dp++ = sep[0]; |
|
6794 |
if (sepLen == 2) { |
|
6795 |
*dp++ = sep[1]; |
|
6796 |
}; |
|
6797 |
} else { |
|
6798 |
*dp++ = c; |
|
6799 |
} |
|
6800 |
} |
|
6801 |
||
6802 |
len = dp - buf; |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6803 |
#ifdef __win32__ |
23743 | 6804 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6805 |
cnt = __win32_fwrite(buf, 1, len, f); |
|
6806 |
} else |
|
17420 | 6807 |
#endif |
23743 | 6808 |
{ |
6809 |
__WRITEBYTES__(cnt, f, buf, len, _buffered, __INST(handleType)); |
|
6810 |
} |
|
6811 |
free(buf); |
|
6812 |
} else { // No EOL conversion needed |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6813 |
#ifdef __win32__ |
23743 | 6814 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6815 |
cnt = __win32_fwrite(stringP, 1, len, f); |
|
6816 |
} else |
|
17420 | 6817 |
#endif |
23743 | 6818 |
{ |
6819 |
o_offs = (char *)__stringVal(aCollection)-(char *)__InstPtr(aCollection); |
|
6820 |
__WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs+iStart-1, len, _buffered, __INST(handleType)); |
|
6821 |
} |
|
6822 |
} |
|
6823 |
} else { // Not a string |
|
6824 |
if (__INST(binary) == true) { |
|
6825 |
int offs; |
|
6826 |
||
6827 |
if (__isByteArrayLike(aCollection)) { |
|
6828 |
offs = 0; |
|
6829 |
len = __byteArraySize(aCollection); |
|
6830 |
} else if (__isBytes(aCollection)) { |
|
6831 |
offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars)); |
|
6832 |
len = __byteArraySize(aCollection) - offs; |
|
6833 |
} else |
|
6834 |
goto out; |
|
6835 |
||
6836 |
if (iStop > len) { |
|
6837 |
RETURN(self); |
|
6838 |
} |
|
6839 |
if (iStop > len) |
|
6840 |
iStop = len; |
|
6841 |
len = iStop - iStart + 1; |
|
6842 |
offs += iStart - 1; |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6843 |
#ifdef __win32__ |
23743 | 6844 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6845 |
cnt = __win32_fwrite(__stringVal(aCollection)+iStart-1, 1, len, f); |
|
6846 |
} else |
|
17418 | 6847 |
#endif |
23743 | 6848 |
{ |
6849 |
o_offs = (char *)(__ByteArrayInstPtr(aCollection)->ba_element)-(char *)__InstPtr(aCollection); |
|
6850 |
__WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs+offs, len, _buffered, __INST(handleType)); |
|
6851 |
} |
|
6852 |
} else |
|
6853 |
goto out; |
|
6854 |
} |
|
6855 |
if (cnt == len) { |
|
6856 |
if (__isSmallInteger(__INST(position))) { |
|
6857 |
INT np = __intVal(__INST(position)) + len; |
|
6858 |
OBJ t; |
|
6859 |
||
6860 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
6861 |
} else { |
|
6862 |
__INST(position) = nil; /* i.e. do not know */ |
|
6863 |
} |
|
6864 |
RETURN (self); |
|
6865 |
} |
|
23538 | 6866 |
# ifdef __win32__ |
23743 | 6867 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 6868 |
# endif |
23743 | 6869 |
error = __mkSmallInteger(__threadErrno); |
6870 |
} |
|
17418 | 6871 |
} |
6872 |
out: ; |
|
6873 |
%}. |
|
6874 |
error notNil ifTrue:[ |
|
23743 | 6875 |
lastErrorNumber := error. |
6876 |
self writeError:error. |
|
6877 |
^ self |
|
17418 | 6878 |
]. |
23538 | 6879 |
super nextPutAll:aCollection startingAt:start to:stop |
6880 |
||
6881 |
"Modified: / 22-11-2018 / 12:52:13 / Stefan Vogel" |
|
17418 | 6882 |
! |
6883 |
||
6884 |
nextPutAllUnicode:aString |
|
6885 |
"normal streams can not handle multi-byte characters, so convert them to utf8. |
|
6886 |
This is needed, so that you can do ('something' asUnicode16String errorPrintCR)" |
|
6887 |
||
6888 |
aString do:[:eachCharacter| |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
6889 |
self nextPutUtf8:eachCharacter. |
17418 | 6890 |
]. |
6891 |
||
6892 |
" |
|
25134 | 6893 |
'Bönnigheim' asUnicode16String errorPrintCR |
17418 | 6894 |
" |
6895 |
! |
|
6896 |
||
17608 | 6897 |
nextPutBytes:count from:anObject startingAt:start |
6898 |
"write count bytes from an object starting at index start. |
|
6899 |
return the number of bytes written - which could be 0. |
|
6900 |
The object must have non-pointer indexed instvars |
|
6901 |
(i.e. be a ByteArray, String, Float- or DoubleArray), |
|
6902 |
or an externalBytes object (with known size). |
|
6903 |
||
6904 |
Use with care - non object oriented i/o. |
|
6905 |
Warning: |
|
23743 | 6906 |
in general, you cannot use this method to pass non-byte data to other |
6907 |
architectures (unless you prepared the buffer with care), |
|
6908 |
since it does not care for byte order or float representation." |
|
17608 | 6909 |
|
6910 |
|error| |
|
6911 |
||
6912 |
%{ |
|
18312 | 6913 |
#ifdef __SCHTEAM__ |
6914 |
byte[] bytes; |
|
6915 |
STObject handle = self.instVarAt(I_handle); |
|
6916 |
||
6917 |
if (anObject.isSTString()) { |
|
23743 | 6918 |
char[] chars = anObject.asSTString().characters; |
6919 |
handle.writeCharacters(chars, start.intValue()-1, count.intValue()); |
|
6920 |
self.instVarAt_put(I_position, STObject.Nil); |
|
6921 |
return context._RETURN(count); |
|
18364 | 6922 |
} |
6923 |
if (anObject.isSymbol()) { |
|
23743 | 6924 |
java.lang.String chars = anObject.asSTSymbol().characters; |
6925 |
handle.writeString(chars, start.intValue()-1, count.intValue()); |
|
6926 |
self.instVarAt_put(I_position, STObject.Nil); |
|
6927 |
return context._RETURN(count); |
|
18312 | 6928 |
} |
6929 |
#else |
|
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
6930 |
int ret; |
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
6931 |
int objSize, nInstBytes; |
17608 | 6932 |
char *extPtr; |
6933 |
OBJ fp; |
|
6934 |
||
6935 |
__INST(lastErrorNumber) = nil; |
|
6936 |
if ((__INST(handleType) == nil) |
|
6937 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
6938 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
6939 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
6940 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
23743 | 6941 |
if (((fp = __INST(handle)) != nil) |
6942 |
&& (__INST(mode) != @symbol(readonly)) |
|
6943 |
&& __bothSmallInteger(count, start) |
|
6944 |
) { |
|
6945 |
int _buffered = (__INST(buffered) == true); |
|
6946 |
FILEPOINTER f = __FILEVal(fp); |
|
6947 |
int len = __intVal(count); |
|
6948 |
int offs = __intVal(start) - 1; |
|
6949 |
||
6950 |
if (__isExternalBytesLike(anObject)) { |
|
6951 |
OBJ sz; |
|
6952 |
||
6953 |
nInstBytes = 0; |
|
6954 |
extPtr = (char *)__externalBytesAddress(anObject); |
|
6955 |
if (extPtr == NULL) goto bad; |
|
6956 |
sz = __externalBytesSize(anObject); |
|
6957 |
if (__isSmallInteger(sz)) { |
|
6958 |
objSize = __intVal(sz); |
|
6959 |
} else { |
|
6960 |
objSize = 0; /* unknown */ |
|
6961 |
} |
|
6962 |
} else { |
|
6963 |
OBJ oClass = __Class(anObject); |
|
6964 |
int nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
6965 |
||
6966 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
6967 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
|
6968 |
case BYTEARRAY: |
|
6969 |
case WORDARRAY: |
|
6970 |
case LONGARRAY: |
|
6971 |
case SWORDARRAY: |
|
6972 |
case SLONGARRAY: |
|
6973 |
case FLOATARRAY: |
|
6974 |
break; |
|
6975 |
case DOUBLEARRAY: |
|
18312 | 6976 |
# ifdef __NEED_DOUBLE_ALIGN |
23743 | 6977 |
nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1); |
18312 | 6978 |
# endif |
23743 | 6979 |
break; |
6980 |
case LONGLONGARRAY: |
|
6981 |
case SLONGLONGARRAY: |
|
18312 | 6982 |
# ifdef __NEED_LONGLONG_ALIGN |
23743 | 6983 |
nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1); |
18312 | 6984 |
# endif |
23743 | 6985 |
break; |
6986 |
default: |
|
6987 |
goto bad; |
|
6988 |
} |
|
6989 |
extPtr = (char *)0; |
|
6990 |
objSize = __Size(anObject) - nInstBytes; |
|
6991 |
} |
|
6992 |
if ( (offs >= 0) && (len >= 0) && (objSize >= (len + offs)) ) { |
|
6993 |
int cnt; |
|
6994 |
||
6995 |
if (_buffered) { |
|
6996 |
__WRITING__(f) |
|
6997 |
} |
|
6998 |
||
6999 |
if (extPtr) { |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
7000 |
# ifdef __win32__ |
23743 | 7001 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
7002 |
cnt = __win32_fwrite(extPtr+offs, 1, len, f); |
|
7003 |
} else |
|
18312 | 7004 |
# endif |
23743 | 7005 |
{ |
7006 |
__WRITEBYTES__(cnt, f, extPtr+offs, len, _buffered, __INST(handleType)); |
|
7007 |
} |
|
7008 |
} else { |
|
7009 |
/* |
|
7010 |
* on interrupt, anObject may be moved to another location. |
|
7011 |
* So we pass anObject, and the offset to the __WRITEBYTES_OBJ__ macro. |
|
7012 |
*/ |
|
7013 |
offs += nInstBytes; |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
7014 |
# ifdef __win32__ |
23743 | 7015 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
7016 |
cnt = __win32_fwrite((char *)anObject+offs, 1, len, f); |
|
7017 |
} else |
|
18312 | 7018 |
# endif |
23743 | 7019 |
{ |
7020 |
__WRITEBYTES_OBJ__(cnt, f, anObject, offs, len, _buffered, __INST(handleType)); |
|
7021 |
} |
|
7022 |
} |
|
7023 |
||
7024 |
if (cnt >= 0) { |
|
7025 |
if (__isSmallInteger(__INST(position))) { |
|
7026 |
INT np = __intVal(__INST(position)) + cnt; |
|
7027 |
OBJ t; |
|
7028 |
||
7029 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
7030 |
} else { |
|
7031 |
__INST(position) = nil; /* i.e. do not know */ |
|
7032 |
} |
|
7033 |
RETURN ( __mkSmallInteger(cnt) ); |
|
7034 |
} else /* cnt < 0 */ { |
|
7035 |
if ( |
|
18312 | 7036 |
# ifdef EWOULDBLOCK |
23743 | 7037 |
(__threadErrno == EWOULDBLOCK) || |
18312 | 7038 |
# endif |
23743 | 7039 |
(__threadErrno == EAGAIN) |
7040 |
) { |
|
7041 |
RETURN ( __mkSmallInteger(0) ); |
|
7042 |
} |
|
7043 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 7044 |
# ifdef __win32__ |
23743 | 7045 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 7046 |
# endif |
23743 | 7047 |
error = __mkSmallInteger(__threadErrno); |
7048 |
} |
|
7049 |
} |
|
7050 |
} |
|
17608 | 7051 |
} |
7052 |
bad: ; |
|
18312 | 7053 |
#endif /* not SCHTEAM */ |
17608 | 7054 |
%}. |
7055 |
error notNil ifTrue:[ |
|
23743 | 7056 |
lastErrorNumber := error. |
7057 |
self writeError:error. |
|
7058 |
^ 0 |
|
17608 | 7059 |
]. |
17634 | 7060 |
handle isNil ifTrue:[self errorNotOpen. ^ 0]. |
7061 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ 0]. |
|
7062 |
self primitiveFailed. |
|
7063 |
^ 0. |
|
23538 | 7064 |
|
7065 |
"Modified: / 22-11-2018 / 14:47:58 / Stefan Vogel" |
|
17608 | 7066 |
! |
7067 |
||
17418 | 7068 |
nextPutUnicode:aCharacter |
7069 |
"normal streams can not handle multi-byte characters, so convert them to utf8" |
|
7070 |
||
7071 |
self nextPutUtf8:aCharacter. |
|
612 | 7072 |
! ! |
7073 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
7074 |
!ExternalStream class methodsFor:'documentation'! |
730 | 7075 |
|
7076 |
version |
|
18636 | 7077 |
^ '$Header$' |
12398 | 7078 |
! |
7079 |
||
7080 |
version_CVS |
|
18636 | 7081 |
^ '$Header$' |
730 | 7082 |
! ! |
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6758
diff
changeset
|
7083 |
|
14603 | 7084 |
|
612 | 7085 |
ExternalStream initialize! |