author | Claus Gittinger <cg@exept.de> |
Thu, 27 Jun 2019 16:34:40 +0200 | |
changeset 24379 | 852be153b0ec |
parent 24045 | 031200ccf630 |
child 24383 | fb67cbcafd72 |
permissions | -rw-r--r-- |
23934 | 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 |
} \ |
|
300 |
} else { \ |
|
301 |
(ret) = 0; \ |
|
302 |
} \ |
|
303 |
break; \ |
|
304 |
} \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
305 |
} else { \ |
23743 | 306 |
OBJ rA = __INST(readAhead); \ |
307 |
if (rA != nil) { \ |
|
308 |
*(buf) = (char)__intVal(rA); \ |
|
309 |
__INST(readAhead) = nil; \ |
|
310 |
(ret) = 1; \ |
|
311 |
} else { \ |
|
312 |
for (;;) { \ |
|
313 |
CLEAR_ERRNO; \ |
|
314 |
READ((ret), f, buf, 1, handleType); \ |
|
315 |
if ((ret) >= 0 || __threadErrno != EINTR) \ |
|
316 |
break; \ |
|
317 |
} \ |
|
318 |
} \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
319 |
} |
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 |
* read_bytes into a c-buffer |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
323 |
* (which may NOT move) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
324 |
*/ |
12548 | 325 |
# define __READBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
326 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
327 |
if (isBuffered) { \ |
23743 | 328 |
int __offs = 0; \ |
329 |
while (__offs < (cnt)) { \ |
|
330 |
CLEAR_ERRNO; \ |
|
331 |
(ret) = getc(f); \ |
|
332 |
if ((ret) < 0) { \ |
|
333 |
if (ferror(f)) { \ |
|
334 |
if (__threadErrno == EINTR) { \ |
|
335 |
clearerr(f); \ |
|
336 |
continue; \ |
|
337 |
} \ |
|
338 |
} else { \ |
|
339 |
(ret) = 0; \ |
|
340 |
} \ |
|
341 |
break; \ |
|
342 |
} \ |
|
343 |
(buf)[__offs++] = (ret); \ |
|
344 |
} \ |
|
345 |
if (__offs > 0) \ |
|
346 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
347 |
} else { \ |
23743 | 348 |
int __offs = 0; \ |
349 |
\ |
|
350 |
while (__offs < (cnt)) { \ |
|
351 |
OBJ rA = __INST(readAhead); \ |
|
352 |
if (rA != nil) { \ |
|
353 |
(buf)[__offs] = __intVal(rA); \ |
|
354 |
__INST(readAhead) = nil; \ |
|
355 |
(ret) = 1; \ |
|
356 |
} else { \ |
|
357 |
CLEAR_ERRNO; \ |
|
358 |
READ((ret), f, (buf)+__offs, (cnt)-__offs, handleType); \ |
|
359 |
if ((ret) <= 0) { \ |
|
360 |
if ((ret) < 0 && __threadErrno == EINTR) { \ |
|
361 |
continue; \ |
|
362 |
} \ |
|
363 |
break; \ |
|
364 |
} \ |
|
365 |
} \ |
|
366 |
__offs += (ret); \ |
|
367 |
} \ |
|
368 |
if (__offs > 0) \ |
|
369 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
370 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
371 |
|
12548 | 372 |
# define __READAVAILBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
373 |
{ \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
374 |
int __offs = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
375 |
int oldFlags; \ |
23743 | 376 |
\ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
377 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
378 |
if (isBuffered) { \ |
23743 | 379 |
while (__offs < (cnt)) { \ |
380 |
CLEAR_ERRNO; \ |
|
381 |
(ret) = getc(f); \ |
|
382 |
if ((ret) < 0) { \ |
|
383 |
if (ferror(f)) { \ |
|
384 |
if (__threadErrno == EINTR) { \ |
|
385 |
clearerr(f); \ |
|
386 |
continue; \ |
|
387 |
} \ |
|
388 |
} else { \ |
|
389 |
(ret) = 0; \ |
|
390 |
} \ |
|
391 |
break; \ |
|
392 |
} \ |
|
393 |
(buf)[__offs++] = (ret); \ |
|
394 |
} \ |
|
395 |
if (__offs > 0) \ |
|
396 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
397 |
} else { \ |
23743 | 398 |
while (__offs < (cnt)) { \ |
399 |
OBJ rA = __INST(readAhead); \ |
|
400 |
if (rA != nil) { \ |
|
401 |
(buf)[__offs] = __intVal(rA); \ |
|
402 |
__INST(readAhead) = nil; \ |
|
403 |
(ret) = 1; \ |
|
404 |
__offs ++; \ |
|
405 |
continue; \ |
|
406 |
} \ |
|
407 |
CLEAR_ERRNO; \ |
|
408 |
{ \ |
|
409 |
int res = -1, ok = 0; \ |
|
410 |
SOCKET sock = 0; \ |
|
411 |
if ((handleType == @symbol(socketFilePointer) && ((ok = ioctlsocket(sock = (SOCKET)_get_osfhandle(fileno(f)),FIONREAD,&res) == 0), 1)) \ |
|
412 |
|| (handleType == @symbol(socketHandle) && ((ok = ioctlsocket(sock = (SOCKET)(f), FIONREAD, &res) == 0), 1)) \ |
|
413 |
|| (handleType == @symbol(pipeFilePointer) && ((ok = PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0, 0,0,&res,0)), 1))) { \ |
|
414 |
if (!ok) { \ |
|
415 |
__threadErrno = sock ? WSAGetLastError() : __WIN32_ERR(GetLastError()); \ |
|
416 |
(ret) = __threadErrno == __WIN32_ERR(ERROR_BROKEN_PIPE) ? 0 : -1; \ |
|
417 |
break; \ |
|
418 |
} \ |
|
419 |
if (res > 0) { \ |
|
420 |
if (res > ((cnt)-__offs)) \ |
|
421 |
res = (cnt)-__offs; \ |
|
422 |
READ((ret), f, (buf)+__offs, res, handleType); \ |
|
423 |
} else { \ |
|
424 |
if (sock && send(sock, NULL, 0, 0) == SOCKET_ERROR) { \ |
|
425 |
(ret) = -1; __threadErrno = WSAGetLastError(); \ |
|
426 |
} else { \ |
|
427 |
(ret) = 0; \ |
|
428 |
} \ |
|
429 |
break; \ |
|
430 |
} \ |
|
431 |
} else { \ |
|
432 |
READ((ret), f, (buf)+__offs, (cnt)-__offs, handleType); \ |
|
433 |
} \ |
|
434 |
} \ |
|
435 |
if ((ret) <= 0) { \ |
|
436 |
if ((ret) < 0 && __threadErrno == EINTR)\ |
|
437 |
continue; \ |
|
438 |
break; \ |
|
439 |
} \ |
|
440 |
__offs += (ret); \ |
|
441 |
} \ |
|
442 |
if (__offs > 0) \ |
|
443 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
444 |
} \ |
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 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
447 |
# define IO_BUFFER_SIZE (8*1024) |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
448 |
|
12548 | 449 |
# 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
|
450 |
{ \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
451 |
int __ooffs = obj_offs; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
452 |
int __offs = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
453 |
char *buf = (char *)(obj); \ |
23743 | 454 |
\ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
455 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
456 |
if (isBuffered) { \ |
23743 | 457 |
while (__offs < (cnt)) { \ |
458 |
CLEAR_ERRNO; \ |
|
459 |
(ret) = getc(f); \ |
|
460 |
if ((ret) < 0) { \ |
|
461 |
if (ferror(f)) { \ |
|
462 |
if (__threadErrno == EINTR) { \ |
|
463 |
clearerr(f); \ |
|
464 |
/* refetch */ \ |
|
465 |
buf = (char *)(obj); \ |
|
466 |
continue; \ |
|
467 |
} \ |
|
468 |
} else { \ |
|
469 |
(ret) = 0; \ |
|
470 |
} \ |
|
471 |
break; \ |
|
472 |
} \ |
|
473 |
(buf)[__ooffs+__offs] = (ret); \ |
|
474 |
__offs++; \ |
|
475 |
} \ |
|
476 |
if (__offs > 0) \ |
|
477 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
478 |
} else { \ |
23743 | 479 |
while (__offs < (cnt)) { \ |
480 |
char __buf[IO_BUFFER_SIZE]; \ |
|
481 |
OBJ rA = __INST(readAhead); \ |
|
482 |
if (rA != nil) { \ |
|
483 |
(buf)[__ooffs+__offs] = __intVal(rA); \ |
|
484 |
__INST(readAhead) = nil; \ |
|
485 |
(ret) = 1; \ |
|
486 |
} else { \ |
|
487 |
int l; \ |
|
488 |
CLEAR_ERRNO; \ |
|
489 |
l = (cnt)-__offs; \ |
|
490 |
if ( l > IO_BUFFER_SIZE) \ |
|
491 |
l = IO_BUFFER_SIZE; \ |
|
492 |
READ((ret),f, __buf, l, handleType); \ |
|
493 |
if ((ret) <= 0) { \ |
|
494 |
if ((ret) < 0 && __threadErrno == EINTR) { \ |
|
495 |
continue; \ |
|
496 |
} \ |
|
497 |
break; \ |
|
498 |
} \ |
|
499 |
} \ |
|
500 |
if ((ret) > 0 ) { \ |
|
501 |
/* refetch */ \ |
|
502 |
buf = (char *)(obj); \ |
|
503 |
memcpy((buf)+__ooffs+__offs,__buf,(ret)); \ |
|
504 |
__offs += (ret); \ |
|
505 |
} else { \ |
|
506 |
(ret) = 0; \ |
|
507 |
} \ |
|
508 |
} \ |
|
509 |
if (__offs > 0) \ |
|
510 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
511 |
} \ |
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 |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
514 |
# 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
|
515 |
{ \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
516 |
int __ooffs = obj_offs; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
517 |
int __offs = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
518 |
char *buf = (char *)(obj); \ |
23743 | 519 |
\ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
520 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
521 |
if (isBuffered) { \ |
23743 | 522 |
while (__offs < (cnt)) { \ |
523 |
CLEAR_ERRNO; \ |
|
524 |
(ret) = getc(f); \ |
|
525 |
if ((ret) < 0) { \ |
|
526 |
if (ferror(f)) { \ |
|
527 |
if (__threadErrno == EINTR) { \ |
|
528 |
clearerr(f); \ |
|
529 |
/* refetch */ \ |
|
530 |
buf = (char *)(obj); \ |
|
531 |
continue; \ |
|
532 |
} \ |
|
533 |
} else { \ |
|
534 |
(ret) = 0; \ |
|
535 |
} \ |
|
536 |
break; \ |
|
537 |
} \ |
|
538 |
(buf)[__ooffs+__offs] = (ret); \ |
|
539 |
__offs++; \ |
|
540 |
} \ |
|
541 |
if (__offs > 0) \ |
|
542 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
543 |
} else { \ |
23743 | 544 |
while (__offs < (cnt)) { \ |
545 |
char __buf[IO_BUFFER_SIZE]; \ |
|
546 |
OBJ rA = __INST(readAhead); \ |
|
547 |
if (rA != nil) { \ |
|
548 |
(buf)[__ooffs+__offs] = __intVal(rA);\ |
|
549 |
__INST(readAhead) = nil; \ |
|
550 |
(ret) = 1; \ |
|
551 |
__offs++; \ |
|
552 |
continue; \ |
|
553 |
} \ |
|
554 |
{ \ |
|
555 |
int res = -1, ok = 0; \ |
|
556 |
SOCKET sock = 0; \ |
|
557 |
int l = (cnt)-__offs; \ |
|
558 |
CLEAR_ERRNO; \ |
|
559 |
if (l > IO_BUFFER_SIZE) l = IO_BUFFER_SIZE; \ |
|
560 |
if ((handleType == @symbol(socketFilePointer) && ((ok = ioctlsocket(sock = (SOCKET)_get_osfhandle(fileno(f)),FIONREAD,&res) == 0), 1)) \ |
|
561 |
|| (handleType == @symbol(socketHandle) && ((ok = ioctlsocket(sock = (SOCKET)(f), FIONREAD, &res) == 0), 1)) \ |
|
562 |
|| (handleType == @symbol(pipeFilePointer) && ((ok = PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0, 0,0,&res,0)), 1))) { \ |
|
563 |
if (!ok) { \ |
|
564 |
__threadErrno = sock ? WSAGetLastError() : __WIN32_ERR(GetLastError()); \ |
|
565 |
(ret) = __threadErrno == __WIN32_ERR(ERROR_BROKEN_PIPE) ? 0 : -1; \ |
|
566 |
break; \ |
|
567 |
} \ |
|
568 |
if (res > 0) { \ |
|
569 |
if (res > l) res = l; \ |
|
570 |
READ((ret), f, __buf, res, handleType); \ |
|
571 |
} else { \ |
|
572 |
if (sock && send(sock, NULL, 0, 0) == SOCKET_ERROR) { \ |
|
573 |
(ret) = -1; __threadErrno = WSAGetLastError(); \ |
|
574 |
} else { \ |
|
575 |
(ret) = 0; \ |
|
576 |
} \ |
|
577 |
break; \ |
|
578 |
} \ |
|
579 |
} else { \ |
|
580 |
READ((ret), f, __buf, l, handleType); \ |
|
581 |
} \ |
|
582 |
if ((ret) <= 0) { \ |
|
583 |
if ((ret) < 0 && __threadErrno == EINTR) \ |
|
584 |
continue; \ |
|
585 |
break; \ |
|
586 |
} \ |
|
587 |
} \ |
|
588 |
if ((ret) > 0) { \ |
|
589 |
buf = (char *)(obj); \ |
|
590 |
memcpy((buf)+__ooffs+__offs, __buf, (ret)); \ |
|
591 |
__offs += (ret); \ |
|
592 |
} else { \ |
|
593 |
(ret) = 0; \ |
|
594 |
} \ |
|
595 |
} \ |
|
596 |
if (__offs > 0) \ |
|
597 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
598 |
} \ |
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 |
|
12548 | 601 |
# define __WRITEBYTE__(ret, f, buf, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
602 |
if (isBuffered) { \ |
23743 | 603 |
for (;;) { \ |
604 |
CLEAR_ERRNO; \ |
|
605 |
ret = putc(*(buf), f); \ |
|
606 |
if ((ret) >= 0) { \ |
|
607 |
(ret) = 1; \ |
|
608 |
} else if (ferror(f)) { \ |
|
609 |
if (__threadErrno == EINTR) { \ |
|
610 |
clearerr(f); \ |
|
611 |
continue; \ |
|
612 |
} \ |
|
613 |
} else \ |
|
614 |
(ret) = 0; \ |
|
615 |
break; \ |
|
616 |
} \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
617 |
} else { \ |
23743 | 618 |
for (;;) { \ |
619 |
CLEAR_ERRNO; \ |
|
620 |
WRITE(ret,f, buf, 1, handleType); \ |
|
621 |
if ((ret) >= 0 || __threadErrno != EINTR) \ |
|
622 |
break; \ |
|
623 |
} \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
624 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
625 |
|
12548 | 626 |
# define __WRITEBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
627 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
628 |
if (isBuffered) { \ |
23743 | 629 |
int __offs = 0; \ |
630 |
while (__offs < (cnt)) { \ |
|
631 |
CLEAR_ERRNO; \ |
|
632 |
(ret) = fwrite((buf)+__offs, 1, (cnt)-__offs, f);\ |
|
633 |
if ((ret) <= 0) { \ |
|
634 |
if (ferror(f)) { \ |
|
635 |
if (__threadErrno == EINTR) { \ |
|
636 |
clearerr(f); \ |
|
637 |
continue; \ |
|
638 |
} \ |
|
639 |
break; \ |
|
640 |
} else { \ |
|
641 |
(ret) = 0; \ |
|
642 |
} \ |
|
643 |
} \ |
|
644 |
__offs += (ret); \ |
|
645 |
} \ |
|
646 |
if (__offs > 0) \ |
|
647 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
648 |
} else { \ |
23743 | 649 |
int __offs = 0; \ |
650 |
while (__offs < (cnt)) { \ |
|
651 |
CLEAR_ERRNO; \ |
|
652 |
WRITE((ret),f, (buf)+__offs, (cnt)-__offs, handleType); \ |
|
653 |
if ((ret) <= 0) { \ |
|
654 |
if ((ret) < 0 && __threadErrno == EINTR) { \ |
|
655 |
continue; \ |
|
656 |
} \ |
|
657 |
break; \ |
|
658 |
} \ |
|
659 |
__offs += (ret); \ |
|
660 |
} \ |
|
661 |
if (__offs > 0) \ |
|
662 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
663 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
664 |
|
12548 | 665 |
# 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
|
666 |
{ \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
667 |
int __ooffs = obj_offs; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
668 |
int __offs = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
669 |
char *buf = (char *)(obj); \ |
23743 | 670 |
\ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
671 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
672 |
if (isBuffered) { \ |
23743 | 673 |
while (__offs < (cnt)) { \ |
674 |
CLEAR_ERRNO; \ |
|
675 |
ret = fwrite((buf)+__ooffs+__offs, 1, (cnt)-__offs, f); \ |
|
676 |
if ((ret) <= 0) { \ |
|
677 |
if (ferror(f)) { \ |
|
678 |
if (__threadErrno == EINTR) { \ |
|
679 |
/* refetch */ \ |
|
680 |
buf = (char *)(obj); \ |
|
681 |
clearerr(f); \ |
|
682 |
continue; \ |
|
683 |
} \ |
|
684 |
break; \ |
|
685 |
} else { \ |
|
686 |
(ret) = 0; \ |
|
687 |
} \ |
|
688 |
} \ |
|
689 |
__offs += (ret); \ |
|
690 |
} \ |
|
691 |
if (__offs > 0) \ |
|
692 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
693 |
} else { \ |
23743 | 694 |
while (__offs < (cnt)) { \ |
695 |
char __buf[IO_BUFFER_SIZE]; \ |
|
696 |
int l; \ |
|
697 |
CLEAR_ERRNO; \ |
|
698 |
l = (cnt)-__offs; \ |
|
699 |
if ( l > IO_BUFFER_SIZE) \ |
|
700 |
l = IO_BUFFER_SIZE; \ |
|
701 |
/* refetch */ \ |
|
702 |
buf = (char *)(obj); \ |
|
703 |
memcpy(__buf,(buf)+__ooffs+__offs,l); \ |
|
704 |
WRITE(ret,f, __buf, l, handleType); \ |
|
705 |
if ((ret) <= 0) { \ |
|
706 |
if ((ret) < 0 && __threadErrno == EINTR) { \ |
|
707 |
continue; \ |
|
708 |
} \ |
|
709 |
break; \ |
|
710 |
} \ |
|
711 |
__offs += (ret); \ |
|
712 |
} \ |
|
713 |
if (__offs > 0) \ |
|
714 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
715 |
} \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
716 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
717 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
718 |
#else /* ! __win32__ */ |
16296 | 719 |
/* ======================== UNIX / LINUX ====================================================== */ |
16373
9b9827530bf4
Adapt previous change for linux
Stefan Vogel <sv@exept.de>
parents:
16368
diff
changeset
|
720 |
typedef int SOCKET; |
9b9827530bf4
Adapt previous change for linux
Stefan Vogel <sv@exept.de>
parents:
16368
diff
changeset
|
721 |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
722 |
# define __READING__(f) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
723 |
if ((__INST(didWrite) != false) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
724 |
&& (__INST(mode) == @symbol(readwrite))) { \ |
23743 | 725 |
__INST(didWrite) = false; \ |
726 |
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
|
727 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
728 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
729 |
# define __WRITING__(f) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
730 |
if ((__INST(didWrite) != true) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
731 |
&& (__INST(mode) == @symbol(readwrite))) { \ |
23743 | 732 |
__INST(didWrite) = true; \ |
733 |
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
|
734 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
735 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
736 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
737 |
# ifdef NO_STDIO |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
738 |
# define __UNGETC__(c, f, isBuffered) \ |
8913 | 739 |
__INST(readAhead) = __mkSmallInteger((c)); |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
740 |
# else /* use STDIO */ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
741 |
# define __UNGETC__(c, f, isBuffered) \ |
2264 | 742 |
if (isBuffered) { \ |
23743 | 743 |
ungetc((c), (f)); \ |
2264 | 744 |
} else { \ |
23743 | 745 |
__INST(readAhead) = __mkSmallInteger((c)); \ |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
746 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
747 |
# endif /* use STDIO */ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
748 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
749 |
# ifdef NO_STDIO |
12548 | 750 |
# 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
|
751 |
{ \ |
23743 | 752 |
OBJ rA = __INST(readAhead); \ |
753 |
if (rA != nil) { \ |
|
754 |
*(buf) = __intVal(rA); \ |
|
755 |
DEBUGBUFFER(buf); \ |
|
756 |
__INST(readAhead) = nil; \ |
|
757 |
(ret) = 1; \ |
|
758 |
} else { \ |
|
759 |
for (;;) { \ |
|
760 |
CLEAR_ERRNO; \ |
|
761 |
(ret) = READ(f, buf, 1, handleType); \ |
|
762 |
DEBUGBUFFER(buf); \ |
|
763 |
if ((ret) >= 0) break; \ |
|
764 |
if (errno != EINTR) { \ |
|
765 |
break; \ |
|
766 |
} \ |
|
767 |
__HANDLE_INTERRUPTS__; \ |
|
768 |
} \ |
|
769 |
} \ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
770 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
771 |
# else /* use STDIO */ |
12548 | 772 |
# define __READBYTE__(ret, f, buf, isBuffered, handleType) \ |
2264 | 773 |
if (isBuffered) { \ |
23743 | 774 |
for (;;) { \ |
775 |
CLEAR_ERRNO; \ |
|
776 |
(ret) = getc(f); \ |
|
777 |
if ((ret) >= 0) { \ |
|
778 |
DEBUGBUFFER(buf); \ |
|
779 |
*(buf) = (ret); \ |
|
780 |
(ret) = 1; \ |
|
781 |
} else if (ferror(f)) { \ |
|
782 |
if (errno == EINTR) { \ |
|
783 |
__HANDLE_INTERRUPTS__; \ |
|
784 |
clearerr(f); \ |
|
785 |
continue; \ |
|
786 |
} \ |
|
787 |
} else \ |
|
788 |
(ret) = 0; \ |
|
789 |
break; \ |
|
790 |
} \ |
|
2264 | 791 |
} else { \ |
23743 | 792 |
OBJ rA = __INST(readAhead); \ |
793 |
if (rA != nil) { \ |
|
794 |
*(buf) = __intVal(rA); \ |
|
795 |
DEBUGBUFFER(buf); \ |
|
796 |
__INST(readAhead) = nil; \ |
|
797 |
(ret) = 1; \ |
|
798 |
} else { \ |
|
799 |
for (;;) { \ |
|
800 |
CLEAR_ERRNO; \ |
|
801 |
(ret) = read(fileno(f), buf, 1); \ |
|
802 |
DEBUGBUFFER(buf); \ |
|
803 |
if ((ret) >= 0) break; \ |
|
804 |
if (errno != EINTR) { \ |
|
805 |
break; \ |
|
806 |
} \ |
|
807 |
__HANDLE_INTERRUPTS__; \ |
|
808 |
} \ |
|
809 |
} \ |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
810 |
} |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
811 |
# endif /* use STDIO */ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
812 |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
813 |
/* |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
814 |
* 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
|
815 |
* (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
|
816 |
*/ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
817 |
# ifdef NO_STDIO |
12548 | 818 |
# 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
|
819 |
{ \ |
23743 | 820 |
int __offs = 0, __cnt; \ |
821 |
\ |
|
822 |
while (__offs < (cnt)) { \ |
|
823 |
OBJ rA = __INST(readAhead); \ |
|
824 |
if (rA != nil) { \ |
|
825 |
(buf)[__offs] = __intVal(rA); \ |
|
826 |
DEBUGBUFFER(buf); \ |
|
827 |
__INST(readAhead) = nil; \ |
|
828 |
__offs++; \ |
|
829 |
} else { \ |
|
830 |
CLEAR_ERRNO; \ |
|
831 |
__cnt = READ(f, (buf)+__offs, (cnt)-__offs, handleType); \ |
|
832 |
DEBUGBUFFER(buf); \ |
|
833 |
if (__cnt <= 0) { \ |
|
834 |
if (__cnt < 0 && errno == EINTR) { \ |
|
835 |
__HANDLE_INTERRUPTS__; \ |
|
836 |
continue; \ |
|
837 |
} \ |
|
838 |
break; \ |
|
839 |
} \ |
|
840 |
__offs += __cnt; \ |
|
841 |
} \ |
|
842 |
} \ |
|
843 |
if (__offs > 0) \ |
|
844 |
(ret) = __offs; \ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
845 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
846 |
# else /* use STDIO */ |
12548 | 847 |
# 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
|
848 |
(ret) = 0; \ |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
849 |
if (isBuffered) { \ |
23743 | 850 |
int __offs = 0; \ |
851 |
while (__offs < (cnt)) { \ |
|
852 |
CLEAR_ERRNO; \ |
|
853 |
(ret) = getc(f); \ |
|
854 |
if ((ret) < 0) { \ |
|
855 |
if (ferror(f)) { \ |
|
856 |
if (errno == EINTR) { \ |
|
857 |
__HANDLE_INTERRUPTS__; \ |
|
858 |
clearerr(f); \ |
|
859 |
continue; \ |
|
860 |
} \ |
|
861 |
} else { \ |
|
862 |
(ret) = 0; \ |
|
863 |
} \ |
|
864 |
break; \ |
|
865 |
} \ |
|
866 |
DEBUGBUFFER(buf); \ |
|
867 |
(buf)[__offs++] = (ret); \ |
|
868 |
} \ |
|
869 |
if (__offs > 0) \ |
|
870 |
(ret) = __offs; \ |
|
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
871 |
} else { \ |
23743 | 872 |
int __offs = 0, __cnt; \ |
873 |
int fd = fileno(f); \ |
|
874 |
\ |
|
875 |
while (__offs < (cnt)) { \ |
|
876 |
OBJ rA = __INST(readAhead); \ |
|
877 |
if (rA != nil) { \ |
|
878 |
DEBUGBUFFER(buf); \ |
|
879 |
(buf)[__offs] = __intVal(rA); \ |
|
880 |
__INST(readAhead) = nil; \ |
|
881 |
__offs++; \ |
|
882 |
} else { \ |
|
883 |
CLEAR_ERRNO; \ |
|
884 |
__cnt = read(fd, (buf)+__offs, (cnt)-__offs); \ |
|
885 |
DEBUGBUFFER(buf); \ |
|
886 |
if (__cnt <= 0) { \ |
|
887 |
if (__cnt < 0 && errno == EINTR) { \ |
|
888 |
__HANDLE_INTERRUPTS__; \ |
|
889 |
continue; \ |
|
890 |
} \ |
|
891 |
break; \ |
|
892 |
} \ |
|
893 |
__offs += __cnt; \ |
|
894 |
} \ |
|
895 |
} \ |
|
896 |
if (__offs > 0) \ |
|
897 |
(ret) = __offs; \ |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
898 |
} |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
899 |
|
6563
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
900 |
|
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
901 |
/* |
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
902 |
* 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
|
903 |
*/ |
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
904 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
905 |
# 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
|
906 |
# define SETFLAGS(fd, flags) \ |
23743 | 907 |
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
|
908 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
909 |
# if defined(O_NONBLOCK) |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
910 |
# define __STX_NONBLOCK_FLAG O_NONBLOCK |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
911 |
# else |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
912 |
# if defined(O_NDELAY) |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
913 |
# define __STX_NONBLOCK_FLAG O_NDELAY |
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 |
# define __STX_NONBLOCK_FLAG FNDELAY |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
916 |
# endif |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
917 |
# endif |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
918 |
|
15342 | 919 |
# define SETNONBLOCKING(fd, oldFlags) \ |
23743 | 920 |
{ \ |
921 |
int flags = fcntl(fd, F_GETFL, 0); \ |
|
922 |
if (flags >= 0) { \ |
|
923 |
fcntl(fd, F_SETFL, flags | __STX_NONBLOCK_FLAG); \ |
|
924 |
} \ |
|
925 |
oldFlags = flags; \ |
|
926 |
} |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
927 |
# else |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
928 |
# define SETFLAGS(fd, flags) /* nothing */ |
15342 | 929 |
# define SETNONBLOCKING(fd, oldFlags) /* nothing */ |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
930 |
# endif |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
931 |
|
12548 | 932 |
# define __READAVAILBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
933 |
{ \ |
15342 | 934 |
int __offs = 0, __cnt; \ |
3681 | 935 |
int oldFlags; \ |
23743 | 936 |
\ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
937 |
(ret) = 0; \ |
15342 | 938 |
SETNONBLOCKING(fileno(f), oldFlags); \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
939 |
if (isBuffered) { \ |
23743 | 940 |
while (__offs < (cnt)) { \ |
941 |
CLEAR_ERRNO; \ |
|
942 |
(ret) = getc(f); \ |
|
943 |
if ((ret) < 0) { \ |
|
944 |
if (ferror(f)) { \ |
|
945 |
if (errno == EINTR) { \ |
|
946 |
(ret) = 0; \ |
|
947 |
clearerr(f); \ |
|
948 |
break; \ |
|
949 |
} \ |
|
950 |
} else { \ |
|
951 |
(ret) = 0; \ |
|
952 |
} \ |
|
953 |
break; \ |
|
954 |
} \ |
|
955 |
(buf)[__offs++] = (ret); \ |
|
956 |
DEBUGBUFFER(buf); \ |
|
957 |
} \ |
|
958 |
if (__offs > 0) \ |
|
959 |
(ret) = __offs; \ |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
960 |
} else { \ |
23743 | 961 |
int fd = fileno(f); \ |
962 |
\ |
|
963 |
while (__offs < (cnt)) { \ |
|
964 |
OBJ rA = __INST(readAhead); \ |
|
965 |
if (rA != nil) { \ |
|
966 |
(buf)[__offs] = __intVal(rA); \ |
|
967 |
DEBUGBUFFER(buf); \ |
|
968 |
__INST(readAhead) = nil; \ |
|
969 |
__offs++; \ |
|
970 |
continue; \ |
|
971 |
} \ |
|
972 |
CLEAR_ERRNO; \ |
|
973 |
__cnt = read(fd, (buf)+__offs, (cnt)-__offs); \ |
|
974 |
DEBUGBUFFER(buf); \ |
|
975 |
if (__cnt > 0) { \ |
|
976 |
__offs += __cnt; \ |
|
977 |
} \ |
|
978 |
break; \ |
|
979 |
} \ |
|
980 |
if (__offs > 0) \ |
|
981 |
(ret) = __offs; \ |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
982 |
} \ |
3681 | 983 |
SETFLAGS(fileno(f), oldFlags); \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
984 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
985 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
986 |
# endif /* use STDIO */ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
987 |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
988 |
/* |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
989 |
* 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
|
990 |
* (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
|
991 |
*/ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
992 |
# ifdef NO_STDIO |
12548 | 993 |
# 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
|
994 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
995 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
996 |
int __offs = 0; \ |
7540
7cd542f29024
Fix reading when readAheadBuffer is filled and following read fails
Stefan Vogel <sv@exept.de>
parents:
7503
diff
changeset
|
997 |
int __cnt; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
998 |
char *buf = (char *)(obj); \ |
23743 | 999 |
\ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1000 |
(ret) = 0; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1001 |
{ \ |
23743 | 1002 |
while (__offs < (cnt)) { \ |
1003 |
OBJ rA = __INST(readAhead); \ |
|
1004 |
if (rA != nil) { \ |
|
1005 |
(buf)[__ooffs+__offs] = __intVal(rA); \ |
|
1006 |
DEBUGBUFFER(buf); \ |
|
1007 |
__INST(readAhead) = nil; \ |
|
1008 |
__offs++; \ |
|
1009 |
} else { \ |
|
1010 |
CLEAR_ERRNO; \ |
|
1011 |
__cnt = READ(f, (buf)+__ooffs+__offs, (cnt)-__offs, handleType); \ |
|
1012 |
DEBUGBUFFER(buf); \ |
|
1013 |
if (__cnt <= 0) { \ |
|
1014 |
if (__cnt < 0 && errno == EINTR) { \ |
|
1015 |
__HANDLE_INTERRUPTS__; \ |
|
1016 |
/* refetch */ \ |
|
1017 |
buf = (char *)(obj); \ |
|
1018 |
continue; \ |
|
1019 |
} \ |
|
1020 |
break; \ |
|
1021 |
} \ |
|
1022 |
__offs += __cnt; \ |
|
1023 |
} \ |
|
1024 |
} \ |
|
1025 |
if (__offs > 0) \ |
|
1026 |
(ret) = __offs; \ |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1027 |
} \ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1028 |
} |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
1029 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1030 |
# else /* use STDIO */ |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
1031 |
|
12548 | 1032 |
# 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
|
1033 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1034 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1035 |
int __offs = 0; \ |
7540
7cd542f29024
Fix reading when readAheadBuffer is filled and following read fails
Stefan Vogel <sv@exept.de>
parents:
7503
diff
changeset
|
1036 |
int __cnt; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1037 |
char *buf = (char *)(obj); \ |
23743 | 1038 |
\ |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1039 |
(ret) = 0; \ |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1040 |
if (isBuffered) { \ |
23743 | 1041 |
while (__offs < (cnt)) { \ |
1042 |
CLEAR_ERRNO; \ |
|
1043 |
(ret) = getc(f); \ |
|
1044 |
if ((ret) < 0) { \ |
|
1045 |
if (ferror(f)) { \ |
|
1046 |
if (errno == EINTR) { \ |
|
1047 |
__HANDLE_INTERRUPTS__; \ |
|
1048 |
clearerr(f); \ |
|
1049 |
/* refetch */ \ |
|
1050 |
buf = (char *)(obj); \ |
|
1051 |
DEBUGBUFFER(buf); \ |
|
1052 |
continue; \ |
|
1053 |
} \ |
|
1054 |
} else { \ |
|
1055 |
(ret) = 0; \ |
|
1056 |
} \ |
|
1057 |
break; \ |
|
1058 |
} \ |
|
1059 |
(buf)[__ooffs+__offs] = (ret); \ |
|
1060 |
DEBUGBUFFER(buf); \ |
|
1061 |
__offs++; \ |
|
1062 |
} \ |
|
1063 |
if (__offs > 0) \ |
|
1064 |
(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
|
1065 |
} else { \ |
23743 | 1066 |
int fd = fileno(f); \ |
1067 |
\ |
|
1068 |
while (__offs < (cnt)) { \ |
|
1069 |
OBJ rA = __INST(readAhead); \ |
|
1070 |
if (rA != nil) { \ |
|
1071 |
(buf)[__ooffs+__offs] = __intVal(rA); \ |
|
1072 |
DEBUGBUFFER(buf); \ |
|
1073 |
__INST(readAhead) = nil; \ |
|
1074 |
__offs++; \ |
|
1075 |
} else { \ |
|
1076 |
CLEAR_ERRNO; \ |
|
1077 |
__cnt = read(fd, (buf)+__ooffs+__offs, (cnt)-__offs); \ |
|
1078 |
DEBUGBUFFER(buf); \ |
|
1079 |
if (__cnt <= 0) { \ |
|
1080 |
if (__cnt < 0 && errno == EINTR) { \ |
|
1081 |
__HANDLE_INTERRUPTS__; \ |
|
1082 |
/* refetch */ \ |
|
1083 |
buf = (char *)(obj); \ |
|
1084 |
continue; \ |
|
1085 |
} \ |
|
1086 |
break; \ |
|
1087 |
} \ |
|
1088 |
__offs += __cnt; \ |
|
1089 |
} \ |
|
1090 |
} \ |
|
1091 |
if (__offs > 0) \ |
|
1092 |
(ret) = __offs; \ |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1093 |
} \ |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1094 |
} |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1095 |
|
12548 | 1096 |
# 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
|
1097 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1098 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1099 |
int __offs = 0; \ |
7540
7cd542f29024
Fix reading when readAheadBuffer is filled and following read fails
Stefan Vogel <sv@exept.de>
parents:
7503
diff
changeset
|
1100 |
int __cnt; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1101 |
char *buf = (char *)(obj); \ |
15342 | 1102 |
int oldFlags; \ |
23743 | 1103 |
\ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1104 |
(ret) = 0; \ |
15342 | 1105 |
SETNONBLOCKING(fileno(f), oldFlags); \ |
23743 | 1106 |
\ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1107 |
if (isBuffered) { \ |
23743 | 1108 |
while (__offs < (cnt)) { \ |
1109 |
CLEAR_ERRNO; \ |
|
1110 |
(ret) = getc(f); \ |
|
1111 |
if ((ret) < 0) { \ |
|
1112 |
if (ferror(f)) { \ |
|
1113 |
if (errno == EINTR) { \ |
|
1114 |
clearerr(f); \ |
|
1115 |
/* refetch */ \ |
|
1116 |
buf = (char *)(obj); \ |
|
1117 |
(ret) = 0; \ |
|
1118 |
break; \ |
|
1119 |
} \ |
|
1120 |
} else { \ |
|
1121 |
(ret) = 0; \ |
|
1122 |
} \ |
|
1123 |
break; \ |
|
1124 |
} \ |
|
1125 |
(buf)[__ooffs+__offs] = (ret); \ |
|
1126 |
DEBUGBUFFER(buf); \ |
|
1127 |
__offs++; \ |
|
1128 |
} \ |
|
1129 |
if (__offs > 0) \ |
|
1130 |
(ret) = __offs; \ |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1131 |
} else { \ |
23743 | 1132 |
int fd = fileno(f); \ |
1133 |
\ |
|
1134 |
while (__offs < (cnt)) { \ |
|
1135 |
OBJ rA = __INST(readAhead); \ |
|
1136 |
if (rA != nil) { \ |
|
1137 |
(buf)[__ooffs+__offs] = __intVal(rA); \ |
|
1138 |
DEBUGBUFFER(buf); \ |
|
1139 |
__INST(readAhead) = nil; \ |
|
1140 |
__offs++; \ |
|
1141 |
continue; \ |
|
1142 |
} \ |
|
1143 |
CLEAR_ERRNO; \ |
|
1144 |
__cnt = read(fd, (buf)+__ooffs+__offs, (cnt)-__offs); \ |
|
1145 |
DEBUGBUFFER(buf); \ |
|
1146 |
if (__cnt > 0) { \ |
|
1147 |
__offs += __cnt; \ |
|
1148 |
} \ |
|
1149 |
break; \ |
|
1150 |
} \ |
|
1151 |
if (__offs > 0) \ |
|
1152 |
(ret) = __offs; \ |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1153 |
} \ |
15342 | 1154 |
SETFLAGS(fileno(f), oldFlags); \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1155 |
} |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1156 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1157 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1158 |
# endif /* use STDIO */ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1159 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1160 |
# ifdef NO_STDIO |
12548 | 1161 |
# define __WRITEBYTE__(ret, f, buf, isBuffered, handleType) \ |
23743 | 1162 |
for (;;) { \ |
1163 |
CLEAR_ERRNO; \ |
|
1164 |
(ret) = WRITE(f, buf, 1, handleType); \ |
|
1165 |
if ((ret) >= 0) break; \ |
|
1166 |
if (errno != EINTR) { \ |
|
1167 |
break; \ |
|
1168 |
} \ |
|
1169 |
__HANDLE_INTERRUPTS__; \ |
|
1170 |
} |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1171 |
# else /* use STDIO */ |
12548 | 1172 |
# 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
|
1173 |
if (isBuffered) { \ |
23743 | 1174 |
for (;;) { \ |
1175 |
CLEAR_ERRNO; \ |
|
1176 |
ret = putc(*(buf), f); \ |
|
1177 |
if ((ret) >= 0) { \ |
|
1178 |
(ret) = 1; \ |
|
1179 |
} else if (ferror(f)) { \ |
|
1180 |
/* SOLARIS/SPARC (2.6) generates spurious errors with errno = 0 */ \ |
|
1181 |
if (errno == EINTR || errno == 0) { \ |
|
1182 |
__HANDLE_INTERRUPTS__; \ |
|
1183 |
clearerr(f); \ |
|
1184 |
continue; \ |
|
1185 |
} \ |
|
1186 |
} else \ |
|
1187 |
(ret) = 0; \ |
|
1188 |
break; \ |
|
1189 |
} \ |
|
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
1190 |
} else { \ |
23743 | 1191 |
for (;;) { \ |
1192 |
CLEAR_ERRNO; \ |
|
1193 |
(ret) = write(fileno(f), buf, 1); \ |
|
1194 |
if ((ret) >= 0) break; \ |
|
1195 |
if (errno != EINTR) { \ |
|
1196 |
break; \ |
|
1197 |
} \ |
|
1198 |
__HANDLE_INTERRUPTS__; \ |
|
1199 |
} \ |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1200 |
} |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1201 |
# endif /* use STDIO */ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1202 |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1203 |
/* |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1204 |
* 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
|
1205 |
* (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
|
1206 |
*/ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1207 |
# ifdef NO_STDIO |
12548 | 1208 |
# define __WRITEBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
2961 | 1209 |
(ret) = 0; \ |
1210 |
{ \ |
|
23743 | 1211 |
int __offs = 0; \ |
1212 |
while (__offs < (cnt)) { \ |
|
1213 |
CLEAR_ERRNO; \ |
|
1214 |
ret = WRITE(f, (buf)+__offs, (cnt)-__offs, handleType); \ |
|
1215 |
if (ret <= 0) { \ |
|
1216 |
if (ret < 0 && errno == EINTR) { \ |
|
1217 |
__HANDLE_INTERRUPTS__; \ |
|
1218 |
continue; \ |
|
1219 |
} \ |
|
1220 |
break; \ |
|
1221 |
} \ |
|
1222 |
__offs += (ret); \ |
|
1223 |
} \ |
|
1224 |
if (__offs > 0) \ |
|
1225 |
(ret) = __offs; \ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1226 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1227 |
# else /* use STDIO */ |
12548 | 1228 |
# define __WRITEBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
2961 | 1229 |
(ret) = 0; \ |
1230 |
if (isBuffered) { \ |
|
23743 | 1231 |
int __offs = 0; \ |
1232 |
while (__offs < (cnt)) { \ |
|
1233 |
CLEAR_ERRNO; \ |
|
1234 |
(ret) = fwrite((buf)+__offs, 1, (cnt)-__offs, f);\ |
|
1235 |
if ((ret) <= 0) { \ |
|
1236 |
if (ferror(f)) { \ |
|
1237 |
if (errno == EINTR) { \ |
|
1238 |
__HANDLE_INTERRUPTS__; \ |
|
1239 |
clearerr(f); \ |
|
1240 |
continue; \ |
|
1241 |
} \ |
|
1242 |
} else { \ |
|
1243 |
(ret) = 0; \ |
|
1244 |
} \ |
|
1245 |
break; \ |
|
1246 |
} \ |
|
1247 |
__offs += (ret); \ |
|
1248 |
} \ |
|
1249 |
if (__offs > 0) \ |
|
1250 |
(ret) = __offs; \ |
|
2961 | 1251 |
} else { \ |
23743 | 1252 |
int __offs = 0; \ |
1253 |
while (__offs < (cnt)) { \ |
|
1254 |
CLEAR_ERRNO; \ |
|
1255 |
(ret) = write(fileno(f), (buf)+__offs, (cnt)-__offs);\ |
|
1256 |
if ((ret) <= 0) { \ |
|
1257 |
if ((ret) < 0) { \ |
|
1258 |
if (errno == EINTR) { \ |
|
1259 |
__HANDLE_INTERRUPTS__; \ |
|
1260 |
continue; \ |
|
1261 |
} \ |
|
1262 |
} \ |
|
1263 |
break; \ |
|
1264 |
} \ |
|
1265 |
__offs += (ret); \ |
|
1266 |
} \ |
|
1267 |
if (__offs > 0) \ |
|
1268 |
(ret) = __offs; \ |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1269 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1270 |
# endif /* use STDIO */ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1271 |
|
223 | 1272 |
/* |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1273 |
* 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
|
1274 |
* (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
|
1275 |
*/ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1276 |
# ifdef NO_STDIO |
12548 | 1277 |
# 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
|
1278 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1279 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1280 |
int __offs = 0; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1281 |
char *buf = (char *)(obj); \ |
23743 | 1282 |
\ |
2961 | 1283 |
(ret) = 0; \ |
1284 |
{ \ |
|
23743 | 1285 |
while (__offs < (cnt)) { \ |
1286 |
CLEAR_ERRNO; \ |
|
1287 |
ret = WRITE(f, (buf)+__ooffs+__offs, (cnt)-__offs, handleType); \ |
|
1288 |
if (ret <= 0) { \ |
|
1289 |
if (ret < 0 && errno == EINTR) { \ |
|
1290 |
__HANDLE_INTERRUPTS__; \ |
|
1291 |
/* refetch */ \ |
|
1292 |
buf = (char *)(obj); \ |
|
1293 |
continue; \ |
|
1294 |
} \ |
|
1295 |
break; \ |
|
1296 |
} \ |
|
1297 |
__offs += (ret); \ |
|
1298 |
} \ |
|
1299 |
if (__offs > 0) \ |
|
1300 |
(ret) = __offs; \ |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1301 |
} \ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1302 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1303 |
# else /* use STDIO */ |
12548 | 1304 |
# 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
|
1305 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1306 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1307 |
int __offs = 0; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1308 |
char *buf = (char *)(obj); \ |
23743 | 1309 |
\ |
2961 | 1310 |
(ret) = 0; \ |
1311 |
if (isBuffered) { \ |
|
23743 | 1312 |
while (__offs < (cnt)) { \ |
1313 |
CLEAR_ERRNO; \ |
|
1314 |
(ret) = fwrite((buf)+__ooffs+__offs, 1, (cnt)-__offs, f); \ |
|
1315 |
if ((ret) <= 0) { \ |
|
1316 |
if (ferror(f)) { \ |
|
1317 |
if (errno == EINTR) { \ |
|
1318 |
__HANDLE_INTERRUPTS__; \ |
|
1319 |
/* refetch */ \ |
|
1320 |
buf = (char *)(obj); \ |
|
1321 |
clearerr(f); \ |
|
1322 |
continue; \ |
|
1323 |
} \ |
|
1324 |
break; \ |
|
1325 |
} else { \ |
|
1326 |
(ret) = 0; \ |
|
1327 |
} \ |
|
1328 |
} \ |
|
1329 |
__offs += (ret); \ |
|
1330 |
} \ |
|
2961 | 1331 |
} else { \ |
23743 | 1332 |
while (__offs < (cnt)) { \ |
1333 |
CLEAR_ERRNO; \ |
|
1334 |
(ret) = write(fileno(f), (buf)+__ooffs+__offs, (cnt)-__offs); \ |
|
1335 |
if ((ret) <= 0) { \ |
|
1336 |
if ((ret) < 0) { \ |
|
1337 |
if (errno == EINTR){ \ |
|
1338 |
__HANDLE_INTERRUPTS__; \ |
|
1339 |
/* refetch */ \ |
|
1340 |
buf = (char *)(obj); \ |
|
1341 |
continue; \ |
|
1342 |
} \ |
|
1343 |
} \ |
|
1344 |
break; \ |
|
1345 |
} \ |
|
1346 |
__offs += (ret); \ |
|
1347 |
} \ |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1348 |
} \ |
15845 | 1349 |
if (__offs > 0) \ |
23743 | 1350 |
(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
|
1351 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1352 |
# endif /* use STDIO */ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1353 |
#endif /* unix */ |
1 | 1354 |
%} |
188 | 1355 |
! ! |
1 | 1356 |
|
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1357 |
!ExternalStream class methodsFor:'documentation'! |
22 | 1358 |
|
88 | 1359 |
copyright |
1360 |
" |
|
1361 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1362 |
All Rights Reserved |
88 | 1363 |
|
1364 |
This software is furnished under a license and may be used |
|
1365 |
only in accordance with the terms of that license and with the |
|
1366 |
inclusion of the above copyright notice. This software may not |
|
1367 |
be provided or otherwise made available to, or used by, any |
|
1368 |
other person. No title to or ownership of the software is |
|
1369 |
hereby transferred. |
|
1370 |
" |
|
1371 |
! |
|
1372 |
||
22 | 1373 |
documentation |
1374 |
" |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1375 |
ExternalStream defines protocol common to Streams which have a file-descriptor and |
68 | 1376 |
represent some file or communicationChannel of the underlying OperatingSystem. |
1377 |
ExternalStream is abstract; concrete classes are FileStream, PipeStream etc. |
|
77 | 1378 |
|
159 | 1379 |
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
|
1380 |
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
|
1381 |
while in binary-mode the basic elements are bytes which read/write as SmallIntegers |
68 | 1382 |
in the range 0..255. |
22 | 1383 |
|
68 | 1384 |
Also, the stream can be either in buffered or unbuffered mode. In buffered mode, |
1385 |
data is not written until either a cr is written (in text mode) or a synchronizeOutput |
|
1386 |
is sent (in both modes). |
|
22 | 1387 |
|
77 | 1388 |
The underlying OperatingSystem streams may either be closed explicitely (sending a close) |
68 | 1389 |
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
|
1390 |
object AND a close will be performed automatically (but you will NOT know when this |
77 | 1391 |
happens - so it is recommended, that you close your files when no longer needed). |
159 | 1392 |
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
|
1393 |
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
|
1394 |
All streams understand the close message, so it never hurts to use it (it is defined as |
77 | 1395 |
a noop in one of the superclasses). |
22 | 1396 |
|
68 | 1397 |
Most of the methods found here redefine inherited methods for better performance, |
1398 |
since I/O from/to files should be fast. |
|
22 | 1399 |
|
68 | 1400 |
Recovering a snapshot: |
1295 | 1401 |
not all streams can be restored to the state they had before - see the implementation of |
1402 |
reOpen in subclasses for more information. |
|
1403 |
For streams sitting on some communication channel (i.e. Pipes and Sockets) you should |
|
1404 |
reestablish the stream upon image restart (make someone dependent on ObjectMemory). |
|
1405 |
FileStreams are reopened and positioned to their offset they had at snapshot time. |
|
1406 |
This may fail, if the file was removed or renamed - or lead to confusion |
|
1407 |
if the contents changed in the meantime. |
|
1408 |
Therefore, it is a good idea to reopen files and check for these things at restart time. |
|
1409 |
||
1410 |
[Instance variables:] |
|
1411 |
||
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1412 |
handleType <Symbol> desribes what handle is: |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1413 |
win32: #fileHandle, #socketHandle, |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1414 |
#filePointer, #socketFilePointer, #pipeFilePointer |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1415 |
unix: #filePointer, #socketFilePointer, #pipeFilePointer |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1416 |
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
|
1417 |
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
|
1418 |
now, either a filePointer or a handle (win32) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1419 |
mode <Symbol> #readwrite, #readonly or #writeonly |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1420 |
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
|
1421 |
not output immediately) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1422 |
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
|
1423 |
eolMode <Symbol> one of nil, #nl, #cr or #crlf. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1424 |
determines how lines should be terminated. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1425 |
nil -> newLine (as in Unix); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1426 |
#crlf -> with cr-lf (as in MSDOS) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1427 |
#cr -> with cr (as in VMS) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1428 |
hitEOF <Boolean> true, if EOF was reached |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1429 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1430 |
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
|
1431 |
updated with next i/o operation) |
1295 | 1432 |
|
1433 |
[Class variables:] |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1434 |
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
|
1435 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1436 |
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
|
1437 |
InvalidReadSignal <Signal> raised on read from writeonly stream |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1438 |
InvalidWriteSignal <Signal> raised on write to readonly stream |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1439 |
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
|
1440 |
or binary I/O with text-stream |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1441 |
OpenErrorSignal <Signal> raised if open fails |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1442 |
StreamNotOpenSignal <Signal> raised on I/O with non-open stream |
159 | 1443 |
|
1444 |
Additional notes: |
|
1445 |
This class is implemented using the underlying stdio-c library package, which |
|
1446 |
has both advantages and disadvantages: since it is portable (posix defined), porting |
|
1447 |
ST/X to non-Unix machines is simplified. The disadvantage is that the stdio library |
|
1448 |
has big problems handling unbounded Streams, since the EOF handling in stdio is |
|
1449 |
not prepared for data to arrive after EOF has been reached - time will show, if we need |
|
1450 |
a complete rewrite for UnboundedStream ... |
|
325 | 1451 |
|
188 | 1452 |
Also, depending on the system, the stdio library behaves infriendly when signals |
1453 |
occur while reading (for example, timer interrupts) - on real unixes (i.e. BSD) the signal |
|
1454 |
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
|
1455 |
an error and errno is set to EINTR. |
20411 | 1456 |
That's what the ugly code around all getc-calls is for ... |
1295 | 1457 |
Since things get more and more ugly - we will rewrite ExternalStream |
1458 |
completely, to NOT use any stdio stuff (and do its buffering itself). |
|
325 | 1459 |
|
1460 |
Notice that typical stdio's use a single errno global variable to return an error code, |
|
16508 | 1461 |
this was bad design in the stdio lib (right from the very beginning), since it's much |
325 | 1462 |
harder to deal with this in the presence of lightweight processes, where errno gets |
1463 |
overwritten by an I/O operation done in another thread. (stdio should have been written |
|
1464 |
to return errno as a negative number ...). |
|
1465 |
To deal with this, the scheduler treats errno like a per-thread private variable, |
|
1466 |
and saves/restores the errno setting when switching to another thread. |
|
1467 |
(Notice that some thread packages do this also, but ST/X's thread implementation |
|
1468 |
does not depend on those, but instead uses a portable private package). |
|
1469 |
||
216 | 1470 |
Finally, if an stdio-stream is open for both reading and writing, we have to call |
1471 |
fseek whenever we are about to read after write and vice versa. |
|
1472 |
Two macros (__READING__ and __WRITING__) have been defined to be used before every |
|
1473 |
fread/fgetc and fwrite/putc respectively. |
|
1295 | 1474 |
|
1475 |
[author:] |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1476 |
Claus Gittinger |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1477 |
Stefan Vogel (many, many fixes ...) |
1295 | 1478 |
|
1479 |
[see also:] |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1480 |
FileStream Socket PipeStream |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1481 |
Filename OperatingSystem |
22 | 1482 |
" |
3255 | 1483 |
! |
1484 |
||
1485 |
examples |
|
1486 |
" |
|
1487 |
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
|
1488 |
[exBegin] |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1489 |
|topView scrollPane textView fileStream text| |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1490 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1491 |
topView := StandardSystemView new. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1492 |
topView label:'contents of Makefile'. |
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 |
scrollPane := HVScrollableView in:topView. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1495 |
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
|
1496 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1497 |
textView := EditTextView new. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1498 |
scrollPane scrolledView:textView. |
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 |
fileStream := 'Makefile' asFilename readStream. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1501 |
text := fileStream upToEnd. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1502 |
fileStream close. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1503 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1504 |
textView contents:text. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1505 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1506 |
topView open. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1507 |
[exEnd] |
3255 | 1508 |
|
1509 |
||
1510 |
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
|
1511 |
[exBegin] |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1512 |
EditTextView openOn:'Makefile' |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1513 |
[exEnd] |
3255 | 1514 |
" |
22 | 1515 |
! ! |
1516 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1517 |
!ExternalStream class methodsFor:'initialization'! |
1 | 1518 |
|
18636 | 1519 |
closeFiles |
1520 |
"close all files. |
|
1521 |
To be called on exit of Smalltalk." |
|
1522 |
||
1523 |
Lobby do:[:eachFileStream | |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1524 |
(eachFileStream ~~ Stdin |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1525 |
and:[eachFileStream ~~ Stdout |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1526 |
and:[eachFileStream ~~ Stderr]]) ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1527 |
eachFileStream close |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1528 |
]. |
18636 | 1529 |
]. |
22709 | 1530 |
|
1531 |
"Modified: / 25-04-2018 / 15:23:41 / stefan" |
|
18636 | 1532 |
! |
1533 |
||
2920 | 1534 |
initDefaultEOLMode |
1535 |
OperatingSystem isUNIXlike ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1536 |
"/ unix EOL conventions |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1537 |
DefaultEOLMode := #nl |
2920 | 1538 |
] ifFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1539 |
OperatingSystem isVMSlike ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1540 |
"/ vms EOL conventions |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1541 |
DefaultEOLMode := #cr |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1542 |
] ifFalse:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1543 |
"/ msdos EOL conventions |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1544 |
"/ msdos uses #crlf. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1545 |
"/ the following breaks all programs, which do not explicitly |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1546 |
"/ 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
|
1547 |
"/ MUST change all classes before doing the following. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1548 |
"/ 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
|
1549 |
"/ mode (for a while, I hope). |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1550 |
DefaultEOLMode := #crlf. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1551 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1552 |
"/ DefaultEOLMode := #nl |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1553 |
] |
2920 | 1554 |
] |
1555 |
! |
|
1556 |
||
1557 |
initModeStrings |
|
1558 |
"initialize modeStrings which are passed down to the underlying |
|
1559 |
fopen/fdopen functions." |
|
1560 |
||
3132
037027ae20fd
msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1561 |
OperatingSystem isMSDOSlike ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1562 |
ReadMode := 'rb'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1563 |
ReadWriteMode := 'rb+'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1564 |
WriteMode := 'wb'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1565 |
AppendMode := 'ab+'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1566 |
CreateReadWriteMode := 'wb+'. |
3132
037027ae20fd
msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1567 |
] ifFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1568 |
ReadMode := 'r'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1569 |
ReadWriteMode := 'r+'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1570 |
WriteMode := 'w'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1571 |
AppendMode := 'a+'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1572 |
CreateReadWriteMode := 'w+'. |
3132
037027ae20fd
msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1573 |
] |
2920 | 1574 |
! |
1575 |
||
1 | 1576 |
initialize |
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
583
diff
changeset
|
1577 |
OpenErrorSignal isNil ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1578 |
OpenErrorSignal := OpenError. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1579 |
OpenErrorSignal notifierString:'open error'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1580 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1581 |
InvalidReadSignal := InvalidReadError. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1582 |
InvalidReadSignal notifierString:'stream does not support reading'. |
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 |
InvalidWriteSignal := InvalidWriteError. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1585 |
InvalidWriteSignal notifierString:'stream does not support writing'. |
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 |
InvalidModeSignal := InvalidModeError. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1588 |
InvalidModeSignal notifierString:'binary/text mode mismatch'. |
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 |
InvalidOperationSignal := InvalidOperationError. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1591 |
InvalidOperationSignal notifierString:'unsupported file operation'. |
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 |
StreamNotOpenSignal := StreamNotOpenError. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1594 |
StreamNotOpenSignal notifierString:'stream is not open'. |
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 |
StreamIOErrorSignal := StreamIOError. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1597 |
StreamIOErrorSignal notifierString:'I/O error'. |
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 |
"/ self patchByteOrderOptimizedMethods |
159 | 1600 |
]. |
1601 |
||
31 | 1602 |
Lobby isNil ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1603 |
Lobby := Registry new. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1604 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1605 |
"want to get informed when returning from snapshot" |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1606 |
ObjectMemory addDependent:self |
2920 | 1607 |
]. |
5442 | 1608 |
DefaultEOLMode isNil ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1609 |
self initDefaultEOLMode. |
5442 | 1610 |
]. |
1611 |
ReadMode isNil ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1612 |
self initModeStrings. |
5442 | 1613 |
]. |
18790 | 1614 |
|
1615 |
"limit the amount of newspace to be used for non-tenurable executors to 5%" |
|
18929 | 1616 |
"/ MaxNonTenurableExecutors := ObjectMemory newSpaceSize // (Socket sizeOfInst:0) // 20. |
1617 |
"/ cg: changed because Socket is not in libbasic. Thus, standalone (libbasic only) |
|
1618 |
"/ 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
|
1619 |
MaxNonTenurableExecutors := (ObjectMemory newSpaceSize // 20 min:2000). |
18790 | 1620 |
|
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1621 |
"Modified: / 21.5.1998 / 16:33:53 / cg" |
1 | 1622 |
! |
1623 |
||
19615 | 1624 |
patchByteOrderOptimizedMethods |
1625 |
"EXPERIMENTAL (not yet done by default): |
|
1626 |
change the underlying implementation of |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1627 |
nextPutInt16MSB / nextPutInt16LSB |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1628 |
nextPutInt32MSB / nextPutInt32LSB |
19615 | 1629 |
to the corresponding NATIVE methods." |
1630 |
||
1631 |
|native16 native32| |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
1632 |
|
19615 | 1633 |
native16 := self compiledMethodAt:#nextPutInt16NATIVE:. |
1634 |
native32 := self compiledMethodAt:#nextPutInt32NATIVE:. |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
1635 |
|
19615 | 1636 |
UninterpretedBytes isBigEndian ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1637 |
(self compiledMethodAt:#nextPutInt16MSB:) code:(native16 code). |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1638 |
(self compiledMethodAt:#nextPutInt32MSB:) code:(native32 code). |
19615 | 1639 |
] ifFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1640 |
(self compiledMethodAt:#nextPutInt16LSB:) code:(native16 code). |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1641 |
(self compiledMethodAt:#nextPutInt32LSB:) code:(native32 code). |
19615 | 1642 |
]. |
1643 |
! |
|
1644 |
||
1 | 1645 |
reOpenFiles |
4108
8c4a45bc70eb
perform reOpen of streams earlier (before doing the view-reinit)
Claus Gittinger <cg@exept.de>
parents:
4093
diff
changeset
|
1646 |
"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
|
1647 |
This is invoked via the #earlyRestart change notification." |
1 | 1648 |
|
18636 | 1649 |
Lobby do:[:eachFileStream | |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1650 |
eachFileStream reOpen |
2920 | 1651 |
]. |
1 | 1652 |
! |
1653 |
||
1469 | 1654 |
update:something with:aParameter from:changedObject |
1 | 1655 |
"have to reopen files when returning from snapshot" |
1656 |
||
4108
8c4a45bc70eb
perform reOpen of streams earlier (before doing the view-reinit)
Claus Gittinger <cg@exept.de>
parents:
4093
diff
changeset
|
1657 |
something == #earlyRestart ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1658 |
self reOpenFiles. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1659 |
self initDefaultEOLMode |
1 | 1660 |
] |
1469 | 1661 |
|
1662 |
"Created: 15.6.1996 / 15:19:59 / cg" |
|
1 | 1663 |
! ! |
1664 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1665 |
!ExternalStream class methodsFor:'instance creation'! |
612 | 1666 |
|
12706 | 1667 |
forFileDescriptor:aFileDescriptor mode:modeSymbol |
2920 | 1668 |
"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
|
1669 |
to operate on this fd. |
12706 | 1670 |
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
|
1671 |
This may be used to wrap fd's as returned by user |
2920 | 1672 |
primitive code, or to wrap pipe-fds into externalStreams." |
1673 |
||
12706 | 1674 |
^ self forFileDescriptor:aFileDescriptor mode:modeSymbol buffered:true handleType:nil |
7002 | 1675 |
|
1676 |
" |
|
1677 |
the example below will probably fail (15 is a random FD): |
|
1678 |
||
1679 |
|s| |
|
1680 |
||
1681 |
s := ExternalStream forFileDescriptor:15 mode:'r'. |
|
1682 |
s next. |
|
1683 |
" |
|
1684 |
||
1685 |
"Created: 29.2.1996 / 18:05:00 / cg" |
|
1686 |
"Modified: 29.2.1996 / 18:17:07 / cg" |
|
1687 |
! |
|
1688 |
||
12706 | 1689 |
forFileDescriptor:aFileDescriptor mode:modeSymbol buffered:buffered handleType:handleTypeSymbol |
7002 | 1690 |
"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
|
1691 |
to operate on this fd. |
12706 | 1692 |
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
|
1693 |
This may be used to wrap fd's as returned by user |
7002 | 1694 |
primitive code, or to wrap pipe-fds into externalStreams." |
1695 |
||
21224 | 1696 |
^ self new |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1697 |
buffered:buffered; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1698 |
connectTo:aFileDescriptor withMode:modeSymbol handleType:handleTypeSymbol. |
2920 | 1699 |
|
1700 |
" |
|
1701 |
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
|
1702 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1703 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1704 |
|
21224 | 1705 |
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
|
1706 |
s next. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1707 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1708 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1709 |
"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
|
1710 |
"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
|
1711 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1712 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1713 |
forReadWriteToFileDescriptor:aFileDescriptor |
2920 | 1714 |
"given a fileDescriptor, create an ExternalStream object |
1715 |
to read/write from/to this fd. This may be used to wrap fd's |
|
1716 |
as returned by user primitive code, or to wrap pipe- |
|
1717 |
filedescriptors into externalStreams." |
|
1718 |
||
12706 | 1719 |
^ self forFileDescriptor:aFileDescriptor mode:#readWrite |
2920 | 1720 |
|
1721 |
" |
|
1722 |
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
|
1723 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1724 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1725 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1726 |
s := ExternalStream forReadWriteToFileDescriptor:15. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1727 |
s next. |
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 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1730 |
"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
|
1731 |
"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
|
1732 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1733 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1734 |
forReadingFromFileDescriptor:aFileDescriptor |
2920 | 1735 |
"given a fileDescriptor, create an ExternalStream object |
1736 |
to read from this fd. This may be used to wrap fd's |
|
1737 |
as returned by user primitive code, or to wrap pipe- |
|
1738 |
filedescriptors into externalStreams." |
|
1739 |
||
12706 | 1740 |
^ self forFileDescriptor:aFileDescriptor mode:#readonly |
2920 | 1741 |
|
1742 |
" |
|
1743 |
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
|
1744 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1745 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1746 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1747 |
s := ExternalStream forReadingFromFileDescriptor:15. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1748 |
s next. |
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 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1751 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1752 |
|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
|
1753 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1754 |
'create OS pipe ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1755 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1756 |
pipe := OperatingSystem makePipe. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1757 |
readFd := pipe at:1. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1758 |
writeFd := pipe at:2. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1759 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1760 |
'connect Smalltalk streams ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1761 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1762 |
rs := ExternalStream forReadingFromFileDescriptor:readFd. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1763 |
ws := ExternalStream forWritingToFileDescriptor:writeFd. |
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 |
'read ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1766 |
[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1767 |
1 to:10 do:[:i | |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1768 |
Transcript showCR:rs nextLine |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1769 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1770 |
rs close. |
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1771 |
] forkAt:7. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1772 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1773 |
'write ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1774 |
[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1775 |
1 to:10 do:[:i | |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1776 |
ws nextPutAll:'hello world '; nextPutAll:i printString; cr |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1777 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1778 |
ws close. |
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1779 |
] fork. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1780 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1781 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1782 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1783 |
"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
|
1784 |
"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
|
1785 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1786 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1787 |
forWritingToFileDescriptor:aFileDescriptor |
2920 | 1788 |
"given a fileDescriptor, create an ExternalStream object |
1789 |
to write to this fd. This may be used to wrap fd's |
|
1790 |
as returned by user primitive code, or to wrap pipe- |
|
1791 |
filedescriptors into externalStreams." |
|
1792 |
||
12706 | 1793 |
^ self forFileDescriptor:aFileDescriptor mode:#writeonly |
2920 | 1794 |
|
1795 |
" |
|
1796 |
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
|
1797 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1798 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1799 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1800 |
s := ExternalStream forWritingToFileDescriptor:15. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1801 |
s binary. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1802 |
s nextPut:1. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1803 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1804 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1805 |
"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
|
1806 |
"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
|
1807 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1808 |
|
612 | 1809 |
new |
15918
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
1810 |
"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
|
1811 |
|
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
1812 |
^ self basicNew initialize. |
612 | 1813 |
! ! |
1814 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1815 |
!ExternalStream class methodsFor:'Signal constants'! |
159 | 1816 |
|
1522
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1817 |
inaccessibleSignal |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1818 |
"ST-80 compatibility: return openErrorSignal" |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1819 |
|
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1820 |
^ self openErrorSignal |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1821 |
|
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1822 |
"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
|
1823 |
! |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1824 |
|
612 | 1825 |
invalidModeSignal |
1826 |
"return the signal raised when doing text-I/O with a binary stream |
|
1827 |
or binary-I/O with a text stream" |
|
1828 |
||
8074 | 1829 |
^ InvalidModeError |
159 | 1830 |
! |
1831 |
||
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1832 |
invalidOperationSignal |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1833 |
"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
|
1834 |
I/O operation is attempted" |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1835 |
|
8074 | 1836 |
^ InvalidOperationError |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1837 |
! |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1838 |
|
159 | 1839 |
invalidReadSignal |
1840 |
"return the signal raised when reading from writeonly streams" |
|
1841 |
||
8074 | 1842 |
^ InvalidReadError |
159 | 1843 |
! |
1844 |
||
1845 |
invalidWriteSignal |
|
1846 |
"return the signal raised when writing to readonly streams" |
|
1847 |
||
8074 | 1848 |
^ InvalidWriteError |
159 | 1849 |
! |
1850 |
||
612 | 1851 |
openErrorSignal |
1852 |
"return the signal raised when a file open failed" |
|
1853 |
||
1854 |
^ OpenErrorSignal |
|
1855 |
! |
|
1856 |
||
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1857 |
streamIOErrorSignal |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1858 |
"return the signal raised when an I/O error occurs. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1859 |
(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
|
1860 |
which is no longer available and has been mounted soft)" |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1861 |
|
8074 | 1862 |
^ StreamIOError |
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1863 |
|
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1864 |
"Created: / 21.5.1998 / 16:32:55 / cg" |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1865 |
! |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1866 |
|
159 | 1867 |
streamNotOpenSignal |
1868 |
"return the signal raised on I/O with closed streams" |
|
1869 |
||
8074 | 1870 |
^ StreamNotOpenError |
2 | 1871 |
! ! |
1872 |
||
22697 | 1873 |
!ExternalStream class methodsFor:'accessing'! |
1874 |
||
1875 |
openStreams |
|
1876 |
"answer a collection of open Streams having this class" |
|
1877 |
||
1878 |
|openStreams| |
|
1879 |
||
1880 |
openStreams := OrderedCollection new. |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1881 |
Lobby keysDo:[:eachStream| |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1882 |
(eachStream isKindOf:self) ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1883 |
openStreams add:eachStream |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1884 |
] |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1885 |
]. |
22697 | 1886 |
|
1887 |
^ openStreams |
|
1888 |
||
1889 |
" |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1890 |
self openStreams |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1891 |
Socket openStreams |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1892 |
NonPositionableExternalStream openStreams |
22697 | 1893 |
" |
1894 |
||
1895 |
"Created: / 24-04-2018 / 09:23:33 / stefan" |
|
1896 |
! ! |
|
1897 |
||
21337 | 1898 |
!ExternalStream class methodsFor:'defaults'! |
1899 |
||
1900 |
defaultCopyBufferSize:anInteger |
|
1901 |
"allows changing the size of buffer used when copying big |
|
1902 |
files/buld data from one stream to another. |
|
1903 |
Due to a bug on older Windows systems, the default used in copyToEndInto: |
|
1904 |
is chosen very conservatively, as the copy used to fail with big buffers. |
|
1905 |
However, modern Windows systems seem to not suffer from that bug, |
|
22578 | 1906 |
and bigger buffer sizes will dramatically increase the performance of |
21337 | 1907 |
copies to/from network drives. |
1908 |
This method allows for fine tuning, in case you run into performance problems, |
|
1909 |
or network buffer failures. |
|
1910 |
When nil, a somewhat conservative compromise is used." |
|
22578 | 1911 |
|
21337 | 1912 |
^ DefaultCopyBufferSize |
1913 |
! ! |
|
1914 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1915 |
!ExternalStream class methodsFor:'error handling'! |
92 | 1916 |
|
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1917 |
errorReporter |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1918 |
"I know about error codes" |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1919 |
|
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1920 |
^ self |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1921 |
! |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1922 |
|
92 | 1923 |
lastErrorNumber |
159 | 1924 |
"return the errno of the last error" |
92 | 1925 |
|
1926 |
^ LastErrorNumber |
|
159 | 1927 |
|
1928 |
" |
|
1929 |
ExternalStream lastErrorNumber |
|
1930 |
" |
|
92 | 1931 |
! |
1932 |
||
1933 |
lastErrorString |
|
1934 |
"return a message string describing the last error" |
|
1935 |
||
1936 |
^ OperatingSystem errorTextForNumber:LastErrorNumber |
|
1937 |
||
1938 |
" |
|
1939 |
ExternalStream lastErrorString |
|
1940 |
" |
|
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1941 |
! |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1942 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1943 |
reportOn:anErrorSymbolOrNumber |
20259 | 1944 |
"an error occurred. |
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1945 |
Report it via an Exception" |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1946 |
|
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1947 |
anErrorSymbolOrNumber isInteger ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1948 |
StreamError |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1949 |
raiseRequestWith:anErrorSymbolOrNumber |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1950 |
errorString:(' - os error:' , (OperatingSystem errorTextForNumber:anErrorSymbolOrNumber)) |
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1951 |
]. |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1952 |
(self respondsTo:anErrorSymbolOrNumber) ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1953 |
self perform:anErrorSymbolOrNumber |
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1954 |
] ifFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1955 |
StreamError |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1956 |
raiseRequestWith:anErrorSymbolOrNumber |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1957 |
errorString:(' - ' , anErrorSymbolOrNumber printString) |
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1958 |
]. |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1959 |
^ false |
92 | 1960 |
! ! |
1961 |
||
20987 | 1962 |
!ExternalStream class methodsFor:'finalization'! |
1963 |
||
1964 |
finalizationLobby |
|
1965 |
"answer the registry used for finalization. |
|
1966 |
ExternalStreams have their own Registry" |
|
1967 |
||
1968 |
^ Lobby |
|
1969 |
! ! |
|
1970 |
||
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1971 |
!ExternalStream class methodsFor:'obsolete'! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1972 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1973 |
makePTYPair |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1974 |
"obsolete since 12-07-2003" |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1975 |
<resource:#obsolete> |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1976 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1977 |
self obsoleteMethodWarning:'use NonPositionableExternalStream makePTYPair'. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1978 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1979 |
^ NonPositionableExternalStream makePTYPair. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1980 |
! |
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 |
makePipe |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1983 |
"obsolete since 12-07-2003" |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1984 |
<resource:#obsolete> |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1985 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1986 |
self obsoleteMethodWarning:'use NonPositionableExternalStream makePipe'. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1987 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1988 |
^ NonPositionableExternalStream makePipe. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1989 |
! ! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1990 |
|
21037 | 1991 |
!ExternalStream class methodsFor:'testing'! |
1992 |
||
1993 |
isAbstract |
|
1994 |
^ self == ExternalStream |
|
1995 |
! ! |
|
1996 |
||
7261 | 1997 |
!ExternalStream methodsFor:'Compatibility-Dolphin'! |
6474 | 1998 |
|
1999 |
beText |
|
2000 |
self text |
|
2001 |
! ! |
|
2002 |
||
7261 | 2003 |
!ExternalStream methodsFor:'Compatibility-Squeak'! |
3044 | 2004 |
|
3872
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2005 |
nextInto:aByteArrayOrString |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2006 |
"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
|
2007 |
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
|
2008 |
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
|
2009 |
|
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2010 |
|n nWanted| |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2011 |
|
4368 | 2012 |
nWanted := aByteArrayOrString byteSize. |
3872
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2013 |
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
|
2014 |
n == nWanted ifTrue:[^ aByteArrayOrString]. |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2015 |
^ aByteArrayOrString copyTo:n |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2016 |
|
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2017 |
! |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2018 |
|
4368 | 2019 |
readInto:aContainer startingAt:index count:nElements |
2020 |
"same as #nextBytes:into:startingAt: for ByteArrays; |
|
2021 |
for LongArrays, nelements longs are read. |
|
3872
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2022 |
Squeak compatibility." |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2023 |
|
4368 | 2024 |
|elementSize n| |
2025 |
||
2026 |
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
|
2027 |
n := self nextBytes:nElements*elementSize into:aContainer startingAt:(index-1)*elementSize+1. |
4368 | 2028 |
^ n // elementSize |
3872
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2029 |
|
13940
12eb1c056d5e
fixed: #readInto:startingAt:count:; offset was wrong for non-byte elements
Claus Gittinger <cg@exept.de>
parents:
13927
diff
changeset
|
2030 |
"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
|
2031 |
! |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2032 |
|
3044 | 2033 |
readOnly |
2034 |
"Squeak compatibility: make the stream readOnly" |
|
2035 |
||
2036 |
mode := #readonly |
|
2037 |
||
2038 |
"Modified: 20.10.1997 / 19:23:04 / cg" |
|
2039 |
"Created: 20.10.1997 / 19:23:19 / cg" |
|
2040 |
! ! |
|
2041 |
||
5187 | 2042 |
!ExternalStream methodsFor:'Signal constants'! |
2043 |
||
2044 |
invalidReadSignal |
|
2045 |
^ self class invalidReadSignal |
|
2046 |
||
2047 |
"Created: / 3.12.1998 / 15:12:06 / cg" |
|
2048 |
! |
|
2049 |
||
2050 |
invalidWriteSignal |
|
2051 |
^ self class invalidWriteSignal |
|
2052 |
||
2053 |
"Created: / 3.12.1998 / 15:12:10 / cg" |
|
2054 |
! ! |
|
2055 |
||
1 | 2056 |
!ExternalStream methodsFor:'accessing'! |
2057 |
||
612 | 2058 |
binary |
2059 |
"switch to binary mode - default is text" |
|
2060 |
||
2061 |
binary := true |
|
1 | 2062 |
! |
2063 |
||
23900 | 2064 |
binary:beBinaryBool |
2065 |
"switch to binary mode - default is text" |
|
2066 |
||
2067 |
|wasBinary| |
|
2068 |
||
2069 |
wasBinary := binary. |
|
2070 |
binary := beBinaryBool. |
|
2071 |
^ wasBinary |
|
2072 |
||
2073 |
"Created: / 13-03-2019 / 19:18:53 / Stefan Vogel" |
|
2074 |
! |
|
2075 |
||
1 | 2076 |
buffered:aBoolean |
23900 | 2077 |
"turn buffering on or off - default is on. |
2078 |
Answer the previous bufferd state." |
|
2079 |
||
2080 |
|wasBuffered| |
|
2081 |
||
2082 |
wasBuffered := buffered. |
|
2083 |
buffered := aBoolean. |
|
2084 |
^ wasBuffered. |
|
2085 |
||
2086 |
"Modified (comment): / 13-03-2019 / 19:33:16 / Stefan Vogel" |
|
1 | 2087 |
! |
2088 |
||
2089 |
contents |
|
2 | 2090 |
"return the contents of the file from the current position up-to |
2091 |
the end. If the stream is in binary mode, a ByteArray containing |
|
2092 |
the byte values is returned. |
|
2093 |
In text-mode, a collection of strings, each representing one line, |
|
2094 |
is returned." |
|
2095 |
||
20092 | 2096 |
|text| |
2 | 2097 |
|
2098 |
binary ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2099 |
^ self upToEnd. |
2 | 2100 |
]. |
1 | 2101 |
|
20092 | 2102 |
"/ text mode |
244 | 2103 |
text := StringCollection new. |
1 | 2104 |
[self atEnd] whileFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2105 |
|line| |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2106 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2107 |
line := self nextLine. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2108 |
line isNil ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2109 |
^ text |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2110 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2111 |
text add:line |
1 | 2112 |
]. |
2113 |
^ text |
|
2114 |
! |
|
2115 |
||
11751
1e75c54748ef
added #contentsAsString for Filename compatibility
Stefan Vogel <sv@exept.de>
parents:
11651
diff
changeset
|
2116 |
contentsAsString |
1e75c54748ef
added #contentsAsString for Filename compatibility
Stefan Vogel <sv@exept.de>
parents:
11651
diff
changeset
|
2117 |
"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
|
2118 |
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
|
2119 |
|
22848 | 2120 |
binary ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2121 |
^ [ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2122 |
binary := false. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2123 |
self contentsOfEntireFile. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2124 |
] ensure:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2125 |
binary := true. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2126 |
]. |
22848 | 2127 |
]. |
2128 |
||
2129 |
^ self contentsOfEntireFile. |
|
2130 |
||
2131 |
"Modified: / 09-05-2018 / 19:37:36 / stefan" |
|
11751
1e75c54748ef
added #contentsAsString for Filename compatibility
Stefan Vogel <sv@exept.de>
parents:
11651
diff
changeset
|
2132 |
! |
1e75c54748ef
added #contentsAsString for Filename compatibility
Stefan Vogel <sv@exept.de>
parents:
11651
diff
changeset
|
2133 |
|
612 | 2134 |
contentsOfEntireFile |
3938
4e7d1880336b
oops - #contentsOfEntireFile must return a byteArray if in binaryMode.
Claus Gittinger <cg@exept.de>
parents:
3906
diff
changeset
|
2135 |
"ST-80 compatibility: return contents as a String (or byteArray, if in binary mode). |
3876 | 2136 |
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
|
2137 |
|
6305 | 2138 |
^ self upToEnd |
1522
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
2139 |
|
3876 | 2140 |
"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
|
2141 |
"Modified: / 27.11.1998 / 16:29:43 / cg" |
2 | 2142 |
! |
2143 |
||
612 | 2144 |
contentsSpecies |
2145 |
"return the kind of object to be returned by sub-collection builders |
|
2146 |
(such as upTo)" |
|
159 | 2147 |
|
21139 | 2148 |
binary ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2149 |
^ ByteArray |
159 | 2150 |
]. |
612 | 2151 |
^ String |
2 | 2152 |
! |
2153 |
||
23745 | 2154 |
dependents |
23751 | 2155 |
^ dependents ? #() |
23745 | 2156 |
|
2157 |
"Created: / 19-02-2019 / 16:08:09 / Claus Gittinger" |
|
23751 | 2158 |
"Modified: / 19-02-2019 / 23:42:56 / Claus Gittinger" |
23745 | 2159 |
! |
2160 |
||
2161 |
dependents:aDependentsCollection |
|
2162 |
dependents := aDependentsCollection |
|
2163 |
||
2164 |
"Created: / 19-02-2019 / 16:08:23 / Claus Gittinger" |
|
2165 |
! |
|
2166 |
||
16776 | 2167 |
eolMode |
2168 |
"return how end-of-line (EOL) is to be marked. |
|
2169 |
Returns one one of: |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2170 |
#crlf -> add a CR-NL, as in MSDOS |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2171 |
#cr -> add a CR, as in VMS |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2172 |
#nl -> add a NL, as in Unix |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2173 |
#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
|
2174 |
#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
|
2175 |
#nl -> add a NL, as in Unix |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2176 |
nil -> transparent |
16776 | 2177 |
" |
2178 |
||
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
|
2179 |
^ eolMode |
21097 | 2180 |
|
2181 |
"Modified (comment): / 06-12-2016 / 14:26:24 / cg" |
|
16776 | 2182 |
! |
2183 |
||
2920 | 2184 |
eolMode:aSymbolOrNil |
2185 |
"specify how end-of-line (EOL) is to be marked. |
|
2186 |
The argument may be one of: |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2187 |
#crlf -> add a CR-NL, as in MSDOS |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2188 |
#cr -> add a CR, as in VMS |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2189 |
#nl -> add a NL, as in Unix |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2190 |
#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
|
2191 |
#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
|
2192 |
anyOther -> like #nl |
2920 | 2193 |
" |
2194 |
||
17462 | 2195 |
aSymbolOrNil == #crnl ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2196 |
eolMode := #crlf |
17462 | 2197 |
] ifFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2198 |
aSymbolOrNil == #lf ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2199 |
eolMode := #nl |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2200 |
] ifFalse:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2201 |
eolMode := aSymbolOrNil |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2202 |
] |
17462 | 2203 |
]. |
21097 | 2204 |
|
2205 |
"Modified (comment): / 06-12-2016 / 14:26:37 / cg" |
|
2920 | 2206 |
! |
2207 |
||
612 | 2208 |
fileDescriptor |
2209 |
"return the fileDescriptor of the receiver - |
|
2210 |
notice: this one returns the underlying OSs fileDescriptor - |
|
2211 |
this may not be available on all platforms (i.e. non unix systems)." |
|
1 | 2212 |
|
21742 | 2213 |
|fileClosed| |
22578 | 2214 |
|
3971 | 2215 |
%{ |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2216 |
OBJ _handle = __INST(handle); |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2217 |
|
21742 | 2218 |
fileClosed = false; |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2219 |
if (_handle != nil) { |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2220 |
if ((__INST(handleType) == @symbol(fileHandle)) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2221 |
|| (__INST(handleType) == @symbol(socketHandle))) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2222 |
RETURN (_handle); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2223 |
} |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2224 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2225 |
if ((__INST(handleType) == nil) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2226 |
|| (__INST(handleType) == @symbol(filePointer)) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2227 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2228 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2229 |
FILE *file = __FILEVal(_handle); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2230 |
if (file != NULL) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2231 |
int fileNo = fileno(file); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2232 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2233 |
if (fileNo >= 0) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2234 |
RETURN ( __MKINT(fileNo)); |
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 |
fileClosed = true; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2237 |
} |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2238 |
} |
1 | 2239 |
} |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2240 |
%}. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2241 |
handle isNil ifTrue:[^ self errorNotOpen]. |
21742 | 2242 |
fileClosed ifTrue:[handle := nil. ^ self errorNotOpen]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2243 |
^ self fileDescriptorOfFile:handle |
21689 | 2244 |
|
21742 | 2245 |
"Modified: / 05-05-2017 / 16:27:34 / cg" |
2246 |
! |
|
2247 |
||
2248 |
fileDescriptorOfFile:aHandle |
|
5852 | 2249 |
"for migration to rel5 only: |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2250 |
return the fileDescriptor of the argument handle - |
5852 | 2251 |
notice: this one returns the underlying OSs fileDescriptor - |
2252 |
this may not be available on all platforms (i.e. non unix systems)." |
|
2253 |
||
18312 | 2254 |
%{ |
2255 |
#ifdef __SCHTEAM__ |
|
21742 | 2256 |
return context._RETURN(aHandle); |
18312 | 2257 |
#endif |
2258 |
%}. |
|
21742 | 2259 |
^ nil |
2260 |
||
2261 |
"Modified: / 05-05-2017 / 16:20:20 / cg" |
|
612 | 2262 |
! |
2263 |
||
10455 | 2264 |
fileHandle |
2265 |
"return the fileHandle of the receiver. |
|
2266 |
Under unix, this is the fileDescriptor; under windows, this is the Handle." |
|
2267 |
||
2268 |
%{ |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2269 |
OBJ _handle = __INST(handle); |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2270 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2271 |
if (_handle != nil) { |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2272 |
if ((__INST(handleType) == @symbol(fileHandle)) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2273 |
|| (__INST(handleType) == @symbol(socketHandle))) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2274 |
RETURN (_handle); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2275 |
} |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2276 |
if (__INST(handleType) == @symbol(pipeFilePointer)) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2277 |
RETURN (__MKINT(fileno(__FILEVal(_handle)))); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2278 |
} |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2279 |
if ((__INST(handleType) == nil) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2280 |
|| (__INST(handleType) == @symbol(filePointer)) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2281 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2282 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
2283 |
#ifdef __win32__ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2284 |
RETURN(__MKEXTERNALADDRESS(_get_osfhandle(fileno(__FILEVal(_handle))))); |
10455 | 2285 |
#else |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2286 |
FILE *file = __FILEVal(_handle); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2287 |
if (file != NULL) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2288 |
int fileNo = fileno(file); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2289 |
if (fileNo >= 0) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2290 |
RETURN (__MKINT(fileNo)); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2291 |
} |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2292 |
} |
10455 | 2293 |
#endif |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2294 |
} |
10455 | 2295 |
} |
2296 |
%}. |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2297 |
^ handle |
21688 | 2298 |
|
2299 |
"Modified: / 07-04-2017 / 16:34:40 / cg" |
|
10455 | 2300 |
! |
2301 |
||
612 | 2302 |
filePointer |
2303 |
"return the filePointer of the receiver - |
|
2304 |
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
|
2305 |
a FILE * - not a fileDescriptor. |
612 | 2306 |
(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
|
2307 |
You cannot do much with the returned value |
612 | 2308 |
- except passing it to a primitive, for example." |
2309 |
||
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2310 |
(handleType isNil or:[handleType == #filePointer]) ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2311 |
^ handle |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2312 |
]. |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2313 |
^ self error:'not a FILE*' |
612 | 2314 |
! |
2315 |
||
21229 | 2316 |
handle |
2317 |
^ handle |
|
2318 |
! |
|
2319 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2320 |
handleType |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2321 |
^ handleType |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2322 |
! |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2323 |
|
5323 | 2324 |
lineEndCRLF |
2325 |
eolMode := #crlf |
|
2326 |
! |
|
2327 |
||
17672 | 2328 |
lineEndLF |
2329 |
eolMode := #nl |
|
2330 |
! |
|
2331 |
||
3016 | 2332 |
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
|
2333 |
eolMode := #nl |
3016 | 2334 |
! |
2335 |
||
8069
fdf460457c96
acessing: pathName added (returns nil)
Michael Beyl <mb@exept.de>
parents:
8066
diff
changeset
|
2336 |
pathName |
8511
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2337 |
"answer the pathName of the stream. |
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2338 |
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
|
2339 |
|
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2340 |
^ '' |
8069
fdf460457c96
acessing: pathName added (returns nil)
Michael Beyl <mb@exept.de>
parents:
8066
diff
changeset
|
2341 |
! |
fdf460457c96
acessing: pathName added (returns nil)
Michael Beyl <mb@exept.de>
parents:
8066
diff
changeset
|
2342 |
|
612 | 2343 |
readonly |
2344 |
"set access mode to readonly" |
|
2345 |
||
2346 |
mode := #readonly |
|
2347 |
! |
|
2348 |
||
2349 |
readwrite |
|
2350 |
"set access mode to readwrite" |
|
2351 |
||
2352 |
mode := #readwrite |
|
2353 |
! |
|
2354 |
||
2355 |
text |
|
2356 |
"switch to text mode - default is text" |
|
2357 |
||
2358 |
binary := false |
|
2359 |
! |
|
2360 |
||
2361 |
useCRLF:aBoolean |
|
20147 | 2362 |
<resource: #obsolete> |
2920 | 2363 |
"turn on or off CRLF sending (instead of LF only) - default is off. |
2364 |
This method is provided for backward compatibility - see #eolMode: |
|
2365 |
which offers another choice." |
|
2366 |
||
2367 |
aBoolean ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2368 |
eolMode := #crlf |
2920 | 2369 |
] ifFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2370 |
eolMode := #nl |
2920 | 2371 |
]. |
1 | 2372 |
! |
2373 |
||
612 | 2374 |
writeonly |
2375 |
"set access mode to writeonly" |
|
2376 |
||
2377 |
mode := #writeonly |
|
2378 |
! ! |
|
2379 |
||
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2380 |
!ExternalStream methodsFor:'closing'! |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2381 |
|
20679 | 2382 |
abortAndClose |
2383 |
"close the stream - added for protocol compatibility with Socket and PipeStream. |
|
2384 |
see comment there" |
|
2385 |
||
2386 |
self close. |
|
2387 |
||
2388 |
"Modified: 30.8.1996 / 00:39:21 / cg" |
|
2389 |
! |
|
2390 |
||
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2391 |
close |
20106 | 2392 |
"Close the stream. |
2393 |
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
|
2394 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2395 |
self isOpen ifTrue:[ |
23879 | 2396 |
self unregisterForFinalization. |
2397 |
self isOpen ifTrue:[ |
|
2398 |
self closeFile. |
|
2399 |
dependents notNil ifTrue:[ |
|
2400 |
self changed:#close. |
|
2401 |
]. |
|
2402 |
]. |
|
16300 | 2403 |
]. |
23745 | 2404 |
|
2405 |
"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
|
2406 |
! |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2407 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2408 |
shutDown |
20679 | 2409 |
"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
|
2410 |
see comment there" |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2411 |
|
19072 | 2412 |
self close. |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2413 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2414 |
"Modified: 30.8.1996 / 00:39:21 / cg" |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2415 |
! ! |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2416 |
|
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2417 |
!ExternalStream methodsFor:'copying'! |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2418 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2419 |
copy |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2420 |
"answer a copy of myself. |
22713 | 2421 |
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
|
2422 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2423 |
|copy| |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2424 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2425 |
copy := super copy. |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2426 |
copy dupFd. |
22713 | 2427 |
self isPositionable ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2428 |
copy position:position. |
22713 | 2429 |
]. |
18779 | 2430 |
copy registerForFinalization. |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2431 |
^ copy |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2432 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2433 |
" |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2434 |
|stream1 stream2| |
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 |
stream1 := Filename newTemporary writeStream. |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2437 |
stream2 := stream1 copy. |
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 inspect. |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2440 |
stream2 inspect. |
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 |
! ! |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2443 |
|
23913 | 2444 |
!ExternalStream methodsFor:'defaults'! |
2445 |
||
2446 |
bufferSizeForBulkCopy |
|
2447 |
"return the size of buffer used when copying big files/bulk data |
|
2448 |
from one stream to another. |
|
2449 |
Due to a bug on older Windows systems, the default used |
|
2450 |
is chosen very conservatively, as the copy used to fail with big buffers. |
|
2451 |
However, modern Windows systems seem to not suffer from that bug, |
|
2452 |
and bigger buffer sizes will dramatically increase the performance of |
|
2453 |
copies to/from network drives. |
|
2454 |
Setting DefaultCopyBufferSize allows for fine tuning, |
|
2455 |
in case you run into performance problems, or network buffer failures. |
|
2456 |
When nil, a somewhat conservative compromise is used." |
|
2457 |
||
2458 |
DefaultCopyBufferSize notNil ifTrue:[^ DefaultCopyBufferSize]. |
|
2459 |
||
2460 |
(OperatingSystem isMSWINDOWSlike and:[OperatingSystem isWin7Like not]) ifTrue:[ |
|
2461 |
"/ mhmh - NT hangs, when copying bigger blocks to a network drive - why ? |
|
2462 |
^ 1 * 1024. |
|
2463 |
]. |
|
2464 |
^ 64 * 1024. |
|
2465 |
||
2466 |
"Created: / 13-03-2019 / 16:49:17 / Stefan Vogel" |
|
2467 |
"Modified: / 13-03-2019 / 23:19:43 / Stefan Vogel" |
|
2468 |
! ! |
|
2469 |
||
612 | 2470 |
!ExternalStream methodsFor:'error handling'! |
2471 |
||
2472 |
argumentMustBeCharacter |
|
14440 | 2473 |
"report an error, that the argument must be a character in 0..FF" |
2474 |
||
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2475 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2476 |
|
14440 | 2477 |
ArgumentError raiseErrorString:' - argument must be a single byte character' |
612 | 2478 |
! |
2479 |
||
2480 |
argumentMustBeInteger |
|
14440 | 2481 |
"report an error, that the argument must be an integer" |
2482 |
||
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2483 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2484 |
|
14440 | 2485 |
ArgumentError raiseErrorString:' - argument must be an integer' |
77 | 2486 |
! |
2487 |
||
612 | 2488 |
argumentMustBeString |
14440 | 2489 |
"report an error, that the argument must be a string" |
2490 |
||
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2491 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2492 |
|
14440 | 2493 |
ArgumentError raiseErrorString:' - argument must be a string' |
612 | 2494 |
! |
2495 |
||
4526
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2496 |
errorAlreadyOpen |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2497 |
"{ Pragma: +optSpace }" |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2498 |
|
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2499 |
"report an error, that the stream is already opened" |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2500 |
|
8074 | 2501 |
^ OpenError |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2502 |
raiseRequestWith:self |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2503 |
errorString:' - stream is already open' |
8511
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2504 |
|
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2505 |
" |
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2506 |
self new errorAlreadyOpen |
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2507 |
" |
4526
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2508 |
|
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2509 |
"Modified: / 8.5.1999 / 20:12:30 / cg" |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2510 |
! |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2511 |
|
612 | 2512 |
errorBinary |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2513 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2514 |
|
612 | 2515 |
"report an error, that the stream is in binary mode" |
2516 |
||
8074 | 2517 |
^ InvalidModeError |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2518 |
raiseRequestWith:self |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2519 |
errorString:(self class name , ' is in binary mode') |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2520 |
"/ in:thisContext sender |
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2521 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2522 |
"Modified: / 8.5.1999 / 20:12:43 / cg" |
612 | 2523 |
! |
2524 |
||
2525 |
errorNotBinary |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2526 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2527 |
|
612 | 2528 |
"report an error, that the stream is not in binary mode" |
2529 |
||
8074 | 2530 |
^ InvalidModeError |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2531 |
raiseRequestWith:self |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2532 |
errorString:(self class name , ' is not in binary mode') |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2533 |
"/ in:thisContext sender |
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2534 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2535 |
"Modified: / 8.5.1999 / 20:12:40 / cg" |
1 | 2536 |
! |
2537 |
||
612 | 2538 |
errorNotBuffered |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2539 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2540 |
|
612 | 2541 |
"report an error, that the stream is not in buffered mode" |
2542 |
||
8074 | 2543 |
^ StreamError |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2544 |
raiseRequestWith:self |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2545 |
errorString:(self class name , ' is unbuffered - operation not allowed') |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2546 |
"/ in:thisContext sender |
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2547 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2548 |
"Modified: / 8.5.1999 / 20:12:36 / cg" |
612 | 2549 |
! |
2550 |
||
2551 |
errorReadOnly |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2552 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2553 |
|
612 | 2554 |
"report an error, that the stream is a readOnly stream" |
2555 |
||
8511
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2556 |
^ 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
|
2557 |
|
4468 | 2558 |
"Modified: / 30.7.1999 / 17:08:19 / cg" |
612 | 2559 |
! |
2560 |
||
6255
d68343dc8288
Define #errorReporter and #reportError: (ST-80 protocol)
Stefan Vogel <sv@exept.de>
parents:
6012
diff
changeset
|
2561 |
errorReporter |
d68343dc8288
Define #errorReporter and #reportError: (ST-80 protocol)
Stefan Vogel <sv@exept.de>
parents:
6012
diff
changeset
|
2562 |
"ST-80 mimicry." |
d68343dc8288
Define #errorReporter and #reportError: (ST-80 protocol)
Stefan Vogel <sv@exept.de>
parents:
6012
diff
changeset
|
2563 |
|
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
2564 |
^ self class |
6255
d68343dc8288
Define #errorReporter and #reportError: (ST-80 protocol)
Stefan Vogel <sv@exept.de>
parents:
6012
diff
changeset
|
2565 |
! |
d68343dc8288
Define #errorReporter and #reportError: (ST-80 protocol)
Stefan Vogel <sv@exept.de>
parents:
6012
diff
changeset
|
2566 |
|
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2567 |
errorUnsupportedOperation |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2568 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2569 |
|
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2570 |
"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
|
2571 |
|
8511
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2572 |
^ 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
|
2573 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2574 |
"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
|
2575 |
! |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2576 |
|
612 | 2577 |
errorWriteOnly |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2578 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2579 |
|
612 | 2580 |
"report an error, that the stream is a writeOnly stream" |
2581 |
||
8511
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2582 |
^ 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
|
2583 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2584 |
"Modified: / 8.5.1999 / 20:12:20 / cg" |
2 | 2585 |
! |
2586 |
||
612 | 2587 |
ioError |
20259 | 2588 |
"report an error, that some I/O error occurred. |
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
2589 |
(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
|
2590 |
which is no longer available and has been mounted soft)" |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
2591 |
|
16296 | 2592 |
"{ Pragma: +optSpace }" |
2593 |
||
2594 |
self ioError:lastErrorNumber |
|
2595 |
||
2596 |
"Modified: / 8.5.1999 / 20:12:16 / cg" |
|
2597 |
! |
|
2598 |
||
2599 |
ioError:errorNumber |
|
20259 | 2600 |
"report an error, that some I/O error occurred. |
16296 | 2601 |
(for example, a device-IO-error, or reading an NFS-dir, |
2602 |
which is no longer available and has been mounted soft)" |
|
2603 |
||
2604 |
"{ Pragma: +optSpace }" |
|
2605 |
||
2606 |
^ StreamIOError newException |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2607 |
errorCode:errorNumber; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2608 |
osErrorHolder:(OperatingSystem errorHolderForNumber:errorNumber); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2609 |
parameter:self; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2610 |
raiseRequest |
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2611 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2612 |
"Modified: / 8.5.1999 / 20:12:16 / cg" |
612 | 2613 |
! |
2614 |
||
2615 |
lastErrorNumber |
|
2616 |
"return the last error" |
|
2617 |
||
2618 |
^ lastErrorNumber |
|
2619 |
! |
|
2620 |
||
2621 |
lastErrorString |
|
2622 |
"return a message string describing the last error" |
|
2623 |
||
2624 |
(lastErrorNumber isNil or:[lastErrorNumber == 0]) ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2625 |
^ 'I/O error' |
612 | 2626 |
]. |
2627 |
^ OperatingSystem errorTextForNumber:lastErrorNumber |
|
2 | 2628 |
! |
2629 |
||
10932 | 2630 |
lastErrorSymbol |
2631 |
"return an error symbol describing the last error" |
|
2632 |
||
2633 |
^ OperatingSystem errorSymbolForNumber:lastErrorNumber |
|
2634 |
! |
|
2635 |
||
612 | 2636 |
openError |
12688 | 2637 |
"report an error, that the open failed" |
2638 |
||
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2639 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2640 |
|
14438 | 2641 |
^ self openError:lastErrorNumber. |
612 | 2642 |
! |
2643 |
||
12688 | 2644 |
openError:errorNumber |
2645 |
"report an error, that the open failed" |
|
2646 |
||
2647 |
"{ Pragma: +optSpace }" |
|
2648 |
||
15496 | 2649 |
|exClass errorHolder| |
2650 |
||
2651 |
errorHolder := OperatingSystem errorHolderForNumber:errorNumber. |
|
2652 |
||
2653 |
exClass := (errorHolder errorCategory == #nonexistentSignal) |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2654 |
ifTrue:[ FileDoesNotExistException ] |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2655 |
ifFalse:[ OpenError ]. |
13673 | 2656 |
|
2657 |
^ exClass newException |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2658 |
errorCode:errorNumber; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2659 |
osErrorHolder:errorHolder; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2660 |
"/ cg: initialized lazily - see OpenError>>#description |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2661 |
"/ errorString:(' : ' , errorHolder errorString); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2662 |
parameter:self; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2663 |
raiseRequest |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2664 |
"/ in:thisContext sender |
13673 | 2665 |
|
2666 |
"Modified: / 09-09-2011 / 07:22:49 / cg" |
|
12688 | 2667 |
! |
2668 |
||
612 | 2669 |
readError |
20259 | 2670 |
"report an error, that some read error occurred" |
15845 | 2671 |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2672 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2673 |
|
15845 | 2674 |
^ self readError:lastErrorNumber |
2675 |
! |
|
2676 |
||
2677 |
readError:errorNumber |
|
20259 | 2678 |
"report an error, that some read error occurred" |
612 | 2679 |
|
15845 | 2680 |
"{ Pragma: +optSpace }" |
2681 |
||
2682 |
^ ReadError newException |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2683 |
errorCode:errorNumber; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2684 |
osErrorHolder:(OperatingSystem errorHolderForNumber:errorNumber); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2685 |
parameter:self; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2686 |
raiseRequest |
612 | 2687 |
! |
2688 |
||
2689 |
writeError |
|
20259 | 2690 |
"report an error, that some write error occurred" |
15845 | 2691 |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2692 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2693 |
|
15845 | 2694 |
^ self writeError:lastErrorNumber |
2695 |
! |
|
2696 |
||
2697 |
writeError:errorNumber |
|
20259 | 2698 |
"report an error, that some write error occurred" |
612 | 2699 |
|
15845 | 2700 |
"{ Pragma: +optSpace }" |
2701 |
||
2702 |
^ WriteError newException |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2703 |
errorCode:errorNumber; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2704 |
osErrorHolder:(OperatingSystem errorHolderForNumber:errorNumber); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2705 |
parameter:self; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2706 |
raiseRequest |
612 | 2707 |
! ! |
2708 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2709 |
!ExternalStream methodsFor:'finalization'! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2710 |
|
22694 | 2711 |
beExecutor |
2712 |
"mark myself as being an executor for finalization. |
|
2713 |
We mis-use the mode symbol for this." |
|
2714 |
||
2715 |
mode := #executor. |
|
2716 |
||
2717 |
"Created: / 23-04-2018 / 18:17:01 / stefan" |
|
2718 |
! |
|
2719 |
||
15468 | 2720 |
executor |
2721 |
"return a copy for finalization-registration; |
|
2722 |
since all we need at finalization time is the fileDescriptor, |
|
2723 |
a cheaper copy is possible." |
|
2724 |
||
22694 | 2725 |
^ self class basicNew |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2726 |
beExecutor; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2727 |
setAccessor:handleType to:handle; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2728 |
yourself. |
22694 | 2729 |
|
2730 |
"Modified: / 23-04-2018 / 18:34:38 / stefan" |
|
15468 | 2731 |
! |
2732 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2733 |
finalize |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2734 |
"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
|
2735 |
|
20679 | 2736 |
self closeFile |
18779 | 2737 |
! |
2738 |
||
2739 |
reRegisterForFinalization |
|
2740 |
Lobby registerChange:self. |
|
2741 |
! |
|
2742 |
||
2743 |
registerForFinalization |
|
2744 |
||
2745 |
"keep myself in newSpace, so it will be finalized early" |
|
18790 | 2746 |
Lobby size < MaxNonTenurableExecutors ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2747 |
ObjectMemory preventTenureOf:self. |
18790 | 2748 |
]. |
18779 | 2749 |
Lobby register:self. |
2750 |
! |
|
2751 |
||
2752 |
unregisterForFinalization |
|
2753 |
Lobby unregister:self. |
|
2754 |
"probably the object will be collected soon..." |
|
18793 | 2755 |
ObjectMemory allowTenureOf:self |
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2756 |
! ! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2757 |
|
15918
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
2758 |
!ExternalStream methodsFor:'initialization'! |
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
2759 |
|
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
2760 |
initialize |
15921 | 2761 |
position := 0. |
2762 |
binary := false. |
|
2763 |
buffered := true. |
|
19687 | 2764 |
self initializeEOLMode. |
2765 |
hitEOF := false. |
|
2766 |
! |
|
2767 |
||
2768 |
initializeEOLMode |
|
15921 | 2769 |
eolMode := DefaultEOLMode. |
15918
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
2770 |
! ! |
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
2771 |
|
2 | 2772 |
!ExternalStream methodsFor:'line reading/writing'! |
1 | 2773 |
|
2774 |
nextLine |
|
2775 |
"read the next line (characters up to newline). |
|
2776 |
Return a string containing those characters excluding the newline. |
|
2777 |
If the previous-to-last character is a cr, this is also removed, |
|
16508 | 2778 |
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
|
2779 |
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
|
2780 |
|
16296 | 2781 |
|line error| |
971
eb70f5674303
max lineLength (in nextLine) increased to 16k
Claus Gittinger <cg@exept.de>
parents:
933
diff
changeset
|
2782 |
|
12873 | 2783 |
%{ /* STACK:100000 */ |
1 | 2784 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2785 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2786 |
int len, ret; |
3029
aa14768e0e6a
larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents:
3016
diff
changeset
|
2787 |
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
|
2788 |
char *rslt, *nextPtr, *limit; |
22 | 2789 |
int fd, ch; |
1068
92fdcccf12a3
alles MIST - zurueck zu 1.89 und NOCONTEXT entfernt
Claus Gittinger <cg@exept.de>
parents:
1067
diff
changeset
|
2790 |
int _buffered; |
216 | 2791 |
OBJ fp; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
2792 |
int lineTooLong = 0; |
2920 | 2793 |
int cutOff = 0; |
1 | 2794 |
|
1133 | 2795 |
__INST(lastErrorNumber) = nil; |
12548 | 2796 |
if ((__INST(handleType) == nil) |
2797 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
2798 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2799 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 2800 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 2801 |
if (((fp = __INST(handle)) != nil) |
2802 |
&& (__INST(mode) != @symbol(writeonly)) |
|
2803 |
&& (__INST(binary) != true) |
|
2804 |
) { |
|
2805 |
f = __FILEVal(fp); |
|
2806 |
buffer[0] = '\0'; |
|
2807 |
||
2808 |
_buffered = (__INST(buffered) == true); |
|
2809 |
if (_buffered) { |
|
2810 |
__READING__(f); |
|
2811 |
} |
|
2812 |
||
2813 |
rslt = nextPtr = buffer; |
|
2814 |
limit = buffer + sizeof(buffer) - 2; |
|
2815 |
||
2816 |
for (;;) { |
|
2817 |
__READBYTE__(ret, f, nextPtr, _buffered, __INST(handleType)); |
|
2818 |
if (ret <= 0) { |
|
2819 |
if (nextPtr == buffer) |
|
2820 |
rslt = NULL; |
|
2821 |
if (ret == 0) { |
|
2822 |
__INST(hitEOF) = true; |
|
2823 |
break; |
|
2824 |
} else { |
|
23538 | 2825 |
# ifdef __win32__ |
23743 | 2826 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 2827 |
# endif |
23743 | 2828 |
error = __mkSmallInteger(__threadErrno); |
2829 |
goto err; |
|
2830 |
} |
|
2831 |
} |
|
2832 |
||
2833 |
if (*nextPtr == '\n') { |
|
2834 |
cutOff = 1; |
|
2835 |
*nextPtr = '\0'; |
|
2836 |
break; |
|
2837 |
} |
|
2838 |
if (*nextPtr == '\r') { |
|
2839 |
char peekChar; |
|
2840 |
||
2841 |
/* |
|
2842 |
* peek ahead for a newLine ... |
|
2843 |
*/ |
|
2844 |
__READBYTE__(ret, f, &peekChar, _buffered, __INST(handleType)); |
|
2845 |
if (ret <= 0) { |
|
2846 |
cutOff = 1; |
|
2847 |
*nextPtr = '\0'; |
|
2848 |
if (ret == 0) { |
|
2849 |
__INST(hitEOF) = true; |
|
2850 |
break; |
|
2851 |
} |
|
23538 | 2852 |
# ifdef __win32__ |
23743 | 2853 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 2854 |
# endif |
23743 | 2855 |
error = __mkSmallInteger(__threadErrno); |
2856 |
goto err; |
|
2857 |
} |
|
2858 |
||
2859 |
if (peekChar == '\n') { |
|
2860 |
cutOff = 2; |
|
2861 |
*nextPtr = '\0'; |
|
2862 |
break; |
|
2863 |
} |
|
2864 |
||
2865 |
__UNGETC__(peekChar, f, _buffered); |
|
2866 |
||
2867 |
cutOff = 1; |
|
2868 |
*nextPtr = '\0'; |
|
2869 |
break; |
|
2870 |
} |
|
2871 |
||
2872 |
nextPtr++; |
|
2873 |
if (nextPtr >= limit) { |
|
2874 |
*nextPtr = '\0'; |
|
2875 |
lineTooLong = 1; |
|
2876 |
break; |
|
2877 |
} |
|
2878 |
} |
|
2879 |
||
2880 |
if (rslt != NULL) { |
|
2881 |
len = nextPtr-buffer; |
|
2882 |
||
2883 |
if (__isSmallInteger(__INST(position))) { |
|
2884 |
INT np = __intVal(__INST(position)) + len + cutOff; |
|
2885 |
OBJ t; |
|
2886 |
||
2887 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
2888 |
} else { |
|
2889 |
__INST(position) = nil; /* i.e. do not know */ |
|
2890 |
} |
|
2891 |
/* remove any EOL character */ |
|
2892 |
if (len != 0) { |
|
2893 |
if (buffer[len-1] == '\n') { |
|
2894 |
buffer[--len] = '\0'; |
|
2895 |
} |
|
2896 |
if ((len != 0) && (buffer[len-1] == '\r')) { |
|
2897 |
buffer[--len] = '\0'; |
|
2898 |
} |
|
2899 |
} |
|
2900 |
line = __MKSTRING_L(buffer, len); |
|
2901 |
if (! lineTooLong) { |
|
2902 |
RETURN ( line ); |
|
2903 |
} |
|
2904 |
} |
|
2905 |
} |
|
1 | 2906 |
} |
1478
aae07192b7d1
labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
2907 |
err: ; |
159 | 2908 |
%}. |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
2909 |
line notNil ifTrue:[ |
23743 | 2910 |
"/ the line as read is longer than 32k characters (boy - what a line) |
2911 |
"/ The exception raised below can be handled to ask the user |
|
2912 |
"/ and to read more and return the concatenation from the exception handler |
|
2913 |
"/ (the receiver and the partial line are passed as parameter) |
|
2914 |
"/ If unhandled, we do exactly that: read the rest and return the concatenation |
|
2915 |
"/ i.e. the full line - whatever its size is. |
|
2916 |
||
2917 |
LineTooLongErrorSignal isHandled ifTrue:[ |
|
2918 |
^ LineTooLongErrorSignal |
|
2919 |
raiseRequestWith:(Array with:self with:line) |
|
2920 |
errorString:('line too long read error') |
|
2921 |
]. |
|
2922 |
'ExternalStream [info]: very long line in nextLine' infoPrintCR. |
|
2923 |
^ 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
|
2924 |
]. |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
2925 |
|
21139 | 2926 |
hitEOF ifTrue:[^ self pastEndRead]. |
16296 | 2927 |
error notNil ifTrue:[ |
23743 | 2928 |
lastErrorNumber := error. |
2929 |
^ self readError:error |
|
16296 | 2930 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2931 |
handle isNil ifTrue:[^ self errorNotOpen]. |
1 | 2932 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
21139 | 2933 |
binary ifTrue:[^ self errorBinary]. |
5431 | 2934 |
^ super nextLine |
23538 | 2935 |
|
2936 |
"Modified: / 22-11-2018 / 14:46:40 / Stefan Vogel" |
|
1 | 2937 |
! |
2938 |
||
2939 |
nextPutLine:aString |
|
2920 | 2940 |
"write the characters in aString and append an end-of-Line marker |
2941 |
(LF, CR or CRLF - depending in the setting of eolMode)" |
|
1 | 2942 |
|
16296 | 2943 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2944 |
%{ |
7875
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
2945 |
OBJ fp; |
1 | 2946 |
|
1133 | 2947 |
__INST(lastErrorNumber) = nil; |
12548 | 2948 |
if ((__INST(handleType) == nil) |
2949 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
2950 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2951 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 2952 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 2953 |
if (((fp = __INST(handle)) != nil) |
2954 |
&& (__INST(mode) != @symbol(readonly)) |
|
2955 |
&& (__INST(binary) != true) |
|
2956 |
&& __isStringLike(aString) |
|
2957 |
) { |
|
2958 |
int _buffered = (__INST(buffered) == true); |
|
2959 |
int len = __stringSize(aString); |
|
2960 |
int cnt, len1; |
|
2961 |
FILEPOINTER f = __FILEVal(fp); |
|
2962 |
char *cp; |
|
2963 |
int o_offs; |
|
2964 |
||
2965 |
if (_buffered) { |
|
2966 |
__WRITING__(f) |
|
2967 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
2968 |
#ifdef __win32__ |
23743 | 2969 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
2970 |
cnt = __win32_fwrite(__stringVal(aString), 1, len, f); |
|
2971 |
} else |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2972 |
#endif |
23743 | 2973 |
{ |
2974 |
o_offs = (char *)__stringVal(aString)-(char *)aString; |
|
2975 |
__WRITEBYTES_OBJ__(cnt, f, aString, o_offs, len, _buffered, __INST(handleType)); |
|
2976 |
} |
|
2977 |
if (cnt == len) { |
|
2978 |
OBJ mode = __INST(eolMode); |
|
2979 |
||
2980 |
len1 = len; |
|
2981 |
||
2982 |
if (mode == @symbol(cr)) { |
|
2983 |
cp = "\r"; len = 1; |
|
2984 |
} else if (mode == @symbol(crlf)) { |
|
2985 |
cp = "\r\n"; len = 2; |
|
2986 |
} else if (mode == @symbol(eot)) { |
|
2987 |
cp = "\004"; len = 1; |
|
2988 |
} else if (mode == @symbol(etx)) { |
|
2989 |
cp = "\003"; len = 1; |
|
2990 |
} else { |
|
2991 |
cp = "\n"; len = 1; |
|
2992 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
2993 |
#ifdef __win32__ |
23743 | 2994 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
2995 |
cnt = __win32_fwrite(cp, 1, len, f); |
|
2996 |
} else |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2997 |
#endif |
23743 | 2998 |
{ |
2999 |
__WRITEBYTES__(cnt, f, cp, len, _buffered, __INST(handleType)); |
|
3000 |
} |
|
3001 |
if (cnt > 0) { |
|
3002 |
if (__isSmallInteger(__INST(position))) { |
|
3003 |
INT np = __intVal(__INST(position)) + len1 + cnt; |
|
3004 |
OBJ t; |
|
3005 |
||
3006 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
3007 |
} else { |
|
3008 |
__INST(position) = nil; /* i.e. do not know */ |
|
3009 |
} |
|
3010 |
RETURN ( self ); |
|
3011 |
} |
|
3012 |
} |
|
23538 | 3013 |
# ifdef __win32__ |
23743 | 3014 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 3015 |
# endif |
23743 | 3016 |
error = __mkSmallInteger(__threadErrno); |
3017 |
} |
|
1 | 3018 |
} |
159 | 3019 |
%}. |
16296 | 3020 |
error notNil ifTrue:[ |
23743 | 3021 |
lastErrorNumber := error. |
3022 |
self writeError:error. |
|
3023 |
^ self |
|
16296 | 3024 |
]. |
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
3025 |
super nextPutLine:aString. |
23538 | 3026 |
|
3027 |
"Modified: / 22-11-2018 / 14:48:48 / Stefan Vogel" |
|
1 | 3028 |
! |
3029 |
||
3030 |
nextPutLinesFrom:aStream upToLineStartingWith:aStringOrNil |
|
68 | 3031 |
"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
|
3032 |
and append all lines to self. |
159 | 3033 |
Can be used to copy/create large files or copy from a pipe/socket. |
68 | 3034 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3035 |
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
|
3036 |
|
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3037 |
|line| |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3038 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3039 |
[aStream atEnd] whileFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3040 |
line := aStream nextLine. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3041 |
line isNil ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3042 |
^ self. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3043 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3044 |
self nextPutLine:line. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3045 |
(aStringOrNil notNil and:[line startsWith:aStringOrNil]) ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3046 |
^ self |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3047 |
] |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3048 |
]. |
1 | 3049 |
! |
3050 |
||
3051 |
peekForLineStartingWith:aString |
|
3052 |
"read ahead for next line starting with aString; |
|
159 | 3053 |
return the line-string if found, or nil if EOF is encountered. |
7118 | 3054 |
If matched, do not advance position beyond that line |
159 | 3055 |
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
|
3056 |
If not matched, reposition to original position for further reading." |
1 | 3057 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3058 |
|firstPos lastPos line| |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3059 |
|
1 | 3060 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3061 |
handle isNil ifTrue:[^ self errorNotOpen]. |
2 | 3062 |
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
|
3063 |
buffered ifFalse:[^ self errorNotBuffered]. |
12 | 3064 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3065 |
firstPos := self position. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3066 |
[self atEnd] whileFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3067 |
lastPos := self position. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3068 |
line := self nextLine. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3069 |
line isNil ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3070 |
self position:firstPos. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3071 |
^ nil |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3072 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3073 |
(line startsWith:aString) ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3074 |
self position:lastPos. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3075 |
^ line |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3076 |
] |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3077 |
]. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3078 |
self position:firstPos. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3079 |
^ nil |
1 | 3080 |
! |
3081 |
||
3082 |
peekForLineStartingWithAny:aCollectionOfStrings |
|
3083 |
"read ahead for next line starting with any of aCollectionOfStrings; |
|
3084 |
return the index in aCollection if found, nil otherwise.. |
|
3085 |
If no match, do not change position; otherwise advance right before the |
|
3086 |
matched line so that nextLine will return this line." |
|
3087 |
||
3088 |
|line startPos linePos index| |
|
3089 |
||
3090 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3091 |
handle isNil ifTrue:[^ self errorNotOpen]. |
2 | 3092 |
binary ifTrue:[^ self errorBinary]. |
3093 |
||
1 | 3094 |
startPos := self position. |
3095 |
[self atEnd] whileFalse:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3096 |
linePos := self position. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3097 |
line := self nextLine. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3098 |
line notNil ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3099 |
index := 1. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3100 |
aCollectionOfStrings do:[:prefix | |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3101 |
(line startsWith:prefix) ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3102 |
self position:linePos. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3103 |
^ index |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3104 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3105 |
index := index + 1 |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3106 |
] |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3107 |
] |
1 | 3108 |
]. |
3109 |
self position:startPos. |
|
3110 |
^ nil |
|
3111 |
! ! |
|
3112 |
||
612 | 3113 |
!ExternalStream methodsFor:'misc functions'! |
3114 |
||
3115 |
async:aBoolean |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3116 |
"set/clear the async attribute - if set, the availability of data on |
612 | 3117 |
the receiver will trigger an ioInterrupt. |
779 | 3118 |
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
|
3119 |
Notice: |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3120 |
not every OS supports this |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3121 |
- check with OS>>supportsIOInterrupts before using" |
92 | 3122 |
|
3123 |
|fd| |
|
3124 |
||
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3125 |
OperatingSystem supportsIOInterrupts ifFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3126 |
^ self errorUnsupportedOperation |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3127 |
]. |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3128 |
|
92 | 3129 |
fd := self fileDescriptor. |
22195 | 3130 |
"self fileDescriptor may set handle to nil" |
3131 |
handle isNil ifTrue:[^ self errorNotOpen]. |
|
3132 |
||
612 | 3133 |
aBoolean ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3134 |
^ OperatingSystem enableIOInterruptsOn:fd |
612 | 3135 |
]. |
3136 |
^ OperatingSystem disableIOInterruptsOn:fd |
|
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3137 |
|
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3138 |
"Modified: 11.1.1997 / 17:50:21 / cg" |
92 | 3139 |
! |
3140 |
||
612 | 3141 |
blocking:aBoolean |
3142 |
"set/clear the blocking attribute - if set (which is the default) |
|
3143 |
a read (using next) on the receiver will block until data is available. |
|
3144 |
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
|
3145 |
nil. |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3146 |
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
|
3147 |
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
|
3148 |
in advance. However, the data must then be read using #nextBytes: |
8616 | 3149 |
methods, in order to avoid other (pastEndRead) exceptions." |
92 | 3150 |
|
22195 | 3151 |
|fd| |
3152 |
||
3153 |
fd := self fileDescriptor. |
|
3154 |
"self fileDescriptor may set handle to nil" |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3155 |
handle isNil ifTrue:[^ self errorNotOpen]. |
22195 | 3156 |
^ OperatingSystem setBlocking:aBoolean on:fd. |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3157 |
|
3174 | 3158 |
"Modified: / 11.1.1997 / 17:48:01 / cg" |
3159 |
"Modified: / 15.1.1998 / 11:49:48 / stefan" |
|
612 | 3160 |
! |
3161 |
||
3162 |
ioctl:ioctlNumber |
|
3163 |
"to provide a simple ioctl facility - an ioctl is performed |
|
3164 |
on the underlying file; no arguments are passed." |
|
3165 |
||
2920 | 3166 |
^ self ioctl:ioctlNumber with:nil |
3167 |
! |
|
3168 |
||
3169 |
ioctl:ioctlNumber with:arg |
|
3170 |
"to provide a simple ioctl facility - an ioctl is performed |
|
3171 |
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
|
3172 |
This is not used by ST/X, but provided for special situations |
2920 | 3173 |
- for example, to control proprietrary I/O devices. |
3174 |
||
3175 |
Since the type of the argument depends on the ioctl being |
|
3176 |
performed, different arg types are allowed here. |
|
3177 |
If the argument is nil, an ioctl without argument is performed. |
|
16508 | 3178 |
If the argument is an integral number, it's directly passed; |
3179 |
if it's a kind of ByteArray (ByteArray, String or Structure), |
|
2920 | 3180 |
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
|
3181 |
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
|
3182 |
This allows performing most ioctls |
2920 | 3183 |
- however, it might be tricky to setup the buffer. |
3184 |
Be careful in what you pass - ST/X cannot validate its correctness." |
|
3185 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3186 |
|error| |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3187 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3188 |
%{ |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3189 |
#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
|
3190 |
int fd; |
10552
d52aa8e066e5
#ioctl:with: accept 32-bit integers as arguments
Stefan Vogel <sv@exept.de>
parents:
10469
diff
changeset
|
3191 |
int ret; |
d52aa8e066e5
#ioctl:with: accept 32-bit integers as arguments
Stefan Vogel <sv@exept.de>
parents:
10469
diff
changeset
|
3192 |
unsigned int ioNum; |
2920 | 3193 |
INT ioArg; |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3194 |
OBJ fp = __INST(handle); |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3195 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3196 |
if (fp == nil) |
23743 | 3197 |
goto out; |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3198 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3199 |
if (!__isInteger(ioctlNumber) |
23743 | 3200 |
|| (!__isInteger(arg) |
3201 |
&& (arg != nil) |
|
3202 |
&& !__isBytes(arg) |
|
3203 |
&& !__isExternalBytesLike(arg) |
|
3204 |
&& !__isExternalAddress(arg))) { |
|
3205 |
error = @symbol(badArgument); |
|
3206 |
goto out; |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3207 |
} |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3208 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3209 |
if (__INST(handleType) == @symbol(socketHandle)) { |
23743 | 3210 |
fd = (int)((SOCKET)(__FILEVal(fp))); |
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3211 |
} else |
23743 | 3212 |
if ((__INST(handleType) == nil) |
3213 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3214 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
3215 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
3216 |
fd = fileno(__FILEVal(fp)); |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3217 |
} else { |
23743 | 3218 |
error = @symbol(badHandleType); |
3219 |
goto out; |
|
612 | 3220 |
} |
16508 | 3221 |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3222 |
ioNum = __unsignedLongIntVal(ioctlNumber); |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3223 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3224 |
__BEGIN_INTERRUPTABLE__ |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3225 |
do { |
23743 | 3226 |
__threadErrno = 0; |
3227 |
if (arg == nil) { |
|
3228 |
ioArg = 0; |
|
3229 |
} else if (__isSmallInteger(arg)) { |
|
3230 |
ioArg = __intVal(arg); |
|
3231 |
} else if (__isInteger(arg)) { |
|
3232 |
ioArg = __unsignedLongIntVal(arg); |
|
3233 |
} else if (__isExternalBytesLike(arg)) { |
|
3234 |
ioArg = (INT)(__externalBytesAddress(arg)); |
|
3235 |
} else if (__isExternalAddress(arg)) { |
|
3236 |
ioArg = (INT)(__externalAddressVal(arg)); |
|
3237 |
} else { |
|
3238 |
ioArg = (INT)(__ByteArrayInstPtr(arg)->ba_element); |
|
3239 |
} |
|
3240 |
ret = ioctl(fd, ioNum, ioArg); |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3241 |
} while (ret < 0 && __threadErrno == EINTR); |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3242 |
__END_INTERRUPTABLE__ |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3243 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3244 |
if (ret >= 0) { |
23743 | 3245 |
RETURN ( __mkSmallInteger(ret) ); |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3246 |
} |
23538 | 3247 |
# ifdef __win32__ |
23743 | 3248 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 3249 |
# endif |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3250 |
error = __mkSmallInteger(__threadErrno); |
791 | 3251 |
#endif |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3252 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3253 |
out:; |
612 | 3254 |
%}. |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3255 |
error notNil ifTrue:[ |
23743 | 3256 |
lastErrorNumber := error. |
3257 |
^ self ioError:error. |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3258 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3259 |
handle isNil ifTrue:[^ self errorNotOpen]. |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3260 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3261 |
"/ the system does not support ioctl (MSDOS or VMS) |
2920 | 3262 |
^ self errorUnsupportedOperation |
23538 | 3263 |
|
3264 |
"Modified: / 22-11-2018 / 14:42:04 / Stefan Vogel" |
|
612 | 3265 |
! |
3266 |
||
16551 | 3267 |
reset |
3268 |
"set the read position to the beginning of the collection" |
|
3269 |
||
3270 |
self position:0 |
|
3271 |
! |
|
3272 |
||
3273 |
setToEnd |
|
3274 |
"redefined since it must be implemented differently" |
|
3275 |
||
3276 |
^ self subclassResponsibility |
|
3277 |
! |
|
3278 |
||
3279 |
sync |
|
3280 |
"make sure, that the OS writes cached data to the disk" |
|
3281 |
||
3282 |
|error| |
|
3283 |
||
3284 |
self flush. |
|
3285 |
||
3286 |
%{ |
|
3287 |
#if !defined(__openVMS__) |
|
3288 |
int fd; |
|
3289 |
int ret; |
|
3290 |
OBJ fp = __INST(handle); |
|
3291 |
||
3292 |
if (fp == nil) |
|
23743 | 3293 |
goto out; |
16551 | 3294 |
|
3295 |
if (__INST(handleType) == @symbol(socketHandle)) { |
|
23743 | 3296 |
// syncing a socket to disk ? |
3297 |
error = @symbol(badHandleType); |
|
3298 |
goto out; |
|
3299 |
// fd = __FILEVal(fp); |
|
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3300 |
} else |
23743 | 3301 |
if ((__INST(handleType) == nil) |
3302 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3303 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
3304 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
3305 |
fd = fileno(__FILEVal(fp)); |
|
16551 | 3306 |
} else { |
23743 | 3307 |
error = @symbol(badHandleType); |
3308 |
goto out; |
|
16551 | 3309 |
} |
3310 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
3311 |
#ifdef __win32__ |
16551 | 3312 |
__threadErrno = 0; |
3313 |
ret = __STX_API_NOINT_CALL1( "FlushFileBuffers", FlushFileBuffers, _get_osfhandle(fd)); |
|
3314 |
if (ret) { |
|
23743 | 3315 |
RETURN (self); |
16551 | 3316 |
} |
23538 | 3317 |
__threadErrno = __WIN32_ERR(GetLastError()); |
16551 | 3318 |
#else |
3319 |
__BEGIN_INTERRUPTABLE__ |
|
3320 |
do { |
|
23743 | 3321 |
ret = fsync(fd); |
16551 | 3322 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
3323 |
__END_INTERRUPTABLE__ |
|
3324 |
||
3325 |
if (ret >= 0) { |
|
23743 | 3326 |
RETURN (self); |
16551 | 3327 |
} |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
3328 |
#endif /* ! __win32__ */ |
16551 | 3329 |
error = __mkSmallInteger(__threadErrno); |
3330 |
#endif /* ! __openVMS__ */ |
|
3331 |
out:; |
|
3332 |
%}. |
|
3333 |
error notNil ifTrue:[ |
|
23743 | 3334 |
lastErrorNumber := error. |
3335 |
self ioError:error. |
|
3336 |
^ self. |
|
16551 | 3337 |
]. |
3338 |
handle isNil ifTrue:[self errorNotOpen]. |
|
3339 |
||
3340 |
" |
|
23743 | 3341 |
|f| |
3342 |
f := 'x' asFilename writeStream. |
|
3343 |
f nextPutAll:'hallo'; sync; syncData; close |
|
16551 | 3344 |
" |
23538 | 3345 |
|
3346 |
"Modified: / 22-11-2018 / 14:51:43 / Stefan Vogel" |
|
16551 | 3347 |
! |
3348 |
||
3349 |
syncData |
|
3350 |
"make sure, that the OS writes cached data to the disk. |
|
3351 |
In this case, metadata is only written, if it is |
|
3352 |
required to read the file's data (so metadata will not be written, |
|
3353 |
if only access/modification time has changed)." |
|
3354 |
|error| |
|
3355 |
||
3356 |
self flush. |
|
3357 |
||
3358 |
%{ |
|
3359 |
#if !defined(__openVMS__) |
|
3360 |
int fd; |
|
3361 |
int ret; |
|
3362 |
OBJ fp = __INST(handle); |
|
3363 |
||
3364 |
if (fp == nil) |
|
23743 | 3365 |
goto out; |
16551 | 3366 |
|
3367 |
if (__INST(handleType) == @symbol(socketHandle)) { |
|
23743 | 3368 |
// syncing a socket to disk ? |
3369 |
error = @symbol(badHandleType); |
|
3370 |
goto out; |
|
3371 |
// fd = __FILEVal(fp); |
|
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3372 |
} else |
23743 | 3373 |
if ((__INST(handleType) == nil) |
3374 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3375 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
3376 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
3377 |
fd = fileno(__FILEVal(fp)); |
|
16551 | 3378 |
} else { |
23743 | 3379 |
error = @symbol(badHandleType); |
3380 |
goto out; |
|
16551 | 3381 |
} |
3382 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
3383 |
#ifdef __win32__ |
16551 | 3384 |
__threadErrno = 0; |
3385 |
ret = __STX_API_NOINT_CALL1( "FlushFileBuffers", FlushFileBuffers, _get_osfhandle(fd)); |
|
3386 |
if (ret) { |
|
23743 | 3387 |
RETURN (self); |
16551 | 3388 |
} |
23538 | 3389 |
__threadErrno = __WIN32_ERR(GetLastError()); |
16551 | 3390 |
#else |
3391 |
__BEGIN_INTERRUPTABLE__ |
|
3392 |
do { |
|
23743 | 3393 |
ret = fdatasync(fd); |
16551 | 3394 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
3395 |
__END_INTERRUPTABLE__ |
|
3396 |
||
3397 |
if (ret >= 0) { |
|
23743 | 3398 |
RETURN (self); |
16551 | 3399 |
} |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
3400 |
#endif /* ! __win32__ */ |
16551 | 3401 |
error = __mkSmallInteger(__threadErrno); |
3402 |
#endif /* ! __openVMS__ */ |
|
3403 |
out:; |
|
3404 |
%}. |
|
3405 |
||
3406 |
error notNil ifTrue:[ |
|
23743 | 3407 |
lastErrorNumber := error. |
3408 |
self ioError:error. |
|
3409 |
^ self. |
|
16551 | 3410 |
]. |
3411 |
handle isNil ifTrue:[^ self errorNotOpen]. |
|
3412 |
||
3413 |
"if notdef HAS_DATASYNC, fall back" |
|
3414 |
self sync. |
|
3415 |
||
3416 |
" |
|
23743 | 3417 |
|f| |
3418 |
f := 'x' asFilename writeStream. |
|
3419 |
f nextPutAll:'hallo'; sync; syncData; close |
|
16551 | 3420 |
" |
23538 | 3421 |
|
3422 |
"Modified: / 22-11-2018 / 14:51:31 / Stefan Vogel" |
|
16551 | 3423 |
! |
3424 |
||
16508 | 3425 |
tcgetattr |
3426 |
"unix only: |
|
3427 |
provide the information of a tcgetattr call as a dictionary. |
|
3428 |
This provides terminal setting values of a tty or pty. |
|
3429 |
Used by terminal emulators. |
|
3430 |
On non-unix systems, an unsupported operation error is raised" |
|
3431 |
||
3432 |
|error ret |
|
3433 |
iflags "/ input flags |
|
3434 |
ignbrk brkint ignpar parmrk inpck istrip inlcr igncr |
|
16509
2cf139885242
Fixed ExternalStream>>tcgetattr
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16508
diff
changeset
|
3435 |
icrnl iuclc ixon ixoff ixany imaxbel iutf8 |
16508 | 3436 |
oflags "/ output flags |
3437 |
opost onlcr ocrnl olcuc onocr onlret oxtabs onoteot |
|
3438 |
cflags "/ control flags |
|
3439 |
csize cstopb cread parenb parodd hupcl clocal |
|
3440 |
lflags "/ local flags |
|
3441 |
echoke echoe echok echo echonl echoprt echoctl |
|
3442 |
isig icanon altwerase iexten extproc tostop |
|
3443 |
| |
|
3444 |
||
3445 |
%{ |
|
3446 |
#if !defined(MSDOS_LIKE) && !defined(__openVMS__) |
|
3447 |
int fd; |
|
3448 |
int _ret; |
|
3449 |
OBJ fp = __INST(handle); |
|
3450 |
struct termios t; |
|
3451 |
int sz; |
|
3452 |
||
3453 |
if (fp == nil) |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3454 |
goto out; |
16508 | 3455 |
|
3456 |
if (__INST(handleType) == @symbol(socketHandle)) { |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3457 |
// cg: termina attributes of a socket? |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3458 |
error = @symbol(badHandleType); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3459 |
goto out; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3460 |
// fd = __FILEVal(fp); |
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3461 |
} else |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3462 |
if ((__INST(handleType) == nil) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3463 |
|| (__INST(handleType) == @symbol(filePointer)) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3464 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3465 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3466 |
fd = fileno(__FILEVal(fp)); |
16508 | 3467 |
} else { |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3468 |
error = @symbol(badHandleType); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3469 |
goto out; |
16508 | 3470 |
} |
3471 |
||
3472 |
__BEGIN_INTERRUPTABLE__ |
|
3473 |
do { |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3474 |
__threadErrno = 0; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3475 |
_ret = tcgetattr(fd, &t); |
16508 | 3476 |
} while (_ret < 0 && __threadErrno == EINTR); |
3477 |
__END_INTERRUPTABLE__ |
|
3478 |
||
3479 |
if (_ret < 0) { |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3480 |
error = __mkSmallInteger(__threadErrno); |
16508 | 3481 |
} |
3482 |
ignbrk = t.c_iflag & IGNBRK ? true : false; |
|
3483 |
brkint = t.c_iflag & BRKINT ? true : false; |
|
3484 |
ignpar = t.c_iflag & IGNPAR ? true : false; |
|
3485 |
parmrk = t.c_iflag & PARMRK ? true : false; |
|
3486 |
inpck = t.c_iflag & INPCK ? true : false; |
|
3487 |
istrip = t.c_iflag & ISTRIP ? true : false; |
|
3488 |
inlcr = t.c_iflag & INLCR ? true : false; |
|
3489 |
ixon = t.c_iflag & IXON ? true : false; |
|
3490 |
ixoff = t.c_iflag & IXOFF ? true : false; |
|
3491 |
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
|
3492 |
# ifdef IMAXBEL |
16508 | 3493 |
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
|
3494 |
# endif |
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3495 |
# ifdef IUCLC |
16508 | 3496 |
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
|
3497 |
# endif |
16508 | 3498 |
|
3499 |
opost = t.c_oflag & OPOST ? true : false; |
|
3500 |
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
|
3501 |
# ifdef OXTABS |
16508 | 3502 |
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
|
3503 |
# endif |
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3504 |
# ifdef ONOTEOT |
16508 | 3505 |
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
|
3506 |
# endif |
16508 | 3507 |
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
|
3508 |
# ifdef OLCUC |
16508 | 3509 |
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
|
3510 |
# endif |
16508 | 3511 |
onocr = t.c_oflag & ONOCR ? true : false; |
3512 |
onlret = t.c_oflag & ONLRET ? true : false; |
|
3513 |
||
3514 |
sz = t.c_cflag & CSIZE; |
|
3515 |
switch (sz) { |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3516 |
case CS5: |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3517 |
csize = @symbol(cs5); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3518 |
break; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3519 |
case CS6: |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3520 |
csize = @symbol(cs6); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3521 |
break; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3522 |
case CS7: |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3523 |
csize = @symbol(cs7); |
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 CS8: |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3526 |
csize = @symbol(cs8); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3527 |
break; |
16508 | 3528 |
} |
3529 |
cstopb = t.c_cflag & CSTOPB ? true : false; |
|
3530 |
cread = t.c_cflag & CREAD ? true : false; |
|
3531 |
parenb = t.c_cflag & PARENB ? true : false; |
|
3532 |
parodd = t.c_cflag & PARODD ? true : false; |
|
3533 |
hupcl = t.c_cflag & HUPCL ? true : false; |
|
3534 |
clocal = t.c_cflag & CLOCAL ? true : false; |
|
3535 |
||
3536 |
echoke = t.c_lflag & ECHOKE ? true : false; |
|
3537 |
echoe = t.c_lflag & ECHOE ? true : false; |
|
3538 |
echo = t.c_lflag & ECHO ? true : false; |
|
3539 |
echonl = t.c_lflag & ECHONL ? true : false; |
|
3540 |
echoctl = t.c_lflag & ECHOCTL ? true : false; |
|
3541 |
isig = t.c_lflag & ISIG ? true : false; |
|
3542 |
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
|
3543 |
# ifdef ALTWERASE |
16508 | 3544 |
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
|
3545 |
# endif |
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3546 |
# ifdef IEXTEN |
16508 | 3547 |
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
|
3548 |
# endif |
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3549 |
# ifdef EXTPROC |
16508 | 3550 |
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
|
3551 |
# endif |
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3552 |
# ifdef TOSTOP |
16508 | 3553 |
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
|
3554 |
# endif |
16508 | 3555 |
|
3556 |
#else |
|
3557 |
error = @symbol(unsupportedOperation); |
|
3558 |
#endif |
|
3559 |
||
3560 |
out:; |
|
3561 |
%}. |
|
3562 |
error notNil ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3563 |
error == #unsupportedOperation ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3564 |
"/ the system does not support tcgetattr |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3565 |
^ self errorUnsupportedOperation |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3566 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3567 |
lastErrorNumber := error. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3568 |
^ self ioError:error. |
16508 | 3569 |
]. |
3570 |
handle isNil ifTrue:[^ self errorNotOpen]. |
|
3571 |
||
3572 |
"/ construct a dictionary... |
|
3573 |
ret := Dictionary new. |
|
3574 |
ret at:#iflags put:(iflags := Dictionary new). |
|
3575 |
ret at:#oflags put:(oflags := Dictionary new). |
|
3576 |
ret at:#cflags put:(cflags := Dictionary new). |
|
3577 |
ret at:#lflags put:(lflags := Dictionary new). |
|
3578 |
iflags at:#ignbrk put:ignbrk. |
|
3579 |
iflags at:#brkint put:brkint. |
|
3580 |
iflags at:#ignpar put:ignpar. |
|
3581 |
iflags at:#parmrk put:parmrk. |
|
3582 |
iflags at:#inpck put:inpck. |
|
3583 |
iflags at:#istrip put:istrip. |
|
3584 |
iflags at:#inlcr put:inlcr. |
|
3585 |
iflags at:#igncr put:igncr. |
|
3586 |
iflags at:#icrnl put:icrnl. |
|
16509
2cf139885242
Fixed ExternalStream>>tcgetattr
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16508
diff
changeset
|
3587 |
iflags at:#uiclc put:iuclc. |
16508 | 3588 |
iflags at:#ixon put:ixon. |
3589 |
iflags at:#ixoff put:ixoff. |
|
3590 |
iflags at:#ixany put:ixany. |
|
3591 |
iflags at:#imaxbel put:imaxbel. |
|
3592 |
iflags at:#iutf8 put:iutf8. |
|
3593 |
||
3594 |
oflags at:#opost put:opost. |
|
3595 |
oflags at:#onlcr put:onlcr. |
|
3596 |
oflags at:#oxtabs put:oxtabs. |
|
3597 |
oflags at:#onoteot put:onoteot. |
|
3598 |
||
3599 |
cflags at:#csize put:csize. |
|
3600 |
cflags at:#cstopb put:cstopb. |
|
3601 |
cflags at:#cread put:cread. |
|
3602 |
cflags at:#parenb put:parenb. |
|
3603 |
cflags at:#parodd put:parodd. |
|
3604 |
cflags at:#hupcl put:hupcl. |
|
3605 |
cflags at:#clocal put:clocal. |
|
3606 |
||
3607 |
lflags at:#echoke put:echoke. |
|
3608 |
lflags at:#echoe put:echoe. |
|
3609 |
lflags at:#echok put:echok. |
|
3610 |
lflags at:#echo put:echo. |
|
3611 |
lflags at:#echonl put:echonl. |
|
3612 |
lflags at:#echoprt put:echoprt. |
|
3613 |
lflags at:#echoctl put:echoctl. |
|
3614 |
lflags at:#isig put:isig. |
|
3615 |
lflags at:#icanon put:icanon. |
|
3616 |
lflags at:#altwerase put:altwerase. |
|
3617 |
lflags at:#iexten put:iexten. |
|
3618 |
lflags at:#extproc put:extproc. |
|
3619 |
lflags at:#tostop put:tostop. |
|
3620 |
^ ret |
|
612 | 3621 |
! ! |
3622 |
||
3623 |
!ExternalStream methodsFor:'non homogenous reading'! |
|
3624 |
||
17609 | 3625 |
next:count into:aCollection startingAt:start |
20092 | 3626 |
"return the next count bytes or characters from the stream." |
3627 |
||
17609 | 3628 |
|readCount| |
3629 |
||
3630 |
readCount := self nextBytes:count into:aCollection startingAt:start. |
|
3631 |
readCount = count ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3632 |
^ aCollection. |
17609 | 3633 |
]. |
3634 |
^ aCollection copyFrom:1 to:start+readCount-1. |
|
15254 | 3635 |
! |
3636 |
||
3674 | 3637 |
nextAvailable:count |
3638 |
"return the next count elements of the stream as aCollection. |
|
3639 |
If the stream reaches the end before count elements have been read, |
|
3640 |
return what is available. (i.e. a shorter collection). |
|
3641 |
The type of collection is specified in #contentsSpecies." |
|
3642 |
||
3956
51f1a9a4d63f
changes for egcs (stdio uses __new / utsname)
Claus Gittinger <cg@exept.de>
parents:
3949
diff
changeset
|
3643 |
|buffer n| |
3674 | 3644 |
|
20092 | 3645 |
buffer := self contentsSpecies uninitializedNew:count. |
3674 | 3646 |
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
|
3647 |
n == 0 ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3648 |
binary ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3649 |
^ #[] |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3650 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3651 |
^ '' |
5202
e8130049b18f
#nextAvailableBytes:into:startingAt: may NOT set EOF flag,
Claus Gittinger <cg@exept.de>
parents:
5187
diff
changeset
|
3652 |
]. |
3674 | 3653 |
|
3654 |
n ~~ count ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3655 |
^ buffer copyTo:n |
3674 | 3656 |
]. |
3657 |
^ buffer. |
|
3658 |
||
3659 |
" |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3660 |
(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
|
3661 |
(ReadStream on:#(1 2 3 4 5)) nextAvailable:10 |
3674 | 3662 |
(ReadStream on:'hello') nextAvailable:3 |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3663 |
(ReadStream on:'hello') nextAvailable:10 |
3674 | 3664 |
" |
3665 |
||
3666 |
"Modified: / 16.6.1998 / 15:52:41 / cg" |
|
3667 |
! |
|
3668 |
||
17608 | 3669 |
nextAvailable:count into:aCollection startingAt:pos |
3670 |
"return the next count elements of the stream into aCollection at position pos." |
|
3671 |
||
3672 |
^ self nextAvailableBytes:count into:aCollection startingAt:pos. |
|
3673 |
! |
|
3674 |
||
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3675 |
nextAvailableBytes:count into:anObject startingAt:start |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3676 |
"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
|
3677 |
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
|
3678 |
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
|
3679 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3680 |
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
|
3681 |
is raised if the connection is broken. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3682 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3683 |
Notice, that in contrast to other methods, |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3684 |
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
|
3685 |
Thus allowing read of partial blocks. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3686 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3687 |
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
|
3688 |
(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
|
3689 |
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
|
3690 |
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
|
3691 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3692 |
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
|
3693 |
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
|
3694 |
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
|
3695 |
|
16296 | 3696 |
|error| |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3697 |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3698 |
%{ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3699 |
FILEPOINTER f; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3700 |
int cnt, offs, ret, _buffered; |
15987 | 3701 |
int objSize, nInstBytes; |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3702 |
char *cp; |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3703 |
char *extPtr; |
7195
755c46f9b774
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
7118
diff
changeset
|
3704 |
OBJ fp; |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3705 |
int o_offs; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3706 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3707 |
__INST(lastErrorNumber) = nil; |
12548 | 3708 |
if ((__INST(handleType) == nil) |
3709 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3710 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3711 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 3712 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23897 | 3713 |
if (((fp = __INST(handle)) != nil) |
3714 |
&& (__INST(mode) != @symbol(writeonly)) |
|
3715 |
&& __bothSmallInteger(count, start) |
|
3716 |
) { |
|
3717 |
f = __FILEVal(fp); |
|
3718 |
||
3719 |
cnt = __intVal(count); |
|
3720 |
offs = __intVal(start) - 1; |
|
3721 |
||
3722 |
if (__isExternalBytesLike(anObject)) { |
|
3723 |
OBJ sz; |
|
3724 |
||
3725 |
nInstBytes = 0; |
|
3726 |
extPtr = (char *)(__externalBytesAddress(anObject)); |
|
3727 |
if (extPtr == NULL) goto bad; |
|
3728 |
sz = __externalBytesSize(anObject); |
|
3729 |
if (__isSmallInteger(sz)) { |
|
3730 |
objSize = __intVal(sz); |
|
3731 |
} else { |
|
3732 |
objSize = 0; /* unknown */ |
|
3733 |
} |
|
3734 |
} else { |
|
3735 |
OBJ oClass = __Class(anObject); |
|
3736 |
int nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
3737 |
||
3738 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
3739 |
||
3740 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
|
3741 |
case BYTEARRAY: |
|
3742 |
case WORDARRAY: |
|
3743 |
case LONGARRAY: |
|
3744 |
case SWORDARRAY: |
|
3745 |
case SLONGARRAY: |
|
3746 |
case FLOATARRAY: |
|
3747 |
break; |
|
3748 |
case DOUBLEARRAY: |
|
15987 | 3749 |
#ifdef __NEED_DOUBLE_ALIGN |
23897 | 3750 |
nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1); |
15987 | 3751 |
#endif |
23897 | 3752 |
break; |
3753 |
case LONGLONGARRAY: |
|
3754 |
case SLONGLONGARRAY: |
|
16296 | 3755 |
#ifdef __NEED_LONGLONG_ALIGN |
23897 | 3756 |
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
|
3757 |
#endif |
23897 | 3758 |
break; |
3759 |
default: |
|
3760 |
goto bad; |
|
3761 |
} |
|
3762 |
extPtr = (char *)0; |
|
3763 |
objSize = __Size(anObject) - nInstBytes; |
|
3764 |
} |
|
3765 |
||
3766 |
if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) { |
|
3767 |
_buffered = (__INST(buffered) == true); |
|
3768 |
if (_buffered) { |
|
3769 |
__READING__(f); |
|
3770 |
} |
|
3771 |
||
3772 |
if (extPtr) { |
|
3773 |
__READAVAILBYTES__(ret, f, extPtr+offs, cnt, _buffered, __INST(handleType)); |
|
3774 |
} else { |
|
3775 |
/* |
|
3776 |
* on interrupt, anObject may be moved to another location. |
|
3777 |
* So we pass (char *)__InstPtr(anObject) + nInstBytes + offs to the macro __READ_BYTES__, |
|
3778 |
* to get a new address. |
|
3779 |
*/ |
|
3780 |
offs += nInstBytes; |
|
3781 |
__READAVAILBYTES_OBJ__(ret, f, anObject, offs, cnt, _buffered, __INST(handleType)); |
|
3782 |
} |
|
3783 |
/* 0 is NOT an EOF condition here ... */ |
|
3784 |
if (ret >= 0) { |
|
3785 |
if (__isSmallInteger(__INST(position))) { |
|
3786 |
INT np = __intVal(__INST(position)) + ret; |
|
3787 |
OBJ t; |
|
3788 |
||
3789 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
3790 |
} else { |
|
3791 |
__INST(position) = nil; /* i.e. do not know */ |
|
3792 |
} |
|
3793 |
RETURN (__mkSmallInteger(ret)); |
|
3794 |
} |
|
3795 |
__INST(position) = nil; |
|
23538 | 3796 |
# ifdef __win32__ |
23897 | 3797 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 3798 |
# endif |
23897 | 3799 |
error = __mkSmallInteger(__threadErrno); |
3800 |
} |
|
3801 |
} |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3802 |
} |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3803 |
bad: ; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3804 |
%}. |
20092 | 3805 |
hitEOF ifTrue:[^ 0]. |
16296 | 3806 |
error notNil ifTrue:[ |
23897 | 3807 |
lastErrorNumber := error. |
3808 |
^ self readError:error |
|
16296 | 3809 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3810 |
handle isNil ifTrue:[^ self errorNotOpen]. |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3811 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3812 |
" |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3813 |
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
|
3814 |
" |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3815 |
^ self primitiveFailed |
23538 | 3816 |
|
23897 | 3817 |
"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
|
3818 |
! |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3819 |
|
612 | 3820 |
nextByte |
3821 |
"read the next byte and return it as an Integer; return nil on error. |
|
3822 |
This is allowed in both text and binary modes, always returning the |
|
3823 |
bytes binary value as an integer in 0..255." |
|
3824 |
||
16296 | 3825 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3826 |
%{ |
18364 | 3827 |
#ifdef __SCHTEAM__ |
3828 |
STObject handle = self.instVarAt(I_handle); |
|
3829 |
||
3830 |
if (handle != STObject.Nil) { |
|
23743 | 3831 |
STObject next; |
3832 |
||
3833 |
next = handle.nextByte(); |
|
3834 |
if (next != STObject.EOF) { |
|
3835 |
self.instVarAt_put(I_position, STObject.Nil); |
|
3836 |
return __c__._RETURN( next ); |
|
3837 |
} |
|
3838 |
self.instVarAt_put(I_hitEOF, STObject.True); |
|
18364 | 3839 |
} |
3840 |
#else |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3841 |
FILEPOINTER f; |
612 | 3842 |
unsigned char byte; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3843 |
int ret, _buffered; |
612 | 3844 |
OBJ fp; |
3845 |
||
1133 | 3846 |
__INST(lastErrorNumber) = nil; |
12548 | 3847 |
if ((__INST(handleType) == nil) |
3848 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3849 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3850 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 3851 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 3852 |
if (((fp = __INST(handle)) != nil) |
3853 |
&& (__INST(mode) != @symbol(writeonly))) { |
|
3854 |
f = __FILEVal(fp); |
|
3855 |
||
3856 |
_buffered = (__INST(buffered) == true); |
|
3857 |
if (_buffered) { |
|
3858 |
__READING__(f) |
|
3859 |
} |
|
3860 |
__READBYTE__(ret, f, &byte, _buffered, __INST(handleType)); |
|
3861 |
if (ret > 0) { |
|
3862 |
if (__isSmallInteger(__INST(position))) { |
|
3863 |
INT np = __intVal(__INST(position)) + 1; |
|
3864 |
OBJ t; |
|
3865 |
||
3866 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
3867 |
} else { |
|
3868 |
__INST(position) = nil; /* i.e. do not know */ |
|
3869 |
} |
|
3870 |
RETURN (__mkSmallInteger(byte)); |
|
3871 |
} |
|
3872 |
||
3873 |
if (ret == 0) { |
|
3874 |
__INST(hitEOF) = true; |
|
3875 |
} else /* ret < 0 */ { |
|
3876 |
__INST(position) = nil; |
|
23538 | 3877 |
# ifdef __win32__ |
23743 | 3878 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 3879 |
# endif |
23743 | 3880 |
error = __mkSmallInteger(__threadErrno); |
3881 |
} |
|
3882 |
} |
|
612 | 3883 |
} |
18364 | 3884 |
#endif /* not SCHTEAM */ |
612 | 3885 |
%}. |
8614 | 3886 |
hitEOF ifTrue:[^ self pastEndRead]. |
16296 | 3887 |
error notNil ifTrue:[ |
23743 | 3888 |
lastErrorNumber := error. |
3889 |
^ self readError:error |
|
16296 | 3890 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3891 |
handle isNil ifTrue:[^ self errorNotOpen]. |
612 | 3892 |
^ self errorWriteOnly |
23538 | 3893 |
|
3894 |
"Modified: / 22-11-2018 / 14:45:15 / Stefan Vogel" |
|
612 | 3895 |
! |
3896 |
||
3897 |
nextBytes:count into:anObject startingAt:start |
|
3898 |
"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
|
3899 |
bytes read or the number of bytes read, if EOF is encountered before. |
612 | 3900 |
If the receiver is some socket/pipe-like stream, an exception |
3901 |
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
|
3902 |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3903 |
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
|
3904 |
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
|
3905 |
to only read whats there. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3906 |
|
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3907 |
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
|
3908 |
this does NOT return nil on EOF, but the actual count. |
612 | 3909 |
Thus allowing read of partial blocks. |
3910 |
||
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3911 |
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
|
3912 |
(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
|
3913 |
or an externalBytes object (with known size). |
612 | 3914 |
If anObject is a string or byteArray and reused, this provides the |
3915 |
fastest possible physical I/O (since no new objects are allocated). |
|
3916 |
||
3917 |
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
|
3918 |
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
|
3919 |
architectures (unless you prepared the buffer with care), |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3920 |
since it does not care for byte order or float representation." |
612 | 3921 |
|
16296 | 3922 |
|error| |
612 | 3923 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3924 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3925 |
int cnt, offs, ret, _buffered; |
15987 | 3926 |
int objSize, nInstBytes; |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3927 |
char *extPtr; |
7195
755c46f9b774
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
7118
diff
changeset
|
3928 |
OBJ fp; |
612 | 3929 |
|
1133 | 3930 |
__INST(lastErrorNumber) = nil; |
12548 | 3931 |
if ((__INST(handleType) == nil) |
3932 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3933 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3934 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 3935 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 3936 |
if (((fp = __INST(handle)) != nil) |
3937 |
&& (__INST(mode) != @symbol(writeonly)) |
|
3938 |
&& __bothSmallInteger(count, start) |
|
3939 |
) { |
|
3940 |
f = __FILEVal(fp); |
|
3941 |
||
3942 |
cnt = __intVal(count); |
|
3943 |
offs = __intVal(start) - 1; |
|
3944 |
||
3945 |
if (__isExternalBytesLike(anObject)) { |
|
3946 |
OBJ sz; |
|
3947 |
||
3948 |
nInstBytes = 0; |
|
3949 |
extPtr = (char *)(__externalBytesAddress(anObject)); |
|
3950 |
if (extPtr == NULL) goto bad; |
|
3951 |
sz = __externalBytesSize(anObject); |
|
3952 |
if (__isSmallInteger(sz)) { |
|
3953 |
objSize = __intVal(sz); |
|
3954 |
} else { |
|
3955 |
objSize = 0; /* unknown */ |
|
3956 |
} |
|
3957 |
} else { |
|
3958 |
OBJ oClass = __Class(anObject); |
|
3959 |
int nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
3960 |
||
3961 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
3962 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
|
3963 |
case BYTEARRAY: |
|
3964 |
case WORDARRAY: |
|
3965 |
case LONGARRAY: |
|
3966 |
case SWORDARRAY: |
|
3967 |
case SLONGARRAY: |
|
3968 |
case FLOATARRAY: |
|
3969 |
break; |
|
3970 |
case DOUBLEARRAY: |
|
15987 | 3971 |
#ifdef __NEED_DOUBLE_ALIGN |
23743 | 3972 |
nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1); |
15987 | 3973 |
#endif |
23743 | 3974 |
break; |
3975 |
case LONGLONGARRAY: |
|
3976 |
case SLONGLONGARRAY: |
|
16296 | 3977 |
#ifdef __NEED_LONGLONG_ALIGN |
23743 | 3978 |
nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1); |
16296 | 3979 |
#endif |
23743 | 3980 |
break; |
3981 |
default: |
|
3982 |
goto bad; |
|
3983 |
} |
|
3984 |
extPtr = (char *)0; |
|
3985 |
objSize = __Size(anObject) - nInstBytes; |
|
3986 |
} |
|
3987 |
if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) { |
|
3988 |
_buffered = (__INST(buffered) == true); |
|
3989 |
if (_buffered) { |
|
3990 |
__READING__(f); |
|
3991 |
} |
|
3992 |
||
3993 |
if (extPtr) { |
|
3994 |
__READBYTES__(ret, f, extPtr+offs, cnt, _buffered, __INST(handleType)); |
|
3995 |
} else { |
|
3996 |
/* |
|
3997 |
* on interrupt, anObject may be moved to another location. |
|
3998 |
* So we pass anObject, and the offset to the __READBYTES_OBJ__ macro. |
|
3999 |
*/ |
|
4000 |
offs += nInstBytes; |
|
4001 |
__READBYTES_OBJ__(ret, f, anObject, offs, cnt, _buffered, __INST(handleType)); |
|
4002 |
} |
|
4003 |
||
4004 |
if (ret > 0) { |
|
4005 |
if (__isSmallInteger(__INST(position))) { |
|
4006 |
INT np = __intVal(__INST(position)) + ret; |
|
4007 |
OBJ t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4008 |
} else { |
|
4009 |
__INST(position) = nil; /* i.e. do not know */ |
|
4010 |
} |
|
4011 |
RETURN (__mkSmallInteger(ret)); |
|
4012 |
} |
|
4013 |
if (ret == 0) { |
|
4014 |
__INST(hitEOF) = true; |
|
4015 |
} else /* ret < 0 */ { |
|
4016 |
__INST(position) = nil; |
|
23538 | 4017 |
# ifdef __win32__ |
23743 | 4018 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4019 |
# endif |
23743 | 4020 |
error = __mkSmallInteger(__threadErrno); |
4021 |
} |
|
4022 |
} |
|
4023 |
} |
|
612 | 4024 |
} |
4025 |
bad: ; |
|
4026 |
%}. |
|
20092 | 4027 |
hitEOF ifTrue:[^ 0]. |
16296 | 4028 |
error notNil ifTrue:[ |
23743 | 4029 |
lastErrorNumber := error. |
4030 |
^ self readError:error |
|
16296 | 4031 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4032 |
handle isNil ifTrue:[^ self errorNotOpen]. |
612 | 4033 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
4034 |
" |
|
4035 |
count not integer or arg not bit-like (String, ByteArray etc) |
|
4036 |
" |
|
4037 |
^ self primitiveFailed |
|
23538 | 4038 |
|
4039 |
"Modified: / 22-11-2018 / 14:45:28 / Stefan Vogel" |
|
92 | 4040 |
! |
4041 |
||
19219 | 4042 |
nextInt16MSB:msbFlag |
4043 |
"Read two bytes and return the value as a 16-bit signed Integer. |
|
4044 |
If msbFlag is true, value is read with most-significant byte first, |
|
4045 |
otherwise least-significant byte comes first. |
|
4046 |
A nil is returned if EOF is reached (also when EOF is hit after the first byte). |
|
4047 |
Works in both binary and text modes." |
|
4048 |
||
4049 |
|error| |
|
4050 |
%{ |
|
4051 |
OBJ fp; |
|
4052 |
||
4053 |
__INST(lastErrorNumber) = nil; |
|
4054 |
if ((__INST(handleType) == nil) |
|
4055 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4056 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
4057 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
4058 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
23743 | 4059 |
if (((fp = __INST(handle)) != nil) |
4060 |
&& (__INST(mode) != @symbol(writeonly)) |
|
4061 |
) { |
|
4062 |
FILEPOINTER f; |
|
4063 |
int ret, _buffered; |
|
4064 |
short value; |
|
4065 |
union { |
|
4066 |
unsigned char buffer[2]; |
|
4067 |
short shortVal; |
|
4068 |
} u; |
|
4069 |
||
4070 |
f = __FILEVal(fp); |
|
4071 |
_buffered = (__INST(buffered) == true); |
|
4072 |
if (_buffered) { |
|
4073 |
__READING__(f) |
|
4074 |
} |
|
4075 |
__READBYTES__(ret, f, u.buffer, 2, _buffered, __INST(handleType)); |
|
4076 |
||
4077 |
if (ret == 2) { |
|
4078 |
if (__isSmallInteger(__INST(position))) { |
|
4079 |
INT np = __intVal(__INST(position)) + 2; |
|
4080 |
OBJ t; |
|
4081 |
||
4082 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4083 |
} else { |
|
4084 |
__INST(position) = nil; /* i.e. do not know */ |
|
4085 |
} |
|
4086 |
if (msbFlag == true) { |
|
19219 | 4087 |
#if defined(__MSBFIRST__) |
23743 | 4088 |
value = u.shortVal; |
19219 | 4089 |
#else |
23743 | 4090 |
value = ((u.buffer[0] & 0xFF) << 8) | (u.buffer[1] & 0xFF); |
19219 | 4091 |
#endif |
23743 | 4092 |
} else { |
19219 | 4093 |
#if defined(__LSBFIRST__) |
23743 | 4094 |
value = u.shortVal; |
19219 | 4095 |
#else |
23743 | 4096 |
value = ((u.buffer[1] & 0xFF) << 8) | (u.buffer[0] & 0xFF); |
19219 | 4097 |
#endif |
23743 | 4098 |
} |
4099 |
RETURN (__mkSmallInteger(value)); |
|
4100 |
} |
|
4101 |
||
4102 |
if (ret < 0) { |
|
4103 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 4104 |
# ifdef __win32__ |
23743 | 4105 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4106 |
# endif |
23743 | 4107 |
error = __mkSmallInteger(__threadErrno); |
4108 |
} else /* ret == 0 */ { |
|
4109 |
__INST(hitEOF) = true; |
|
4110 |
} |
|
4111 |
} |
|
19219 | 4112 |
} |
4113 |
%}. |
|
4114 |
hitEOF ifTrue:[^ self pastEndRead]. |
|
4115 |
handle isNil ifTrue:[^ self errorNotOpen]. |
|
4116 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
4117 |
lastErrorNumber := error. |
|
4118 |
^ self readError:error. |
|
23538 | 4119 |
|
4120 |
"Modified: / 22-11-2018 / 14:45:57 / Stefan Vogel" |
|
612 | 4121 |
! |
4122 |
||
19213
b990f28738b2
refactored to get rid of implizit sizeinnextPutXX:MSM:methods
Claus Gittinger <cg@exept.de>
parents:
19072
diff
changeset
|
4123 |
nextInt32MSB:msbFlag |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
4124 |
"Read four bytes and return the value as a 32-bit signed Integer, |
612 | 4125 |
which may be a LargeInteger. |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
4126 |
If msbFlag is true, value is read with most-significant byte first, |
612 | 4127 |
otherwise least-significant byte comes first. |
4128 |
A nil is returned, if EOF is hit before all 4 bytes have been read. |
|
4129 |
Works in both binary and text modes." |
|
4130 |
||
16296 | 4131 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4132 |
%{ |
612 | 4133 |
OBJ fp; |
4134 |
||
1133 | 4135 |
__INST(lastErrorNumber) = nil; |
12548 | 4136 |
if ((__INST(handleType) == nil) |
4137 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4138 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4139 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 4140 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 4141 |
if (((fp = __INST(handle)) != nil) |
4142 |
&& (__INST(mode) != @symbol(writeonly)) |
|
4143 |
) { |
|
4144 |
FILEPOINTER f; |
|
4145 |
int ret, _buffered; |
|
4146 |
int value; |
|
4147 |
union { |
|
4148 |
unsigned char buffer[4]; |
|
4149 |
int intVal; |
|
4150 |
} u; |
|
4151 |
||
4152 |
f = __FILEVal(fp); |
|
4153 |
_buffered = (__INST(buffered) == true); |
|
4154 |
if (_buffered) { |
|
4155 |
__READING__(f) |
|
4156 |
} |
|
4157 |
__READBYTES__(ret, f, u.buffer, 4, _buffered, __INST(handleType)); |
|
4158 |
||
4159 |
if (ret == 4) { |
|
4160 |
if (__isSmallInteger(__INST(position))) { |
|
4161 |
INT np = __intVal(__INST(position)) + 4; |
|
4162 |
OBJ t; |
|
4163 |
||
4164 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4165 |
} else { |
|
4166 |
__INST(position) = nil; /* i.e. do not know */ |
|
4167 |
} |
|
4168 |
if (msbFlag == true) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4169 |
#if defined(__MSBFIRST__) |
23743 | 4170 |
value = u.intVal; |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4171 |
#else |
23743 | 4172 |
value = (u.buffer[0] & 0xFF); |
4173 |
value = (value << 8) | (u.buffer[1] & 0xFF); |
|
4174 |
value = (value << 8) | (u.buffer[2] & 0xFF); |
|
4175 |
value = (value << 8) | (u.buffer[3] & 0xFF); |
|
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4176 |
#endif |
23743 | 4177 |
} else { |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4178 |
#if defined(__LSBFIRST__) |
23743 | 4179 |
value = u.intVal; |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4180 |
#else |
23743 | 4181 |
value = (u.buffer[3] & 0xFF); |
4182 |
value = (value << 8) | (u.buffer[2] & 0xFF); |
|
4183 |
value = (value << 8) | (u.buffer[1] & 0xFF); |
|
4184 |
value = (value << 8) | (u.buffer[0] & 0xFF); |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4185 |
#endif |
23743 | 4186 |
} |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4187 |
#if __POINTER_SIZE__ == 8 |
23743 | 4188 |
RETURN ( __mkSmallInteger(value)); |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4189 |
#else |
23743 | 4190 |
RETURN ( __MKINT(value) ); |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4191 |
#endif |
23743 | 4192 |
} |
4193 |
||
4194 |
if (ret < 0) { |
|
4195 |
__INST(position) = nil; |
|
23538 | 4196 |
# ifdef __win32__ |
23743 | 4197 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4198 |
# endif |
23743 | 4199 |
error = __mkSmallInteger(__threadErrno); |
4200 |
} else /* ret == 0 */ { |
|
4201 |
__INST(hitEOF) = true; |
|
4202 |
} |
|
4203 |
} |
|
612 | 4204 |
} |
4205 |
%}. |
|
8614 | 4206 |
hitEOF ifTrue:[^ self pastEndRead]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4207 |
handle isNil ifTrue:[^ self errorNotOpen]. |
612 | 4208 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
16296 | 4209 |
lastErrorNumber := error. |
4210 |
^ self readError:error. |
|
23538 | 4211 |
|
4212 |
"Modified: / 22-11-2018 / 14:46:05 / Stefan Vogel" |
|
362 | 4213 |
! |
4214 |
||
19219 | 4215 |
nextUnsignedInt16MSB:msbFlag |
4216 |
"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
|
4217 |
If msbFlag is true, value is read with most-significant byte first, |
612 | 4218 |
otherwise least-significant byte comes first. |
4219 |
A nil is returned if EOF is reached (also when EOF is hit after the first byte). |
|
4220 |
Works in both binary and text modes." |
|
4221 |
||
16296 | 4222 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4223 |
%{ |
612 | 4224 |
OBJ fp; |
4225 |
||
1133 | 4226 |
__INST(lastErrorNumber) = nil; |
12548 | 4227 |
if ((__INST(handleType) == nil) |
4228 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4229 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4230 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 4231 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 4232 |
if (((fp = __INST(handle)) != nil) |
4233 |
&& (__INST(mode) != @symbol(writeonly)) |
|
4234 |
) { |
|
4235 |
FILEPOINTER f; |
|
4236 |
int ret, _buffered; |
|
4237 |
unsigned int value; |
|
4238 |
union { |
|
4239 |
unsigned char buffer[2]; |
|
4240 |
unsigned short shortVal; |
|
4241 |
} u; |
|
4242 |
||
4243 |
f = __FILEVal(fp); |
|
4244 |
_buffered = (__INST(buffered) == true); |
|
4245 |
if (_buffered) { |
|
4246 |
__READING__(f) |
|
4247 |
} |
|
4248 |
__READBYTES__(ret, f, u.buffer, 2, _buffered, __INST(handleType)); |
|
4249 |
||
4250 |
if (ret == 2) { |
|
4251 |
if (__isSmallInteger(__INST(position))) { |
|
4252 |
INT np = __intVal(__INST(position)) + 2; |
|
4253 |
OBJ t; |
|
4254 |
||
4255 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4256 |
} else { |
|
4257 |
__INST(position) = nil; /* i.e. do not know */ |
|
4258 |
} |
|
4259 |
if (msbFlag == true) { |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4260 |
#if defined(__MSBFIRST__) |
23743 | 4261 |
value = u.shortVal; |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4262 |
#else |
23743 | 4263 |
value = (u.buffer[0] << 8) | u.buffer[1]; |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4264 |
#endif |
23743 | 4265 |
} else { |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4266 |
#if defined(__LSBFIRST__) |
23743 | 4267 |
value = u.shortVal; |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4268 |
#else |
23743 | 4269 |
value = (u.buffer[1] << 8) | u.buffer[0]; |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4270 |
#endif |
23743 | 4271 |
} |
4272 |
RETURN (__mkSmallInteger(value)); |
|
4273 |
} |
|
4274 |
||
4275 |
if (ret < 0) { |
|
4276 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 4277 |
# ifdef __win32__ |
23743 | 4278 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4279 |
# endif |
23743 | 4280 |
error = __mkSmallInteger(__threadErrno); |
4281 |
} else /* ret == 0 */ { |
|
4282 |
__INST(hitEOF) = true; |
|
4283 |
} |
|
4284 |
} |
|
612 | 4285 |
} |
4286 |
%}. |
|
8614 | 4287 |
hitEOF ifTrue:[^ self pastEndRead]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4288 |
handle isNil ifTrue:[^ self errorNotOpen]. |
612 | 4289 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
16296 | 4290 |
lastErrorNumber := error. |
4291 |
^ self readError:error. |
|
23538 | 4292 |
|
4293 |
"Modified: / 22-11-2018 / 14:49:05 / Stefan Vogel" |
|
612 | 4294 |
! |
4295 |
||
19213
b990f28738b2
refactored to get rid of implizit sizeinnextPutXX:MSM:methods
Claus Gittinger <cg@exept.de>
parents:
19072
diff
changeset
|
4296 |
nextUnsignedInt32MSB:msbFlag |
612 | 4297 |
"Read four bytes and return the value as a 32-bit unsigned Integer, which may be |
4298 |
a LargeInteger. |
|
4299 |
If msbFlag is true, value is read with most-significant byte first, otherwise |
|
4300 |
least-significant byte comes first. |
|
4301 |
A nil is returned, if endOfFile occurs before all 4 bytes have been read. |
|
4302 |
Works in both binary and text modes." |
|
4303 |
||
16296 | 4304 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4305 |
%{ |
612 | 4306 |
OBJ fp; |
4307 |
||
1133 | 4308 |
__INST(lastErrorNumber) = nil; |
12548 | 4309 |
if ((__INST(handleType) == nil) |
4310 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4311 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4312 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 4313 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 4314 |
if (((fp = __INST(handle)) != nil) |
4315 |
&& (__INST(mode) != @symbol(writeonly)) |
|
4316 |
) { |
|
4317 |
FILEPOINTER f; |
|
4318 |
int ret, _buffered; |
|
4319 |
unsigned INT value; |
|
4320 |
union { |
|
4321 |
unsigned char buffer[4]; |
|
4322 |
unsigned int intVal; |
|
4323 |
} u; |
|
4324 |
||
4325 |
f = __FILEVal(fp); |
|
4326 |
_buffered = (__INST(buffered) == true); |
|
4327 |
if (_buffered) { |
|
4328 |
__READING__(f) |
|
4329 |
} |
|
4330 |
__READBYTES__(ret, f, u.buffer, 4, _buffered, __INST(handleType)); |
|
4331 |
||
4332 |
if (ret == 4) { |
|
4333 |
if (__isSmallInteger(__INST(position))) { |
|
4334 |
INT np = __intVal(__INST(position)) + 4; |
|
4335 |
OBJ t; |
|
4336 |
||
4337 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4338 |
} else { |
|
4339 |
__INST(position) = nil; /* i.e. do not know */ |
|
4340 |
} |
|
4341 |
if (msbFlag == true) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4342 |
#if defined(__MSBFIRST__) |
23743 | 4343 |
value = u.intVal; |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4344 |
#else |
23743 | 4345 |
value = u.buffer[0]; |
4346 |
value = (value << 8) | u.buffer[1]; |
|
4347 |
value = (value << 8) | u.buffer[2]; |
|
4348 |
value = (value << 8) | u.buffer[3]; |
|
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4349 |
#endif |
23743 | 4350 |
} else { |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4351 |
#if defined(__LSBFIRST__) |
23743 | 4352 |
value = u.intVal; |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4353 |
#else |
23743 | 4354 |
value = u.buffer[3]; |
4355 |
value = (value << 8) | u.buffer[2]; |
|
4356 |
value = (value << 8) | u.buffer[1]; |
|
4357 |
value = (value << 8) | u.buffer[0]; |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4358 |
#endif |
23743 | 4359 |
} |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4360 |
#if __POINTER_SIZE__ == 8 |
23743 | 4361 |
value &= 0xFFFFFFFF; |
4362 |
RETURN (__mkSmallInteger(value)); |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4363 |
#else |
23743 | 4364 |
if (value <= _MAX_INT) { |
4365 |
RETURN (__mkSmallInteger(value)); |
|
4366 |
} |
|
4367 |
RETURN (__MKULARGEINT(value) ); |
|
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4368 |
#endif |
23743 | 4369 |
} |
4370 |
||
4371 |
if (ret < 0) { |
|
4372 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 4373 |
# ifdef __win32__ |
23743 | 4374 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4375 |
# endif |
23743 | 4376 |
error = __mkSmallInteger(__threadErrno); |
4377 |
} else /* ret == 0 */ { |
|
4378 |
__INST(hitEOF) = true; |
|
4379 |
} |
|
4380 |
} |
|
612 | 4381 |
} |
4382 |
%}. |
|
8614 | 4383 |
hitEOF ifTrue:[^ self pastEndRead]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4384 |
handle isNil ifTrue:[^ self errorNotOpen]. |
612 | 4385 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
16296 | 4386 |
lastErrorNumber := error. |
4387 |
^ self readError:error. |
|
23538 | 4388 |
|
4389 |
"Modified: / 22-11-2018 / 14:49:23 / Stefan Vogel" |
|
612 | 4390 |
! |
4391 |
||
4392 |
nextWord |
|
15452 | 4393 |
<resource: #obsolete> |
612 | 4394 |
"in text-mode: |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4395 |
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
|
4396 |
return a string containing those characters. |
612 | 4397 |
in binary-mode: |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4398 |
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
|
4399 |
unsigned Integer (for compatibility with other smalltalks)" |
612 | 4400 |
|
4401 |
binary ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4402 |
self obsoleteMethodWarning:'use #nextUnsignedInt16MSB:true'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4403 |
^ self nextUnsignedInt16MSB:true |
92 | 4404 |
]. |
14518 | 4405 |
self obsoleteMethodWarning:'use #nextAlphaNumericWord'. |
612 | 4406 |
^ self nextAlphaNumericWord |
4407 |
! ! |
|
4408 |
||
4409 |
!ExternalStream methodsFor:'non homogenous writing'! |
|
4410 |
||
4411 |
nextPutByte:aByteValue |
|
4412 |
"write a byte. |
|
4413 |
Works in both binary and text modes." |
|
4414 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4415 |
|error| |
16296 | 4416 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4417 |
%{ |
7875
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
4418 |
OBJ fp; |
612 | 4419 |
|
1133 | 4420 |
__INST(lastErrorNumber) = nil; |
12548 | 4421 |
if ((__INST(handleType) == nil) |
4422 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4423 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4424 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 4425 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 4426 |
if (((fp = __INST(handle)) != nil) |
4427 |
&& (__INST(mode) != @symbol(readonly)) |
|
4428 |
&& __isSmallInteger(aByteValue) |
|
4429 |
||
4430 |
) { |
|
4431 |
int _buffered = (__INST(buffered) == true); |
|
4432 |
FILEPOINTER f = __FILEVal(fp); |
|
4433 |
char c = __intVal(aByteValue); |
|
4434 |
int cnt; |
|
4435 |
||
4436 |
if (_buffered) { |
|
4437 |
__WRITING__(f) |
|
4438 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4439 |
#ifdef __win32__ |
23743 | 4440 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
4441 |
cnt = __win32_fwrite(&c, 1, 1, f); |
|
4442 |
} else |
|
9053
f3f3d48d6f44
fix writing to stdout/stderr for winstx non-console operation
Claus Gittinger <cg@exept.de>
parents:
9024
diff
changeset
|
4443 |
#endif |
23743 | 4444 |
{ |
4445 |
__WRITEBYTE__(cnt, f, &c, _buffered, __INST(handleType)); |
|
4446 |
} |
|
4447 |
if (cnt == 1) { |
|
4448 |
if (__isSmallInteger(__INST(position))) { |
|
4449 |
INT np = __intVal(__INST(position)) + 1; |
|
4450 |
OBJ t; |
|
4451 |
||
4452 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4453 |
} else { |
|
4454 |
__INST(position) = nil; /* i.e. do not know */ |
|
4455 |
} |
|
4456 |
RETURN (self); |
|
4457 |
} |
|
4458 |
if (cnt < 0) { |
|
4459 |
__INST(position) = nil; /* i.e. do not know */ |
|
4460 |
} |
|
23538 | 4461 |
# ifdef __win32__ |
23743 | 4462 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4463 |
# endif |
23743 | 4464 |
error = __mkSmallInteger(__threadErrno); |
4465 |
} |
|
612 | 4466 |
} |
4467 |
%}. |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4468 |
handle isNil ifTrue:[self errorNotOpen. ^ self]. |
7801
d930c353588d
writeError: care for EWOULDBLOCK in nonBlocking case.
penk
parents:
7737
diff
changeset
|
4469 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
16296 | 4470 |
lastErrorNumber := error. |
4471 |
self writeError:error. |
|
23538 | 4472 |
|
4473 |
"Modified: / 22-11-2018 / 14:47:34 / Stefan Vogel" |
|
612 | 4474 |
! |
4475 |
||
19219 | 4476 |
nextPutInt16:anIntegerOrCharacter MSB:msbFlag |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4477 |
"Write the argument, anIntegerOrCharacter as a short (two bytes). |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4478 |
If msbFlag is true, data is written most-significant byte first; |
19615 | 4479 |
otherwise least first. |
22266 | 4480 |
Notice that integers in the range 16r-8000 to +16rFFFF can be written |
19615 | 4481 |
(i.e. both signed and unsigned int32 values can be written. |
19219 | 4482 |
Works in both binary and text modes." |
4483 |
||
4484 |
|error| |
|
4485 |
%{ |
|
4486 |
int num; |
|
4487 |
union { |
|
23743 | 4488 |
char bytes[2]; |
4489 |
short shortVal; |
|
19219 | 4490 |
} u; |
4491 |
OBJ fp; |
|
4492 |
||
4493 |
__INST(lastErrorNumber) = nil; |
|
4494 |
if ((__INST(handleType) == nil) |
|
4495 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4496 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
4497 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
4498 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
23743 | 4499 |
if (((fp = __INST(handle)) != nil) |
4500 |
&& (__INST(mode) != @symbol(readonly)) |
|
4501 |
) { |
|
4502 |
FILEPOINTER f = __FILEVal(fp); |
|
4503 |
int _buffered = (__INST(buffered) == true); |
|
4504 |
int cnt; |
|
4505 |
||
4506 |
if (__isSmallInteger(anIntegerOrCharacter)) { |
|
4507 |
num = __intVal(anIntegerOrCharacter); |
|
4508 |
} else if (__isCharacter(anIntegerOrCharacter)) { |
|
4509 |
num = __smallIntegerVal(__characterVal(anIntegerOrCharacter)); |
|
4510 |
} else |
|
4511 |
goto out; |
|
4512 |
||
4513 |
if (msbFlag == true) { |
|
19219 | 4514 |
#if defined(__MSBFIRST__) |
23743 | 4515 |
u.shortVal = num; |
19219 | 4516 |
#else |
23743 | 4517 |
u.bytes[0] = (num >> 8) & 0xFF; |
4518 |
u.bytes[1] = num & 0xFF; |
|
19219 | 4519 |
#endif |
23743 | 4520 |
} else { |
19219 | 4521 |
#if defined(__LSBFIRST__) |
23743 | 4522 |
u.shortVal = num; |
19219 | 4523 |
#else |
23743 | 4524 |
u.bytes[1] = (num >> 8) & 0xFF; |
4525 |
u.bytes[0] = num & 0xFF; |
|
19219 | 4526 |
#endif |
23743 | 4527 |
} |
4528 |
||
4529 |
if (_buffered) { |
|
4530 |
__WRITING__(f) |
|
4531 |
} |
|
4532 |
__WRITEBYTES__(cnt, f, u.bytes, 2, _buffered, __INST(handleType)); |
|
4533 |
||
4534 |
if (cnt == 2) { |
|
4535 |
if (__isSmallInteger(__INST(position))) { |
|
4536 |
INT np = __intVal(__INST(position)) + 2; |
|
4537 |
OBJ t; |
|
4538 |
||
4539 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4540 |
} else { |
|
4541 |
__INST(position) = nil; /* i.e. do not know */ |
|
4542 |
} |
|
4543 |
RETURN ( self ); |
|
4544 |
} |
|
4545 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 4546 |
# ifdef __win32__ |
23743 | 4547 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4548 |
# endif |
23743 | 4549 |
error = __mkSmallInteger(__threadErrno); |
4550 |
} |
|
19219 | 4551 |
} |
4552 |
out:; |
|
4553 |
%}. |
|
4554 |
error notNil ifTrue:[ |
|
23743 | 4555 |
lastErrorNumber := error. |
4556 |
self writeError:error. |
|
4557 |
^ self |
|
19219 | 4558 |
]. |
4559 |
handle isNil ifTrue:[self errorNotOpen. ^ self]. |
|
4560 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
|
4561 |
self argumentMustBeInteger |
|
22266 | 4562 |
|
4563 |
"Modified: / 19-09-2017 / 16:32:29 / stefan" |
|
23538 | 4564 |
"Modified: / 22-11-2018 / 14:48:14 / Stefan Vogel" |
19219 | 4565 |
! |
4566 |
||
19615 | 4567 |
nextPutInt16LSB:anIntegerOrCharacter |
4568 |
"do not remove. |
|
4569 |
See #patchByteOrderOptimizedMethods" |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4570 |
|
19615 | 4571 |
self nextPutInt16:anIntegerOrCharacter MSB:false |
4572 |
! |
|
4573 |
||
4574 |
nextPutInt16MSB:anIntegerOrCharacter |
|
4575 |
"do not remove. |
|
4576 |
See #patchByteOrderOptimizedMethods" |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4577 |
|
19615 | 4578 |
self nextPutInt16:anIntegerOrCharacter MSB:true |
4579 |
! |
|
4580 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4581 |
nextPutInt16NATIVE:anIntegerOrCharacter |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4582 |
"Write the argument, anIntegerOrCharacter as a short (two bytes) in native byte order. |
23934 | 4583 |
This is the CPU-specific byte order (LSB on x86 and VAX, MSB on sparc, and possibly on ARM). |
22266 | 4584 |
Notice that integers in the range 16r-8000 to +16rFFFF can be written |
19615 | 4585 |
(i.e. both signed and unsigned int32 values can be written. |
4586 |
Works in both binary and text modes." |
|
4587 |
||
4588 |
|error| |
|
4589 |
%{ |
|
4590 |
int num; |
|
4591 |
union { |
|
23934 | 4592 |
char bytes[2]; |
4593 |
short shortVal; |
|
19615 | 4594 |
} u; |
4595 |
OBJ fp; |
|
4596 |
||
4597 |
__INST(lastErrorNumber) = nil; |
|
4598 |
if ((__INST(handleType) == nil) |
|
4599 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4600 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
4601 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
4602 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
23934 | 4603 |
if (((fp = __INST(handle)) != nil) |
4604 |
&& (__INST(mode) != @symbol(readonly)) |
|
4605 |
) { |
|
4606 |
FILEPOINTER f = __FILEVal(fp); |
|
4607 |
int _buffered = (__INST(buffered) == true); |
|
4608 |
int cnt; |
|
4609 |
||
4610 |
if (__isSmallInteger(anIntegerOrCharacter)) { |
|
4611 |
num = __intVal(anIntegerOrCharacter); |
|
4612 |
} else if (__isCharacter(anIntegerOrCharacter)) { |
|
4613 |
num = __smallIntegerVal(__characterVal(anIntegerOrCharacter)); |
|
4614 |
} else |
|
4615 |
goto out; |
|
4616 |
||
4617 |
u.shortVal = num; |
|
4618 |
||
4619 |
if (_buffered) { |
|
4620 |
__WRITING__(f) |
|
4621 |
} |
|
4622 |
__WRITEBYTES__(cnt, f, u.bytes, 2, _buffered, __INST(handleType)); |
|
4623 |
||
4624 |
if (cnt == 2) { |
|
4625 |
if (__isSmallInteger(__INST(position))) { |
|
4626 |
INT np = __intVal(__INST(position)) + 2; |
|
4627 |
OBJ t; |
|
4628 |
||
4629 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4630 |
} else { |
|
4631 |
__INST(position) = nil; /* i.e. do not know */ |
|
4632 |
} |
|
4633 |
RETURN ( self ); |
|
4634 |
} |
|
4635 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 4636 |
# ifdef __win32__ |
23934 | 4637 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4638 |
# endif |
23934 | 4639 |
error = __mkSmallInteger(__threadErrno); |
4640 |
} |
|
19615 | 4641 |
} |
4642 |
out:; |
|
4643 |
%}. |
|
4644 |
self nextPutInt16:anIntegerOrCharacter MSB:(UninterpretedBytes isBigEndian). |
|
22266 | 4645 |
|
4646 |
"Modified: / 19-09-2017 / 16:32:40 / stefan" |
|
23538 | 4647 |
"Modified: / 22-11-2018 / 14:48:23 / Stefan Vogel" |
23934 | 4648 |
"Modified: / 17-03-2019 / 14:52:06 / Claus Gittinger" |
19615 | 4649 |
! |
4650 |
||
19213
b990f28738b2
refactored to get rid of implizit sizeinnextPutXX:MSM:methods
Claus Gittinger <cg@exept.de>
parents:
19072
diff
changeset
|
4651 |
nextPutInt32:aNumber MSB:msbFlag |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4652 |
"Write the argument, aNumber as a long (four bytes). |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4653 |
If msbFlag is true, data is written most-significant byte first; |
19615 | 4654 |
otherwise least first. |
22266 | 4655 |
Notice that integers in the range 16r-80000000 to +16rFFFFFFFF can be written |
19615 | 4656 |
(i.e. both signed and unsigned int32 values can be written. |
612 | 4657 |
Works in both binary and text modes." |
4658 |
||
16296 | 4659 |
|error| |
4660 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4661 |
%{ |
612 | 4662 |
int num; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4663 |
union { |
23743 | 4664 |
char bytes[4]; |
4665 |
int intVal; |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4666 |
} u; |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4667 |
OBJ fp; |
612 | 4668 |
|
1133 | 4669 |
__INST(lastErrorNumber) = nil; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4670 |
if (__isSmallInteger(aNumber)) { |
23743 | 4671 |
num = __intVal(aNumber); |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4672 |
} else { |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4673 |
#if __POINTER_SIZE__ == 8 |
23743 | 4674 |
// always more than 4-bytes |
4675 |
goto badArg; |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4676 |
#else |
23743 | 4677 |
num = __longIntVal(aNumber); |
4678 |
if (num == 0) { |
|
4679 |
num = __signedLongIntVal(aNumber); |
|
4680 |
if (num == 0) { |
|
4681 |
/* bad arg or out-of-range integer |
|
4682 |
* (handled by the fallBack code) |
|
4683 |
*/ |
|
4684 |
goto badArg; |
|
4685 |
} |
|
4686 |
} |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4687 |
#endif |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4688 |
} |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4689 |
|
12548 | 4690 |
if ((__INST(handleType) == nil) |
4691 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4692 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4693 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 4694 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 4695 |
if (((fp = __INST(handle)) != nil) |
4696 |
&& (__INST(mode) != @symbol(readonly)) |
|
4697 |
) { |
|
4698 |
int _buffered = (__INST(buffered) == true); |
|
4699 |
FILEPOINTER f = __FILEVal(fp); |
|
4700 |
int cnt; |
|
4701 |
||
4702 |
if (msbFlag == true) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4703 |
#if defined(__MSBFIRST__) |
23743 | 4704 |
u.intVal = num; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4705 |
#else |
23743 | 4706 |
u.bytes[0] = (num >> 24) & 0xFF; |
4707 |
u.bytes[1] = (num >> 16) & 0xFF; |
|
4708 |
u.bytes[2] = (num >> 8) & 0xFF; |
|
4709 |
u.bytes[3] = num & 0xFF; |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4710 |
#endif |
23743 | 4711 |
} else { |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4712 |
#if defined(__LSBFIRST__) |
23743 | 4713 |
u.intVal = num; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4714 |
#else |
23743 | 4715 |
u.bytes[3] = (num >> 24) & 0xFF; |
4716 |
u.bytes[2] = (num >> 16) & 0xFF; |
|
4717 |
u.bytes[1] = (num >> 8) & 0xFF; |
|
4718 |
u.bytes[0] = num & 0xFF; |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4719 |
#endif |
23743 | 4720 |
} |
4721 |
||
4722 |
if (_buffered) { |
|
4723 |
__WRITING__(f) |
|
4724 |
} |
|
4725 |
__WRITEBYTES__(cnt, f, u.bytes, 4, _buffered, __INST(handleType)); |
|
4726 |
||
4727 |
if (cnt == 4) { |
|
4728 |
if (__isSmallInteger(__INST(position))) { |
|
4729 |
INT np = __intVal(__INST(position)) + 4; |
|
4730 |
OBJ t; |
|
4731 |
||
4732 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4733 |
} else { |
|
4734 |
__INST(position) = nil; /* i.e. do not know */ |
|
4735 |
} |
|
4736 |
RETURN ( self ); |
|
4737 |
} |
|
4738 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 4739 |
# ifdef __win32__ |
23743 | 4740 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4741 |
# endif |
23743 | 4742 |
error = __mkSmallInteger(__threadErrno); |
4743 |
} |
|
612 | 4744 |
} |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4745 |
badArg: ; |
612 | 4746 |
%}. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4747 |
handle isNil ifTrue:[self errorNotOpen. ^ self]. |
7801
d930c353588d
writeError: care for EWOULDBLOCK in nonBlocking case.
penk
parents:
7737
diff
changeset
|
4748 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
16296 | 4749 |
error notNil ifTrue:[ |
23743 | 4750 |
lastErrorNumber := error. |
4751 |
self writeError:error. |
|
4752 |
^ self |
|
16296 | 4753 |
]. |
612 | 4754 |
|
4755 |
aNumber isInteger ifTrue:[ |
|
23743 | 4756 |
^ super nextPutInt32:aNumber MSB:msbFlag |
92 | 4757 |
]. |
612 | 4758 |
self argumentMustBeInteger |
22266 | 4759 |
|
4760 |
"Modified: / 19-09-2017 / 16:32:50 / stefan" |
|
23538 | 4761 |
"Modified: / 22-11-2018 / 14:48:29 / Stefan Vogel" |
19615 | 4762 |
! |
4763 |
||
4764 |
nextPutInt32LSB:anIntegerOrCharacter |
|
4765 |
"do not remove. |
|
4766 |
See #patchByteOrderOptimizedMethods" |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4767 |
|
19615 | 4768 |
self nextPutInt32:anIntegerOrCharacter MSB:false |
4769 |
! |
|
4770 |
||
4771 |
nextPutInt32MSB:anIntegerOrCharacter |
|
4772 |
"do not remove. |
|
4773 |
See #patchByteOrderOptimizedMethods" |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4774 |
|
19615 | 4775 |
self nextPutInt32:anIntegerOrCharacter MSB:true |
4776 |
! |
|
4777 |
||
4778 |
nextPutInt32NATIVE:anInteger |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4779 |
"Write the argument, anInteger as a long (four bytes) in native byte order. |
23934 | 4780 |
This is the CPU-specific byte order (LSB on x86 and VAX, MSB on sparc and possibly on ARM). |
22266 | 4781 |
Notice that integers in the range 16r-80000000 to +16rFFFFFFFF can be written |
19615 | 4782 |
(i.e. both signed and unsigned int32 values can be written. |
4783 |
Works in both binary and text modes. |
|
4784 |
Notice: this message should not be sent explicitly by ANY program. |
|
23934 | 4785 |
the following implementation replaces the code of either nextPutInt32MSB or LSB |
4786 |
dynamically (see #initialize on the class side)" |
|
19615 | 4787 |
|
4788 |
|error| |
|
4789 |
||
4790 |
%{ |
|
4791 |
int num; |
|
4792 |
union { |
|
23934 | 4793 |
char bytes[4]; |
4794 |
int intVal; |
|
19615 | 4795 |
} u; |
4796 |
OBJ fp; |
|
4797 |
||
4798 |
__INST(lastErrorNumber) = nil; |
|
4799 |
if (__isSmallInteger(anInteger)) { |
|
23934 | 4800 |
num = __intVal(anInteger); |
19615 | 4801 |
} else { |
4802 |
#if __POINTER_SIZE__ == 8 |
|
23934 | 4803 |
// always more than 4-bytes |
4804 |
goto badArg; |
|
19615 | 4805 |
#else |
23934 | 4806 |
num = __longIntVal(anInteger); |
4807 |
if (num == 0) { |
|
4808 |
num = __signedLongIntVal(anInteger); |
|
4809 |
if (num == 0) { |
|
4810 |
/* bad arg or out-of-range integer |
|
4811 |
* (handled by the fallBack code) |
|
4812 |
*/ |
|
4813 |
goto badArg; |
|
4814 |
} |
|
4815 |
} |
|
19615 | 4816 |
#endif |
4817 |
} |
|
4818 |
||
4819 |
if ((__INST(handleType) == nil) |
|
4820 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4821 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
4822 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
4823 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
23934 | 4824 |
if (((fp = __INST(handle)) != nil) |
4825 |
&& (__INST(mode) != @symbol(readonly)) |
|
4826 |
) { |
|
4827 |
int _buffered = (__INST(buffered) == true); |
|
4828 |
FILEPOINTER f = __FILEVal(fp); |
|
4829 |
int cnt; |
|
4830 |
||
4831 |
u.intVal = num; |
|
4832 |
if (_buffered) { |
|
4833 |
__WRITING__(f) |
|
4834 |
} |
|
4835 |
__WRITEBYTES__(cnt, f, u.bytes, 4, _buffered, __INST(handleType)); |
|
4836 |
||
4837 |
if (cnt == 4) { |
|
4838 |
if (__isSmallInteger(__INST(position))) { |
|
4839 |
INT np = __intVal(__INST(position)) + 4; |
|
4840 |
OBJ t; |
|
4841 |
||
4842 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4843 |
} else { |
|
4844 |
__INST(position) = nil; /* i.e. do not know */ |
|
4845 |
} |
|
4846 |
RETURN ( self ); |
|
4847 |
} |
|
4848 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 4849 |
# ifdef __win32__ |
23934 | 4850 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4851 |
# endif |
23934 | 4852 |
error = __mkSmallInteger(__threadErrno); |
4853 |
} |
|
19615 | 4854 |
} |
4855 |
badArg: ; |
|
4856 |
%}. |
|
4857 |
self nextPutInt32:anInteger MSB:(UninterpretedBytes isBigEndian) |
|
22266 | 4858 |
|
4859 |
"Modified: / 19-09-2017 / 16:32:59 / stefan" |
|
23538 | 4860 |
"Modified: / 22-11-2018 / 14:48:41 / Stefan Vogel" |
23934 | 4861 |
"Modified: / 17-03-2019 / 14:52:23 / Claus Gittinger" |
20092 | 4862 |
! |
4863 |
||
4864 |
nextPutUtf16:aCharacter |
|
4865 |
"append my UTF-16 MSB representation to the argument, aStream. |
|
4866 |
UTF-16 can encode only characters with code points between 0 to 16r10FFFF." |
|
4867 |
||
4868 |
self nextPutUtf16Bytes:aCharacter MSB:true |
|
4869 |
||
4870 |
" |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4871 |
(FileStream newTemporary |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4872 |
nextPutUtf16:$B; |
23934 | 4873 |
nextPutUtf16:$Ä; |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4874 |
nextPutUtf16:(Character codePoint:16r10CCCC); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4875 |
reset; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4876 |
binary; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4877 |
contents) |
20092 | 4878 |
" |
4879 |
! |
|
4880 |
||
4881 |
nextPutUtf16:aCharacter MSB:msbFlag |
|
4882 |
"append my UTF-16 MSB representation to the argument, aStream. |
|
4883 |
UTF-16 can encode only characters with code points between 0 to 16r10FFFF." |
|
4884 |
||
4885 |
self nextPutUtf16Bytes:aCharacter MSB:msbFlag |
|
10 | 4886 |
! ! |
612 | 4887 |
|
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4888 |
!ExternalStream methodsFor:'positioning'! |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4889 |
|
15619 | 4890 |
position |
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4891 |
self subclassResponsibility |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4892 |
! |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4893 |
|
15619 | 4894 |
position:index0Based |
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4895 |
self subclassResponsibility |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4896 |
! ! |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4897 |
|
12631 | 4898 |
!ExternalStream methodsFor:'printing & storing'! |
4899 |
||
4900 |
printOn:aStream |
|
14068 | 4901 |
aStream |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4902 |
nextPutAll:self className; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4903 |
nextPut:$(. |
22245 | 4904 |
handleType printOn:aStream. |
4905 |
aStream nextPutAll:':('. |
|
12631 | 4906 |
handle printOn:aStream. |
4907 |
aStream nextPutAll:'))' |
|
4908 |
! ! |
|
4909 |
||
612 | 4910 |
!ExternalStream methodsFor:'private'! |
4911 |
||
4912 |
clearEOF |
|
4913 |
hitEOF := false |
|
20987 | 4914 |
! |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4915 |
|
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4916 |
closeFile |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4917 |
"low level close - may be redefined in subclasses |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4918 |
Don't send this message, send #close instead" |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4919 |
|
12674 | 4920 |
|fp error| |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4921 |
|
20679 | 4922 |
handle isNil ifTrue:[ |
23743 | 4923 |
^ self. |
20679 | 4924 |
]. |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4925 |
fp := handle. |
19767 | 4926 |
"/ (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
|
4927 |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4928 |
%{ |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4929 |
int rslt; |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4930 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4931 |
if (__INST(handleType) == @symbol(socketHandle)) { |
23743 | 4932 |
SOCKET sock = (SOCKET)(__FILEVal(fp)); |
4933 |
||
23879 | 4934 |
// whether the close() will be successful or not - the handle is invalid now! |
4935 |
__INST(handle) = nil; |
|
4936 |
||
23743 | 4937 |
if (@global(FileOpenTrace) == true) { |
4938 |
fprintf(stderr, "close socket [ExternalStream] %"_lx_"\n", (INT)sock); |
|
4939 |
} |
|
4940 |
||
4941 |
do { |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4942 |
#ifdef __win32__ |
23743 | 4943 |
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
|
4944 |
#else |
23743 | 4945 |
__threadErrno = 0; |
4946 |
__BEGIN_INTERRUPTABLE__ |
|
4947 |
rslt = close(sock); |
|
4948 |
__END_INTERRUPTABLE__ |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4949 |
#endif |
23743 | 4950 |
} while((rslt < 0) && (__threadErrno == EINTR)); |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4951 |
} else if ((__INST(handleType) == nil) |
23743 | 4952 |
|| (__INST(handleType) == @symbol(filePointer)) |
4953 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
4954 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4955 |
{ |
23743 | 4956 |
FILEPOINTER f = __FILEVal(fp); |
4957 |
||
23879 | 4958 |
// whether the close() will be successful or not - the handle is invalid now! |
4959 |
__INST(handle) = nil; |
|
4960 |
||
23743 | 4961 |
if (@global(FileOpenTrace) == true) { |
4962 |
fprintf(stderr, "fclose [ExternalStream] %"_lx_"\n", (INT)f); |
|
4963 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4964 |
|
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4965 |
#ifdef __win32__ |
23743 | 4966 |
if (__INST(mode) != @symbol(readonly) && __INST(buffered) != false) { |
4967 |
// do a fflush() first, so that fclose() doesn't block |
|
4968 |
// we suspect, that EINTR causes problems in fclose() |
|
4969 |
do { |
|
4970 |
__threadErrno = 0; |
|
4971 |
rslt = __STX_C_CALL1("fflush", fflush, f); |
|
4972 |
} while((rslt < 0) && (__threadErrno == EINTR)); |
|
4973 |
if (rslt < 0) |
|
4974 |
goto err; |
|
4975 |
} |
|
4976 |
do { |
|
4977 |
__threadErrno = 0; |
|
4978 |
rslt = __STX_C_NOINT_CALL1("fclose", fclose, f); |
|
4979 |
} while((rslt < 0) && (__threadErrno == EINTR)); |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4980 |
#else |
23743 | 4981 |
// cg: not sure why, but on osx, I get blocked occasionally in fclose |
4982 |
// lets try this: |
|
4983 |
if ((__INST(mode) != @symbol(readonly)) && (__INST(buffered) != false)) { |
|
4984 |
// do a fflush() first, so that fclose() doesn't block |
|
4985 |
// we suspect, that EINTR causes problems in fclose() |
|
4986 |
do { |
|
4987 |
clearerr(f); |
|
4988 |
__threadErrno = 0; |
|
4989 |
__BEGIN_INTERRUPTABLE__ |
|
4990 |
rslt = fflush(f); |
|
4991 |
__END_INTERRUPTABLE__ |
|
4992 |
} while((rslt < 0) && (__threadErrno == EINTR)); |
|
4993 |
if (rslt < 0) |
|
4994 |
goto err; |
|
4995 |
} |
|
4996 |
do { |
|
4997 |
clearerr(f); |
|
4998 |
__threadErrno = 0; |
|
4999 |
__BEGIN_INTERRUPTABLE__ |
|
5000 |
rslt = fclose(f); |
|
5001 |
__END_INTERRUPTABLE__ |
|
5002 |
} while((rslt < 0) && (__threadErrno == EINTR)); |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5003 |
#endif |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5004 |
} else { |
23743 | 5005 |
error = @symbol(badHandleType); |
5006 |
goto out; |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5007 |
} |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5008 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5009 |
if (rslt < 0) { |
23538 | 5010 |
err: |
5011 |
# ifdef __win32__ |
|
23743 | 5012 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5013 |
# endif |
23743 | 5014 |
error = __mkSmallInteger(__threadErrno); |
5015 |
goto out; |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5016 |
} |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5017 |
RETURN (self); |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5018 |
|
12674 | 5019 |
out:; |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5020 |
%}. |
12674 | 5021 |
|
5022 |
error notNil ifTrue:[ |
|
23743 | 5023 |
error isInteger ifTrue:[ |
5024 |
lastErrorNumber := error. |
|
5025 |
mode == #readonly ifTrue:[ |
|
5026 |
self ioError:error. |
|
5027 |
] ifFalse:[ |
|
5028 |
self writeError:error. |
|
5029 |
]. |
|
5030 |
^ self. |
|
5031 |
]. |
|
5032 |
self primitiveFailed:error. |
|
5033 |
^ self. |
|
12674 | 5034 |
]. |
5035 |
||
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5036 |
"/ fallback for rel5 |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5037 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5038 |
fp := handle. |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5039 |
fp notNil ifTrue:[ |
23743 | 5040 |
handle := nil. |
5041 |
self closeFile:fp |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5042 |
] |
22681 | 5043 |
|
5044 |
"Modified: / 19-04-2018 / 10:57:54 / stefan" |
|
23538 | 5045 |
"Modified: / 22-11-2018 / 12:18:22 / Stefan Vogel" |
23737 | 5046 |
"Modified: / 14-02-2019 / 15:42:44 / Claus Gittinger" |
20987 | 5047 |
! |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5048 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5049 |
closeFile:handle |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5050 |
"for rel5 only" |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5051 |
|
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5052 |
self primitiveFailed |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5053 |
! |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5054 |
|
12706 | 5055 |
connectTo:aFileDescriptor withMode:modeSymbol handleType:handleTypeSymbol |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5056 |
"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
|
5057 |
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
|
5058 |
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
|
5059 |
a Stream object. |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5060 |
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
|
5061 |
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
|
5062 |
|
21224 | 5063 |
|error openmode| |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5064 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5065 |
handle notNil ifTrue:[^ self errorAlreadyOpen]. |
12706 | 5066 |
mode := modeSymbol. |
5067 |
openmode := self fopenMode. |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5068 |
%{ |
12683 | 5069 |
FILEPOINTER f = 0; |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5070 |
OBJ fp; |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5071 |
FILE *fdopen(); |
12683 | 5072 |
int fd = -2; |
5073 |
||
5074 |
if (__isStringLike(openmode)) { |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5075 |
#ifdef __win32__ |
23743 | 5076 |
__stxWrapApiEnterCritical(); |
12688 | 5077 |
#endif |
23743 | 5078 |
if (__isSmallInteger(aFileDescriptor)) { |
5079 |
fd = __intVal(aFileDescriptor); |
|
5080 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5081 |
#ifdef __win32__ |
23743 | 5082 |
else if (__isExternalAddressLike(aFileDescriptor)) { |
5083 |
fd = _open_osfhandle((long)__externalAddressVal(aFileDescriptor), O_BINARY); |
|
5084 |
if (fd < 0) { |
|
5085 |
if (__threadErrno == 0) { |
|
5086 |
// no more file descriptors |
|
5087 |
__threadErrno = EMFILE; |
|
5088 |
} |
|
5089 |
error = __mkSmallInteger(__WIN32_ERR(GetLastError())); |
|
5090 |
__stxWrapApiLeaveCritical(); |
|
5091 |
goto out; |
|
5092 |
} |
|
5093 |
} |
|
12683 | 5094 |
#endif |
23743 | 5095 |
f = (FILEPOINTER) fdopen(fd, (char *)__stringVal(openmode)); |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5096 |
#ifdef __win32__ |
23743 | 5097 |
__stxWrapApiLeaveCritical(); |
12688 | 5098 |
#endif |
23743 | 5099 |
if (f == NULL) { |
23538 | 5100 |
# ifdef __win32__ |
23743 | 5101 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5102 |
# endif |
23743 | 5103 |
error =__mkSmallInteger(__threadErrno); |
5104 |
} else { |
|
5105 |
if (@global(FileOpenTrace) == true) { |
|
5106 |
fprintf(stderr, "fdopen [ExternalStream] %"_ld_" (%"_lx_") -> %"_lx_"\n", (INT)fd, (INT)fd, (INT)f); |
|
5107 |
} |
|
5108 |
||
5109 |
fp = __MKFILEPOINTER(f); __INST(handle) = fp; __STORE(self, fp); |
|
5110 |
} |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5111 |
} |
12688 | 5112 |
out:; |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5113 |
%}. |
21224 | 5114 |
error notNil ifTrue:[ |
23743 | 5115 |
" |
5116 |
the open failed for some reason ... |
|
5117 |
" |
|
5118 |
OperatingSystem closeFd:aFileDescriptor. |
|
5119 |
lastErrorNumber := error. |
|
5120 |
position := nil. |
|
5121 |
^ self openError:error |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5122 |
]. |
21224 | 5123 |
|
5124 |
position := 0. |
|
5125 |
buffered isNil ifTrue:[ |
|
23743 | 5126 |
buffered := true. "default is buffered" |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5127 |
]. |
21224 | 5128 |
handleType := handleTypeSymbol. |
5129 |
self registerForFinalization. |
|
23538 | 5130 |
|
5131 |
"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
|
5132 |
! |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5133 |
|
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5134 |
dupFd |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5135 |
"duplicate my file descriptor" |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5136 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5137 |
|fd dupFd| |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5138 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5139 |
fd := self fileHandle. |
22578 | 5140 |
fd isNil ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5141 |
^ self errorNotOpen. |
20690 | 5142 |
]. |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5143 |
dupFd := OperatingSystem dup:fd. |
10989 | 5144 |
self setFileHandle:dupFd mode:self fopenMode. |
10995 | 5145 |
! |
10989 | 5146 |
|
5147 |
fopenMode |
|
5148 |
"answer the mode for fopen. |
|
5149 |
Only used internally" |
|
5150 |
||
5151 |
mode == #readonly ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5152 |
^ ReadMode |
10989 | 5153 |
]. |
5154 |
mode == #writeonly ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5155 |
^ WriteMode |
10989 | 5156 |
]. |
5157 |
mode == #readWrite ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5158 |
^ ReadWriteMode |
10989 | 5159 |
]. |
5160 |
mode == #append ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5161 |
^ AppendMode |
10989 | 5162 |
]. |
5163 |
^ ReadWriteMode |
|
10995 | 5164 |
! |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5165 |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5166 |
open:aPath withMode:openModeString |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5167 |
"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
|
5168 |
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
|
5169 |
|
16296 | 5170 |
|ok error| |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5171 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5172 |
ok := false. |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5173 |
%{ |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5174 |
FILE *f; |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5175 |
OBJ fp; |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5176 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5177 |
if (__isStringLike(aPath) && __isStringLike(openModeString)) { |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5178 |
#ifdef __win32__ |
10339 | 5179 |
# if 1 |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5180 |
f = fopen((char *) __stringVal(aPath), (char *) __stringVal(openModeString)); |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5181 |
# else |
23743 | 5182 |
__BEGIN_INTERRUPTABLE__ |
5183 |
do { |
|
5184 |
f = fopen((char *) __stringVal(aPath), (char *) __stringVal(openModeString)); |
|
5185 |
} while ((f == NULL) && (__threadErrno == EINTR)); |
|
5186 |
__END_INTERRUPTABLE__ |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5187 |
# endif |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5188 |
#else /* UNIX */ |
23743 | 5189 |
__BEGIN_INTERRUPTABLE__ |
5190 |
do { |
|
5191 |
f = fopen((char *) __stringVal(aPath), (char *) __stringVal(openModeString)); |
|
5192 |
} while ((f == NULL) && (__threadErrno == EINTR)); |
|
5193 |
__END_INTERRUPTABLE__ |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5194 |
#endif /* UNIX */ |
23743 | 5195 |
if (f == NULL) { |
23538 | 5196 |
# ifdef __win32__ |
23743 | 5197 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5198 |
# endif |
23743 | 5199 |
error = __mkSmallInteger(__threadErrno); |
5200 |
} else { |
|
5201 |
if (@global(FileOpenTrace) == true) { |
|
5202 |
fprintf(stderr, "fopen %s [ExternalStream] -> %"_lx_"\n", __stringVal(aPath), (INT)f); |
|
5203 |
} |
|
5204 |
fp = __MKFILEPOINTER(f); __INST(handle) = fp; __STORE(self, fp); |
|
5205 |
__INST(handleType) = @symbol(filePointer); |
|
5206 |
ok = true; |
|
5207 |
} |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5208 |
} |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5209 |
%}. |
16296 | 5210 |
ok ifTrue:[ |
23743 | 5211 |
position := 0. |
5212 |
self registerForFinalization. |
|
5213 |
^ self. |
|
16296 | 5214 |
]. |
5215 |
error notNil ifTrue:[ |
|
23743 | 5216 |
" |
5217 |
the open failed for some reason ... |
|
5218 |
" |
|
5219 |
lastErrorNumber := error. |
|
5220 |
self openError:error. |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5221 |
]. |
16296 | 5222 |
self primitiveFailed. |
23538 | 5223 |
|
5224 |
"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
|
5225 |
! |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5226 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5227 |
reOpen |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5228 |
"USERS WILL NEVER INVOKE THIS METHOD |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5229 |
sent after snapin to reopen streams. |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5230 |
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
|
5231 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5232 |
self class name errorPrint. ' [warning]: automatic reOpen not supported - stream closed' errorPrintCR. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5233 |
handle := nil. |
18779 | 5234 |
self unregisterForFinalization. |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5235 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5236 |
"Modified: 10.1.1997 / 17:50:44 / cg" |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5237 |
! |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5238 |
|
12398 | 5239 |
setAccessor:what to:something |
5240 |
"set the filePointer/fileHandle to the given one; |
|
5241 |
low level private & friend interface; may also be used to connect to some |
|
5242 |
externally provided handle." |
|
5243 |
||
5244 |
handle := something. |
|
5245 |
handleType := what. |
|
5246 |
! |
|
5247 |
||
5248 |
setFileHandle:something |
|
5249 |
"set the fileHandle to the given one; |
|
5250 |
low level private & friend interface; may also be used to connect to some |
|
5251 |
externally provided file handle." |
|
5252 |
||
5253 |
self setAccessor:#fileHandle to:something |
|
5254 |
! |
|
5255 |
||
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5256 |
setFileHandle:anIntegerOrExternalAddress mode:openMode |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5257 |
"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
|
5258 |
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
|
5259 |
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
|
5260 |
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
|
5261 |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5262 |
%{ |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5263 |
FILEPOINTER f; |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5264 |
OBJ fp; |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5265 |
FILE *fdopen(); |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5266 |
int fd; |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5267 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5268 |
if (!__isStringLike(openMode)) |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5269 |
goto err; |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5270 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5271 |
#ifdef __win32__ |
12688 | 5272 |
__stxWrapApiEnterCritical(); |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5273 |
if (__isExternalAddressLike(anIntegerOrExternalAddress) ) { |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5274 |
HANDLE __fileHandle = (HANDLE)__externalAddressVal(anIntegerOrExternalAddress); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5275 |
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
|
5276 |
if (fd < 0) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5277 |
__stxWrapApiLeaveCritical(); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5278 |
CloseHandle(__fileHandle); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5279 |
goto err; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5280 |
} |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5281 |
} else |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5282 |
#endif |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5283 |
if (__isSmallInteger(anIntegerOrExternalAddress)) { |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5284 |
fd = __smallIntegerVal(anIntegerOrExternalAddress); |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5285 |
} else { |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5286 |
#ifdef __win32__ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5287 |
__stxWrapApiLeaveCritical(); |
12688 | 5288 |
#endif |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5289 |
goto err; |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5290 |
} |
10997 | 5291 |
f = fdopen(fd, __stringVal(openMode)); |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5292 |
#ifdef __win32__ |
12688 | 5293 |
__stxWrapApiLeaveCritical(); |
5294 |
#endif |
|
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5295 |
if (f != NULL) { |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5296 |
if (@global(FileOpenTrace) == true) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5297 |
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
|
5298 |
} |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5299 |
fp = __MKFILEPOINTER(f); __INST(handle) = fp; __STORE(self, fp); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5300 |
__INST(handleType) = @symbol(filePointer); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5301 |
RETURN (self); |
10982
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 |
err:; |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5304 |
%}. |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5305 |
^ self primitiveFailed |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5306 |
! |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5307 |
|
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5308 |
setFilePointer:something |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5309 |
"set the filePointer to the given one; |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5310 |
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
|
5311 |
externally provided file." |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5312 |
|
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5313 |
self setAccessor:#filePointer to:something |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5314 |
! |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5315 |
|
12398 | 5316 |
setLastError:aNumber |
5317 |
lastErrorNumber := aNumber |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5318 |
! |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5319 |
|
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5320 |
setSocketHandle:something |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5321 |
"set the socketHandle to the given one; |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5322 |
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
|
5323 |
externally provided socket handle." |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5324 |
|
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5325 |
self setAccessor:#socketHandle to:something |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5326 |
! ! |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5327 |
|
612 | 5328 |
!ExternalStream methodsFor:'queries'! |
5329 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5330 |
nextError |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5331 |
"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
|
5332 |
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
|
5333 |
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
|
5334 |
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
|
5335 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5336 |
%{ /*NOCONTEXT*/ |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5337 |
FILEPOINTER f; |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5338 |
int ret, _buffered; |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5339 |
OBJ fp; |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5340 |
unsigned char ch; |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5341 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5342 |
if ((__INST(handleType) == nil) |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5343 |
|| (__INST(handleType) == @symbol(filePointer)) |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5344 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5345 |
|| (__INST(handleType) == @symbol(socketHandle)) |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5346 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 5347 |
if (((fp = __INST(handle)) != nil) |
5348 |
&& (__INST(mode) != @symbol(writeonly)) |
|
5349 |
) { |
|
5350 |
f = __FILEVal(fp); |
|
5351 |
||
5352 |
_buffered = (__INST(buffered) == true); |
|
5353 |
if (_buffered) { |
|
5354 |
__READING__(f) |
|
5355 |
} |
|
5356 |
__READBYTE__(ret, f, &ch, _buffered, __INST(handleType)); |
|
5357 |
||
5358 |
if (ret > 0) { |
|
5359 |
RETURN(nil) |
|
5360 |
} |
|
5361 |
if (ret < 0) { |
|
23538 | 5362 |
# ifdef __win32__ |
23743 | 5363 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5364 |
# endif |
23743 | 5365 |
RETURN(__mkSmallInteger(__threadErrno)); |
5366 |
} else /* ret == 0 */ { |
|
5367 |
RETURN(__mkSmallInteger(0)); /* EOF */ |
|
5368 |
} |
|
5369 |
} |
|
16368
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 |
%}. |
23538 | 5372 |
|
5373 |
"Modified: / 22-11-2018 / 15:07:16 / Stefan Vogel" |
|
612 | 5374 |
! |
5375 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5376 |
numAvailable |
21130 | 5377 |
<resource: #obsolete> |
5378 |
^ self numAvailableForRead |
|
612 | 5379 |
! ! |
5380 |
||
5381 |
!ExternalStream methodsFor:'reading'! |
|
5382 |
||
5383 |
next |
|
5384 |
"return the next element; advance read position. |
|
5385 |
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
|
5386 |
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
|
5387 |
- see #pastEndRead." |
1 | 5388 |
|
16296 | 5389 |
|c error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
5390 |
%{ |
18364 | 5391 |
#ifdef __SCHTEAM__ |
5392 |
STObject handle = self.instVarAt(I_handle); |
|
5393 |
||
5394 |
if (handle != STObject.Nil) { |
|
23743 | 5395 |
STObject next; |
5396 |
||
5397 |
if (self.instVarAt(I_binary) == STObject.True) { |
|
5398 |
next = handle.nextByte(); |
|
5399 |
} else { |
|
5400 |
next = handle.nextChar(); |
|
5401 |
} |
|
5402 |
if (next != STObject.EOF) { |
|
5403 |
self.instVarAt_put(I_position, STObject.Nil); |
|
5404 |
return __c__._RETURN( next ); |
|
5405 |
} |
|
5406 |
self.instVarAt_put(I_hitEOF, STObject.True); |
|
18364 | 5407 |
} |
5408 |
#else |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
5409 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5410 |
int ret, _buffered; |
612 | 5411 |
OBJ pos, fp; |
5412 |
unsigned char ch; |
|
5413 |
||
1133 | 5414 |
__INST(lastErrorNumber) = nil; |
12548 | 5415 |
if ((__INST(handleType) == nil) |
5416 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
5417 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5418 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 5419 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 5420 |
if (((fp = __INST(handle)) != nil) |
5421 |
&& (__INST(mode) != @symbol(writeonly)) |
|
5422 |
) { |
|
5423 |
f = __FILEVal(fp); |
|
5424 |
||
5425 |
_buffered = (__INST(buffered) == true); |
|
5426 |
if (_buffered) { |
|
5427 |
__READING__(f) |
|
5428 |
} |
|
5429 |
__READBYTE__(ret, f, &ch, _buffered, __INST(handleType)); |
|
5430 |
||
5431 |
if (ret > 0) { |
|
5432 |
pos = __INST(position); |
|
5433 |
if (__isSmallInteger(pos)) { |
|
5434 |
OBJ t; |
|
5435 |
||
5436 |
t = __MKINT(__intVal(pos) + 1); __INST(position) = t; __STORE(self, t); |
|
5437 |
} else { |
|
5438 |
__INST(position) = nil; /* i.e. do not know */ |
|
5439 |
} |
|
5440 |
if (__INST(binary) == true) { |
|
5441 |
RETURN ( __mkSmallInteger(ch) ); |
|
5442 |
} |
|
5443 |
RETURN ( __MKCHARACTER(ch) ); |
|
5444 |
} |
|
5445 |
||
5446 |
__INST(position) = nil; |
|
5447 |
if (ret < 0) { |
|
23538 | 5448 |
# ifdef __win32__ |
23743 | 5449 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5450 |
# endif |
23743 | 5451 |
error = __mkSmallInteger(__threadErrno); |
5452 |
} else /* ret == 0 */ { |
|
5453 |
__INST(hitEOF) = true; |
|
5454 |
} |
|
5455 |
} |
|
612 | 5456 |
} |
18364 | 5457 |
#endif /* not SCHTEAM */ |
612 | 5458 |
%}. |
21139 | 5459 |
hitEOF ifTrue:[^ self pastEndRead]. |
16296 | 5460 |
error notNil ifTrue:[ |
23743 | 5461 |
lastErrorNumber := error. |
5462 |
^ self readError:error |
|
16296 | 5463 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5464 |
handle isNil ifTrue:[^ self errorNotOpen]. |
5420 | 5465 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
5466 |
||
5467 |
readAhead notNil ifTrue:[ |
|
23743 | 5468 |
c := readAhead. |
5469 |
readAhead := nil. |
|
5470 |
^ c. |
|
5420 | 5471 |
]. |
20679 | 5472 |
|
5473 |
"unknown handleType - future" |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5474 |
c := self nextByteFromFile:handle. |
5430 | 5475 |
c isNil ifTrue:[ |
23743 | 5476 |
^ self pastEndRead. |
5430 | 5477 |
]. |
21139 | 5478 |
binary ifTrue:[ |
23743 | 5479 |
^ c |
5420 | 5480 |
]. |
5481 |
^ Character value:c |
|
23538 | 5482 |
|
5483 |
"Modified: / 22-11-2018 / 14:44:30 / Stefan Vogel" |
|
612 | 5484 |
! |
5485 |
||
5486 |
next:count |
|
5487 |
"return the next count elements of the stream as a collection. |
|
5488 |
Redefined to return a String or ByteArray instead of the default: Array." |
|
5489 |
||
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
5490 |
|coll nRead| |
612 | 5491 |
|
20092 | 5492 |
coll := self contentsSpecies uninitializedNew:count. |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
5493 |
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
|
5494 |
|
20092 | 5495 |
nRead ~~ count ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5496 |
"/ for readStream protocol compatibility, |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5497 |
"/ we must raise an exception here. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5498 |
^ self pastEndRead |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
5499 |
]. |
612 | 5500 |
^ coll |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
5501 |
|
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
5502 |
"Modified: 11.1.1997 / 17:44:17 / cg" |
612 | 5503 |
! |
5504 |
||
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5505 |
nextOrNil |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5506 |
"return the next element; advance read position. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5507 |
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
|
5508 |
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
|
5509 |
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
|
5510 |
|
16296 | 5511 |
|c error| |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5512 |
%{ |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5513 |
FILEPOINTER f; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5514 |
int ret, _buffered; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5515 |
OBJ pos, fp; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5516 |
unsigned char ch; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5517 |
|
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5518 |
__INST(lastErrorNumber) = nil; |
12548 | 5519 |
if ((__INST(handleType) == nil) |
5520 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
5521 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5522 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 5523 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 5524 |
if (((fp = __INST(handle)) != nil) |
5525 |
&& (__INST(mode) != @symbol(writeonly)) |
|
5526 |
) { |
|
5527 |
f = __FILEVal(fp); |
|
5528 |
||
5529 |
_buffered = (__INST(buffered) == true); |
|
5530 |
if (_buffered) { |
|
5531 |
__READING__(f) |
|
5532 |
} |
|
5533 |
__READBYTE__(ret, f, &ch, _buffered, __INST(handleType)); |
|
5534 |
||
5535 |
if (ret > 0) { |
|
5536 |
pos = __INST(position); |
|
5537 |
if (__isSmallInteger(pos)) { |
|
5538 |
OBJ t; |
|
5539 |
||
5540 |
t = __MKINT(__intVal(pos) + 1); __INST(position) = t; __STORE(self, t); |
|
5541 |
} else { |
|
5542 |
__INST(position) = nil; /* i.e. do not know */ |
|
5543 |
} |
|
5544 |
if (__INST(binary) == true) { |
|
5545 |
RETURN ( __mkSmallInteger(ch) ); |
|
5546 |
} |
|
5547 |
RETURN ( __MKCHARACTER(ch) ); |
|
5548 |
} |
|
5549 |
||
5550 |
__INST(position) = nil; |
|
5551 |
if (ret < 0) { |
|
23538 | 5552 |
# ifdef __win32__ |
23743 | 5553 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5554 |
# endif |
23743 | 5555 |
error = __mkSmallInteger(__threadErrno); |
5556 |
} else /* ret == 0 */ { |
|
5557 |
__INST(hitEOF) = true; |
|
5558 |
} |
|
5559 |
} |
|
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5560 |
} |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5561 |
%}. |
21139 | 5562 |
hitEOF ifTrue:[^ nil]. |
16296 | 5563 |
error notNil ifTrue:[ |
23743 | 5564 |
lastErrorNumber := error. |
5565 |
^ self readError:error. |
|
16296 | 5566 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5567 |
handle isNil ifTrue:[^ self errorNotOpen]. |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5568 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5569 |
|
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5570 |
readAhead notNil ifTrue:[ |
23743 | 5571 |
c := readAhead. |
5572 |
readAhead := nil. |
|
5573 |
^ c. |
|
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5574 |
]. |
20679 | 5575 |
|
5576 |
"unknown handleType - future" |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5577 |
c := self nextByteFromFile:handle. |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5578 |
c isNil ifTrue:[ |
23743 | 5579 |
^ nil. |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5580 |
]. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5581 |
binary == true ifTrue:[ |
23743 | 5582 |
^ c |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5583 |
]. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5584 |
^ Character value:c |
23538 | 5585 |
|
5586 |
"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
|
5587 |
! |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5588 |
|
612 | 5589 |
peek |
5590 |
"return the element to be read next without advancing read position. |
|
5591 |
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
|
5592 |
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
|
5593 |
- see #pastEndRead." |
612 | 5594 |
|
16296 | 5595 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
5596 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
5597 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5598 |
unsigned char c; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
5599 |
int ret, _buffered; |
216 | 5600 |
OBJ fp; |
3672
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
5601 |
OBJ ra; |
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
5602 |
|
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
5603 |
if ((ra = __INST(readAhead)) != nil) { |
23743 | 5604 |
if (__INST(binary) == true) { |
5605 |
RETURN ( ra ); |
|
5606 |
} |
|
5607 |
c = __intVal(ra); |
|
5608 |
RETURN ( __MKCHARACTER(c) ); |
|
3029
aa14768e0e6a
larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents:
3016
diff
changeset
|
5609 |
} |
aa14768e0e6a
larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents:
3016
diff
changeset
|
5610 |
|
1133 | 5611 |
__INST(lastErrorNumber) = nil; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
5612 |
|
12548 | 5613 |
if ((__INST(handleType) == nil) |
5614 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
5615 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5616 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 5617 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 5618 |
if (((fp = __INST(handle)) != nil) |
5619 |
&& (__INST(mode) != @symbol(writeonly)) |
|
5620 |
) { |
|
5621 |
f = __FILEVal(fp); |
|
5622 |
_buffered = (__INST(buffered) == true); |
|
5623 |
if (_buffered) { |
|
5624 |
__READING__(f) |
|
5625 |
} |
|
5626 |
__READBYTE__(ret, f, &c, _buffered, __INST(handleType)); |
|
5627 |
||
5628 |
if (ret > 0) { |
|
5629 |
__UNGETC__(c, f, _buffered); |
|
5630 |
||
5631 |
if (__INST(binary) == true) { |
|
5632 |
RETURN ( __mkSmallInteger(c) ); |
|
5633 |
} |
|
5634 |
RETURN ( __MKCHARACTER(c) ); |
|
5635 |
} |
|
5636 |
if (ret < 0) { |
|
23538 | 5637 |
# ifdef __win32__ |
23743 | 5638 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5639 |
# endif |
23743 | 5640 |
error = __mkSmallInteger(__threadErrno); |
5641 |
} else /* ret == 0 */ { |
|
5642 |
__INST(hitEOF) = true; |
|
5643 |
} |
|
5644 |
} |
|
1 | 5645 |
} |
159 | 5646 |
%}. |
21139 | 5647 |
hitEOF ifTrue:[^ self pastEndRead]. |
16296 | 5648 |
error notNil ifTrue:[ |
23743 | 5649 |
lastErrorNumber := error. |
5650 |
^ self readError:error. |
|
16296 | 5651 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5652 |
handle isNil ifTrue:[^ self errorNotOpen]. |
5420 | 5653 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
5654 |
||
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5655 |
readAhead isNil ifTrue:[ |
23743 | 5656 |
readAhead := self nextOrNil. |
5657 |
readAhead isNil ifTrue:[ |
|
5658 |
^ self pastEndRead. |
|
5659 |
]. |
|
5420 | 5660 |
]. |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5661 |
^ readAhead |
23538 | 5662 |
|
5663 |
"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
|
5664 |
! |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5665 |
|
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5666 |
peekOrNil |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5667 |
"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
|
5668 |
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
|
5669 |
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
|
5670 |
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
|
5671 |
|
16296 | 5672 |
|error| |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5673 |
%{ |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5674 |
FILEPOINTER f; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5675 |
unsigned char c; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5676 |
int ret, _buffered; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5677 |
OBJ fp; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5678 |
OBJ ra; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5679 |
|
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5680 |
if ((ra = __INST(readAhead)) != nil) { |
23743 | 5681 |
if (__INST(binary) == true) { |
5682 |
RETURN ( ra ); |
|
5683 |
} |
|
5684 |
c = __intVal(ra); |
|
5685 |
RETURN ( __MKCHARACTER(c) ); |
|
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5686 |
} |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5687 |
|
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5688 |
__INST(lastErrorNumber) = nil; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5689 |
|
12548 | 5690 |
if ((__INST(handleType) == nil) |
5691 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
5692 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5693 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 5694 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 5695 |
if (((fp = __INST(handle)) != nil) |
5696 |
&& (__INST(mode) != @symbol(writeonly)) |
|
5697 |
) { |
|
5698 |
f = __FILEVal(fp); |
|
5699 |
_buffered = (__INST(buffered) == true); |
|
5700 |
if (_buffered) { |
|
5701 |
__READING__(f) |
|
5702 |
} |
|
5703 |
__READBYTE__(ret, f, &c, _buffered, __INST(handleType)); |
|
5704 |
||
5705 |
if (ret > 0) { |
|
5706 |
__UNGETC__(c, f, _buffered); |
|
5707 |
||
5708 |
if (__INST(binary) == true) { |
|
5709 |
RETURN ( __mkSmallInteger(c) ); |
|
5710 |
} |
|
5711 |
RETURN ( __MKCHARACTER(c) ); |
|
5712 |
} |
|
5713 |
if (ret < 0) { |
|
23538 | 5714 |
# ifdef __win32__ |
23743 | 5715 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5716 |
# endif |
23743 | 5717 |
error = __mkSmallInteger(__threadErrno); |
5718 |
} else /* ret == 0 */ { |
|
5719 |
__INST(hitEOF) = true; |
|
5720 |
} |
|
5721 |
} |
|
10348
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 |
%}. |
21139 | 5724 |
hitEOF ifTrue:[^ nil]. |
16296 | 5725 |
error notNil ifTrue:[ |
23743 | 5726 |
lastErrorNumber := error. |
5727 |
^ self readError:error. |
|
16296 | 5728 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5729 |
handle isNil ifTrue:[^ self errorNotOpen]. |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5730 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5731 |
|
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5732 |
readAhead isNil ifTrue:[ |
23743 | 5733 |
readAhead := self nextOrNil. |
5420 | 5734 |
]. |
5735 |
^ readAhead |
|
23538 | 5736 |
|
5737 |
"Modified: / 22-11-2018 / 14:50:22 / Stefan Vogel" |
|
1295 | 5738 |
! |
5739 |
||
5740 |
upToEnd |
|
5741 |
"return a collection of the elements up-to the end. |
|
20092 | 5742 |
Return an empty collection, if the stream-end is already at the end." |
5743 |
||
22849 | 5744 |
|chunkSize chunksAndCounts byteCount data offset contentsSpecies| |
20092 | 5745 |
|
5746 |
"adding to a ByteArray produces quadratic time-space |
|
5747 |
behavior - therefore we allocate chunks, and concatenate them |
|
5748 |
at the end." |
|
5749 |
||
5750 |
chunkSize := 4096. |
|
5751 |
byteCount := 0. |
|
22849 | 5752 |
contentsSpecies := self contentsSpecies. |
5753 |
||
1295 | 5754 |
[self atEnd] whileFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5755 |
|chunk cnt| |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5756 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5757 |
chunk := contentsSpecies uninitializedNew:chunkSize. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5758 |
cnt := self nextBytes:chunkSize into:chunk startingAt:1. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5759 |
cnt ~~ 0 ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5760 |
chunksAndCounts isNil ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5761 |
(cnt < chunkSize and:[self atEnd]) ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5762 |
"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
|
5763 |
^ chunk copyFrom:1 to:cnt. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5764 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5765 |
chunksAndCounts := OrderedCollection new. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5766 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5767 |
chunksAndCounts add:chunk; add:cnt. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5768 |
byteCount := byteCount + cnt. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5769 |
] |
1295 | 5770 |
]. |
20092 | 5771 |
|
5772 |
"now, create one big array" |
|
22849 | 5773 |
data := contentsSpecies uninitializedNew:byteCount. |
20092 | 5774 |
offset := 1. |
22849 | 5775 |
1 to:chunksAndCounts size by:2 do:[:index | |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5776 |
|chunk cnt| |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5777 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5778 |
chunk := chunksAndCounts at:index. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5779 |
cnt := chunksAndCounts at:index+1. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5780 |
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
|
5781 |
offset := offset + cnt |
20092 | 5782 |
]. |
5783 |
^ data |
|
5784 |
||
1295 | 5785 |
|
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
5786 |
" |
20092 | 5787 |
'/dev/null' asFilename readStream upToEnd |
5788 |
'/proc/self/stat' asFilename readStream upToEnd |
|
22849 | 5789 |
'librun.so' asFilename readStream binary upToEnd |
20092 | 5790 |
|
20241 | 5791 |
self assert:('smalltalk.rc' asFilename readStream upToEnd size) |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5792 |
= ('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
|
5793 |
" |
22849 | 5794 |
|
5795 |
"Modified (format): / 09-05-2018 / 20:09:31 / stefan" |
|
612 | 5796 |
! ! |
5797 |
||
5420 | 5798 |
!ExternalStream methodsFor:'rel5 protocol'! |
5799 |
||
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5800 |
atEndFile:handle |
5420 | 5801 |
"for migration to rel5 only" |
5802 |
||
5803 |
self primitiveFailed |
|
5804 |
! |
|
5805 |
||
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5806 |
nextByteFromFile:handle |
5420 | 5807 |
"for migration to rel5 only" |
5808 |
||
5809 |
self primitiveFailed |
|
5810 |
! |
|
5811 |
||
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5812 |
nextPutByte:aByte toFile:handle |
5420 | 5813 |
"for migration to rel5 only" |
5814 |
||
5815 |
self primitiveFailed |
|
5816 |
! ! |
|
5817 |
||
612 | 5818 |
!ExternalStream methodsFor:'testing'! |
5819 |
||
5820 |
atEnd |
|
20675 | 5821 |
"return true, if position is at end. |
21032 | 5822 |
If a stream is at the end, the next read operation |
5823 |
would return or raise an exception immediately without waiting. |
|
5824 |
If a stream is not at the end, this may be a blocking operation |
|
5825 |
(see NonPositionableExternalStream)" |
|
612 | 5826 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
5827 |
%{ |
21221 | 5828 |
OBJ fp, lim; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5829 |
char c; |
612 | 5830 |
|
1133 | 5831 |
if (__INST(hitEOF) == true) { |
23743 | 5832 |
RETURN (true); |
3906
7f2d4a3b63e2
oops - readLimit was not handled in #atEnd
Claus Gittinger <cg@exept.de>
parents:
3878
diff
changeset
|
5833 |
} |
7875
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
5834 |
lim = __INST(readLimit); |
21221 | 5835 |
if (lim != nil && __signedLongIntVal(__INST(position)) >= __signedLongIntVal(lim)) { |
23743 | 5836 |
RETURN (true); |
612 | 5837 |
} |
5838 |
||
1133 | 5839 |
__INST(lastErrorNumber) = nil; |
5840 |
||
12548 | 5841 |
if ((__INST(handleType) == nil) |
5842 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
5843 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5844 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 5845 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 5846 |
if ((fp = __INST(handle)) != nil) { |
5847 |
int _buffered = (__INST(buffered) == true); |
|
5848 |
int ret; |
|
5849 |
FILEPOINTER f = __FILEVal(fp); |
|
5850 |
||
5851 |
if (_buffered) { |
|
5852 |
__READING__(f); |
|
5853 |
} else if (__INST(readAhead) != nil) { |
|
5854 |
RETURN (false); |
|
5855 |
} |
|
5856 |
||
5857 |
/* |
|
5858 |
* read ahead ... |
|
5859 |
*/ |
|
5860 |
do { |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5861 |
#ifdef __win32__ |
23743 | 5862 |
__READBYTE__(ret, f, &c, _buffered, __INST(handleType)); |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5863 |
#else /* not __win32__ */ |
23743 | 5864 |
__BEGIN_INTERRUPTABLE__ |
5865 |
__READBYTE__(ret, f, &c, _buffered, __INST(handleType)); |
|
5866 |
__END_INTERRUPTABLE__ |
|
21221 | 5867 |
#endif /* not __win32__ */ |
23743 | 5868 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
5869 |
if (ret > 0) { |
|
5870 |
__UNGETC__(c&0xff, f, _buffered); |
|
5871 |
RETURN (false); |
|
5872 |
} |
|
5873 |
if (ret == 0) { |
|
5874 |
__INST(hitEOF) = true; |
|
5875 |
RETURN (true); |
|
5876 |
} |
|
5877 |
/* ret < 0 -> error */ |
|
23538 | 5878 |
# ifdef __win32__ |
23743 | 5879 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5880 |
# endif |
23743 | 5881 |
__INST(lastErrorNumber) = __mkSmallInteger(__threadErrno); |
5882 |
} |
|
5883 |
// we do not raise an error here - the next read operation will raise the error. |
|
5884 |
RETURN(false); |
|
612 | 5885 |
} |
5886 |
%}. |
|
20675 | 5887 |
|
22578 | 5888 |
"/ we come here if the handle type is unknown |
5420 | 5889 |
"/ migration support |
20675 | 5890 |
^ self atEndFile:handle |
3906
7f2d4a3b63e2
oops - readLimit was not handled in #atEnd
Claus Gittinger <cg@exept.de>
parents:
3878
diff
changeset
|
5891 |
|
23538 | 5892 |
"Modified: / 30-10-1998 / 20:16:06 / cg" |
5893 |
"Modified: / 22-11-2018 / 14:39:54 / Stefan Vogel" |
|
612 | 5894 |
! |
5895 |
||
10995 | 5896 |
gotErrorOrEOF |
20675 | 5897 |
"answer true, if amn error or eof has been occurred on the stream" |
10995 | 5898 |
|
21139 | 5899 |
^ hitEOF or:[lastErrorNumber notNil] |
10995 | 5900 |
! |
5901 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5902 |
isBinary |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5903 |
"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
|
5904 |
The default when created is false." |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5905 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5906 |
^ binary |
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
5907 |
! |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
5908 |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5909 |
isBlocking |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5910 |
"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
|
5911 |
|
22195 | 5912 |
|fd| |
5913 |
||
5914 |
fd := self fileDescriptor. |
|
5915 |
"self fileDescriptor may set handle to nil" |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5916 |
handle isNil ifTrue:[^ self errorNotOpen]. |
22195 | 5917 |
^ OperatingSystem isBlockingOn:fd |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5918 |
! |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5919 |
|
22694 | 5920 |
isExecutor |
5921 |
"am I an executor and no real stream object?" |
|
5922 |
||
5923 |
^ mode == #executor. |
|
5924 |
||
5925 |
"Created: / 23-04-2018 / 18:17:40 / stefan" |
|
5926 |
! |
|
5927 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5928 |
isExternalStream |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5929 |
"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
|
5930 |
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
|
5931 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5932 |
^ true |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5933 |
! |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5934 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5935 |
isOpen |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5936 |
"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
|
5937 |
|
22694 | 5938 |
"executors are only used to finalize - they are not really open and are closed with #closeFile, |
5939 |
which does not check for #isOpen" |
|
5940 |
^ handle notNil and:[self isExecutor not] |
|
5941 |
||
5942 |
"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
|
5943 |
! |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5944 |
|
22978 | 5945 |
isPipeStream |
5946 |
"return true, if this stream is a pipe" |
|
5947 |
||
5948 |
^ false |
|
5949 |
! |
|
5950 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5951 |
isReadable |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5952 |
"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
|
5953 |
|
21139 | 5954 |
^ mode ~~ #writeonly |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5955 |
! |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5956 |
|
22978 | 5957 |
isSocket |
5958 |
"return true, if this stream is a socket" |
|
5959 |
||
5960 |
^ false |
|
5961 |
! |
|
5962 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5963 |
isWritable |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5964 |
"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
|
5965 |
|
21139 | 5966 |
^ mode ~~ #readonly |
612 | 5967 |
! ! |
5968 |
||
5969 |
!ExternalStream methodsFor:'waiting for I/O'! |
|
5970 |
||
5101 | 5971 |
canBeSelected |
5972 |
"return true, if this stream can be selected upon" |
|
5973 |
||
5974 |
^ OperatingSystem supportsSelect |
|
5975 |
! |
|
5976 |
||
20104 | 5977 |
numAvailableForRead |
20241 | 5978 |
"answer the number of bytes available for reading" |
5979 |
||
20104 | 5980 |
|available| |
5981 |
||
5982 |
handle isNil ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5983 |
^ self errorNotOpen |
20104 | 5984 |
]. |
5985 |
mode == #writeonly ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5986 |
^ self errorWriteOnly |
20104 | 5987 |
]. |
21238 | 5988 |
available := OperatingSystem numAvailableForReadOn:self fileHandle. |
20104 | 5989 |
readAhead notNil ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5990 |
available := available + 1 |
20104 | 5991 |
]. |
5992 |
^ available. |
|
5993 |
||
5994 |
" |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5995 |
'/etc/hosts' asFilename readStream numAvailableForRead |
21130 | 5996 |
" |
20104 | 5997 |
! |
5998 |
||
18327 | 5999 |
readWaitWithTimeoutMs:timeoutOrNil |
612 | 6000 |
"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
|
6001 |
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
|
6002 |
If data is already available, return immediate. |
20259 | 6003 |
Return true if a timeout occurred (i.e. false, if data is available). |
612 | 6004 |
The other threads are not affected by the wait." |
6005 |
||
16480 | 6006 |
|fd inputSema hasTimedout wasBlocked| |
612 | 6007 |
|
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
6008 |
readAhead notNil ifTrue:[^ false]. |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
6009 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
6010 |
handle isNil ifTrue:[^ self errorNotOpen]. |
612 | 6011 |
mode == #writeonly ifTrue:[^ self errorWriteOnly]. |
6012 |
||
21238 | 6013 |
fd := self fileHandle. |
612 | 6014 |
(OperatingSystem readCheck:fd) ifTrue:[^ false]. |
6015 |
||
20104 | 6016 |
"cannot do a readWait (which means possible suspend), |
6017 |
if the processor is not yet initialized; i.e. if a read is attempted |
|
6018 |
during early startup. |
|
6019 |
This may happen, for example, if a MiniDebugger is entered, before |
|
6020 |
process scheduling has been setup. |
|
6021 |
In this case, all I/O operations here will be blocking." |
|
6022 |
||
23726 | 6023 |
Smalltalk isInitialized ifFalse:[ |
23743 | 6024 |
^ false |
23726 | 6025 |
]. |
20104 | 6026 |
|
612 | 6027 |
wasBlocked := OperatingSystem blockInterrupts. |
22177 | 6028 |
inputSema := Semaphore name:'readWait'. |
23726 | 6029 |
hasTimedout := [ |
23743 | 6030 |
Processor signal:inputSema onInput:fd. |
6031 |
(inputSema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil. |
|
16463 | 6032 |
] ifCurtailed:[ |
23743 | 6033 |
Processor disableSemaphore:inputSema. |
6034 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
612 | 6035 |
]. |
22683 | 6036 |
hasTimedout ifTrue:[ |
23743 | 6037 |
Processor disableSemaphore:inputSema. |
16480 | 6038 |
]. |
612 | 6039 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
16480 | 6040 |
^ hasTimedout |
22177 | 6041 |
|
6042 |
"Modified: / 09-08-2017 / 11:53:58 / cg" |
|
23726 | 6043 |
"Modified: / 12-02-2019 / 20:56:53 / Stefan Vogel" |
612 | 6044 |
! |
6045 |
||
22683 | 6046 |
readWriteWaitWithTimeoutMs:timeoutOrNil |
6047 |
"suspend the current process, until the receiver |
|
6048 |
becomes ready for reading or writing or a timeout (in milliseconds) expired. |
|
6049 |
Return true if a timeout occurred (i.e. false, if data is available). |
|
6050 |
Return immediate if the receiver is already ready. |
|
6051 |
The other threads are not affected by the wait." |
|
6052 |
||
6053 |
|fd sema hasTimedout wasBlocked| |
|
6054 |
||
6055 |
readAhead notNil ifTrue:[^ false]. |
|
6056 |
handle isNil ifTrue:[ |
|
23743 | 6057 |
^ self errorNotOpen |
22683 | 6058 |
]. |
6059 |
||
6060 |
fd := self fileHandle. |
|
6061 |
(OperatingSystem readWriteCheck:fd) ifTrue:[^ false]. |
|
6062 |
||
6063 |
wasBlocked := OperatingSystem blockInterrupts. |
|
6064 |
sema := Semaphore name:'readWriteWait'. |
|
23726 | 6065 |
hasTimedout := [ |
23743 | 6066 |
Processor |
6067 |
signal:sema onOutput:fd; |
|
6068 |
signal:sema onInput:fd. |
|
6069 |
(sema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil. |
|
22683 | 6070 |
] ifCurtailed:[ |
23743 | 6071 |
Processor disableSemaphore:sema. |
6072 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
22683 | 6073 |
]. |
6074 |
hasTimedout ifTrue:[ |
|
23743 | 6075 |
Processor disableSemaphore:sema. |
22683 | 6076 |
]. |
6077 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
6078 |
^ hasTimedout |
|
6079 |
||
6080 |
"Modified: / 09-08-2017 / 11:54:03 / cg" |
|
23726 | 6081 |
"Modified: / 12-02-2019 / 20:23:41 / Stefan Vogel" |
22683 | 6082 |
! |
6083 |
||
6084 |
writeExceptionWaitWithTimeoutMs:timeoutOrNil |
|
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
6085 |
"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
|
6086 |
becomes ready for reading or writing or a timeout (in milliseconds) expired. |
20259 | 6087 |
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
|
6088 |
Return immediate if the receiver is already ready. |
5506 | 6089 |
The other threads are not affected by the wait." |
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
6090 |
|
16480 | 6091 |
|fd sema hasTimedout wasBlocked| |
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
6092 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
6093 |
handle isNil ifTrue:[ |
23743 | 6094 |
^ self errorNotOpen |
18956 | 6095 |
]. |
6096 |
||
21238 | 6097 |
fd := self fileHandle. |
18956 | 6098 |
(OperatingSystem writeExceptionCheck:fd) ifTrue:[^ false]. |
6099 |
||
6100 |
wasBlocked := OperatingSystem blockInterrupts. |
|
22177 | 6101 |
sema := Semaphore name:'writeExceptionWait'. |
23726 | 6102 |
hasTimedout := [ |
23743 | 6103 |
Processor |
6104 |
signal:sema onOutput:fd; |
|
6105 |
signal:sema onException:fd. |
|
6106 |
(sema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil. |
|
18956 | 6107 |
] ifCurtailed:[ |
23743 | 6108 |
Processor disableSemaphore:sema. |
6109 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
18956 | 6110 |
]. |
22683 | 6111 |
hasTimedout ifTrue:[ |
23743 | 6112 |
Processor disableSemaphore:sema. |
18956 | 6113 |
]. |
6114 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
6115 |
^ hasTimedout |
|
22177 | 6116 |
|
6117 |
"Modified: / 09-08-2017 / 11:54:10 / cg" |
|
23726 | 6118 |
"Modified: / 12-02-2019 / 20:24:03 / Stefan Vogel" |
18956 | 6119 |
! |
6120 |
||
22683 | 6121 |
writeWaitWithTimeoutMs:timeoutOrNil |
612 | 6122 |
"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
|
6123 |
becomes ready for writing or a timeout (in milliseconds) expired. |
20259 | 6124 |
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
|
6125 |
Return immediate if the receiver is already ready. |
612 | 6126 |
The other threads are not affected by the wait." |
6127 |
||
16480 | 6128 |
|fd outputSema hasTimedout wasBlocked| |
612 | 6129 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
6130 |
handle isNil ifTrue:[ |
23743 | 6131 |
^ self errorNotOpen |
612 | 6132 |
]. |
6133 |
mode == #readonly ifTrue:[ |
|
23743 | 6134 |
^ self errorReadOnly |
612 | 6135 |
]. |
6136 |
||
21238 | 6137 |
fd := self fileHandle. |
612 | 6138 |
(OperatingSystem writeCheck:fd) ifTrue:[^ false]. |
6139 |
||
6140 |
wasBlocked := OperatingSystem blockInterrupts. |
|
22177 | 6141 |
outputSema := Semaphore name:'writeWait'. |
23726 | 6142 |
hasTimedout := [ |
23743 | 6143 |
Processor signal:outputSema onOutput:fd. |
6144 |
(outputSema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil. |
|
16463 | 6145 |
] ifCurtailed:[ |
23743 | 6146 |
Processor disableSemaphore:outputSema. |
6147 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
612 | 6148 |
]. |
22683 | 6149 |
hasTimedout ifTrue:[ |
23743 | 6150 |
Processor disableSemaphore:outputSema. |
16480 | 6151 |
]. |
612 | 6152 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
16480 | 6153 |
^ hasTimedout |
22177 | 6154 |
|
6155 |
"Modified: / 09-08-2017 / 11:54:14 / cg" |
|
23726 | 6156 |
"Modified: / 12-02-2019 / 20:25:09 / Stefan Vogel" |
612 | 6157 |
! ! |
6158 |
||
6159 |
!ExternalStream methodsFor:'writing'! |
|
6160 |
||
6161 |
cr |
|
6162 |
"append an end-of-line character (or CRLF if in crlf mode). |
|
6163 |
reimplemented for speed" |
|
6164 |
||
23538 | 6165 |
|error| |
6166 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
6167 |
%{ |
12548 | 6168 |
if ((__INST(handleType) == nil) |
6169 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
6170 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 6171 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
6172 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
23743 | 6173 |
OBJ fp; |
6174 |
||
6175 |
__INST(lastErrorNumber) = nil; |
|
6176 |
if (((fp = __INST(handle)) != nil) |
|
6177 |
&& (__INST(mode) != @symbol(readonly)) |
|
6178 |
&& (__INST(binary) != true) |
|
6179 |
) { |
|
6180 |
FILEPOINTER f = __FILEVal(fp); |
|
6181 |
int _buffered = (__INST(buffered) == true); |
|
6182 |
int len, cnt; |
|
6183 |
char *cp; |
|
6184 |
||
6185 |
if (_buffered) { |
|
6186 |
__WRITING__(f) |
|
6187 |
} |
|
6188 |
{ |
|
6189 |
OBJ mode = __INST(eolMode); |
|
6190 |
||
6191 |
if (mode == @symbol(cr)) { |
|
6192 |
cp = "\r"; len = 1; |
|
6193 |
} else if (mode == @symbol(crlf)) { |
|
6194 |
cp = "\r\n"; len = 2; |
|
6195 |
} else if (mode == @symbol(eot)) { |
|
6196 |
cp = "\004"; len = 1; |
|
6197 |
} else if (mode == @symbol(etx)) { |
|
6198 |
cp = "\003"; len = 1; |
|
6199 |
} else { |
|
6200 |
cp = "\n"; len = 1; |
|
6201 |
} |
|
6202 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6203 |
#ifdef __win32__ |
23743 | 6204 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6205 |
cnt = __win32_fwrite(cp, 1, len, f); |
|
6206 |
} else |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
6207 |
#endif |
23743 | 6208 |
{ |
6209 |
__WRITEBYTES__(cnt, f, cp, len, _buffered, __INST(handleType)); |
|
6210 |
} |
|
6211 |
if (cnt == len) { |
|
6212 |
if (__isSmallInteger(__INST(position))) { |
|
6213 |
INT np = __intVal(__INST(position)) + len; |
|
6214 |
OBJ t; |
|
6215 |
||
6216 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
6217 |
} else { |
|
6218 |
__INST(position) = nil; /* i.e: don't know */ |
|
6219 |
} |
|
6220 |
RETURN ( self ); |
|
6221 |
} |
|
23538 | 6222 |
# ifdef __win32__ |
23743 | 6223 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 6224 |
# endif |
23743 | 6225 |
error = __mkSmallInteger(__threadErrno); |
6226 |
} |
|
612 | 6227 |
} |
6228 |
%}. |
|
23538 | 6229 |
error notNil ifTrue:[ |
23743 | 6230 |
lastErrorNumber := error. |
6231 |
self writeError:error. |
|
6232 |
^ self |
|
23538 | 6233 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
6234 |
handle isNil ifTrue:[self errorNotOpen. ^ self]. |
2326 | 6235 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
21139 | 6236 |
binary ifTrue:[self errorBinary. ^ self]. |
5414 | 6237 |
|
17426
6e49243ce4e0
fix: code treated everything but nl,cr,crnl symbols als cr (by accident).
Claus Gittinger <cg@exept.de>
parents:
17420
diff
changeset
|
6238 |
(eolMode == #cr) ifTrue:[ |
23743 | 6239 |
self nextPut:(Character return). |
6240 |
^ 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
|
6241 |
]. |
6e49243ce4e0
fix: code treated everything but nl,cr,crnl symbols als cr (by accident).
Claus Gittinger <cg@exept.de>
parents:
17420
diff
changeset
|
6242 |
(eolMode == #crlf) ifTrue:[ |
23743 | 6243 |
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
|
6244 |
]. |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
6245 |
self nextPut:(Character nl). |
5414 | 6246 |
^ self |
23538 | 6247 |
|
6248 |
"Modified: / 22-11-2018 / 14:41:46 / Stefan Vogel" |
|
612 | 6249 |
! |
6250 |
||
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6251 |
flush |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6252 |
"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
|
6253 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6254 |
%{ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6255 |
__INST(lastErrorNumber) = nil; |
12548 | 6256 |
if ((__INST(handleType) == nil) |
6257 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
6258 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
6259 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
24045 | 6260 |
OBJ fp; |
6261 |
int _buffered = (__INST(buffered) == true); |
|
6262 |
||
6263 |
if ((fp = __INST(handle)) != nil) { |
|
6264 |
if (__INST(mode) != @symbol(readonly)) { |
|
6265 |
if (1 /* _buffered */) { |
|
6266 |
FILEPOINTER f = __FILEVal(fp); |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6267 |
#ifdef __win32__ |
24045 | 6268 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6269 |
__win32_fflush(f); |
|
6270 |
} else { |
|
6271 |
int rslt; |
|
6272 |
||
6273 |
do { |
|
6274 |
__threadErrno = 0; |
|
6275 |
rslt = __STX_C_CALL1("fflush", fflush, f); |
|
6276 |
} while((rslt < 0) && (__threadErrno == EINTR)); |
|
6277 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6278 |
#else /* ! __win32__ */ |
24045 | 6279 |
__BEGIN_INTERRUPTABLE__ |
6280 |
FFLUSH(f); |
|
6281 |
__END_INTERRUPTABLE__ |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6282 |
#endif /* ! __win32__ */ |
24045 | 6283 |
} |
6284 |
} |
|
6285 |
} |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6286 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6287 |
%} |
24045 | 6288 |
|
6289 |
"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
|
6290 |
! |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6291 |
|
612 | 6292 |
nextPut:aCharacter |
6293 |
"write the argument, aCharacter - return nil if failed, self if ok. |
|
6294 |
Only single-byte characters are currently supported" |
|
6295 |
||
16296 | 6296 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
6297 |
%{ |
18364 | 6298 |
#ifdef __SCHTEAM__ |
6299 |
STObject handle = self.instVarAt(I_handle); |
|
6300 |
||
6301 |
if ((handle != STObject.Nil) |
|
6302 |
&& (aCharacter.isSTCharacter())) { |
|
23743 | 6303 |
handle.writeChar( aCharacter ); |
6304 |
self.instVarAt_put(I_position, STObject.Nil); |
|
6305 |
return __c__._RETURN_self(); |
|
18364 | 6306 |
} |
6307 |
#else |
|
17332 | 6308 |
__INST(lastErrorNumber) = nil; |
6309 |
if ((__INST(handleType) == nil) |
|
6310 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
6311 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
6312 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
6313 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
23743 | 6314 |
OBJ fp; |
6315 |
||
6316 |
if (((fp = __INST(handle)) != nil) |
|
6317 |
&& (__INST(mode) != @symbol(readonly)) |
|
6318 |
) { |
|
6319 |
FILEPOINTER f = __FILEVal(fp); |
|
6320 |
int _buffered = (__INST(buffered) == true); |
|
6321 |
int cnt; |
|
6322 |
char buff[2]; |
|
6323 |
int nBytes = 1; |
|
6324 |
||
6325 |
if (__INST(binary) != true) { |
|
6326 |
if (__isCharacter(aCharacter)) { |
|
6327 |
unsigned int codePoint = __intVal(__characterVal(aCharacter)); |
|
6328 |
if (codePoint <= 0xFF) { |
|
6329 |
unsigned char c = codePoint; |
|
6330 |
buff[0] = c; nBytes = 1; |
|
6331 |
||
6332 |
if (c == '\n') { |
|
6333 |
OBJ mode = __INST(eolMode); |
|
6334 |
if (mode == @symbol(nl)) { |
|
6335 |
// no EOL translation |
|
6336 |
} else if (mode == nil) { |
|
6337 |
// no EOL translation |
|
6338 |
} else if (mode == @symbol(cr)) { |
|
6339 |
buff[0] = '\r'; |
|
6340 |
} else if (mode == @symbol(eot)) { |
|
6341 |
buff[0] = '\004'; |
|
6342 |
} else if (mode == @symbol(etx)) { |
|
6343 |
buff[0] = '\003'; |
|
6344 |
} else if (mode == @symbol(crlf)) { |
|
6345 |
buff[0] = '\r'; |
|
6346 |
buff[1] = '\n'; |
|
6347 |
nBytes = 2; |
|
6348 |
} |
|
6349 |
} |
|
17332 | 6350 |
doWrite: |
23743 | 6351 |
if (! f) { |
6352 |
fprintf(stderr, "oops - fileHandle is NULL in nextPut:\n"); |
|
6353 |
__INST(handle) = nil; |
|
6354 |
goto out; |
|
6355 |
} |
|
6356 |
||
6357 |
if (_buffered) { |
|
6358 |
__WRITING__(f) |
|
6359 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6360 |
# ifdef __win32__ |
23743 | 6361 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6362 |
cnt = __win32_fwrite(buff, 1, nBytes, f); |
|
6363 |
} else |
|
18364 | 6364 |
# endif |
23743 | 6365 |
{ |
6366 |
__WRITEBYTES__(cnt, f, buff, nBytes, _buffered, __INST(handleType)); |
|
6367 |
} |
|
6368 |
if (cnt == nBytes) { |
|
6369 |
if (__isSmallInteger(__INST(position))) { |
|
6370 |
INT np = __intVal(__INST(position)) + nBytes; |
|
6371 |
OBJ t; |
|
6372 |
||
6373 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
6374 |
} else { |
|
6375 |
__INST(position) = nil; /* i.e. do not know */ |
|
6376 |
} |
|
6377 |
RETURN ( self ); |
|
6378 |
} |
|
23538 | 6379 |
# ifdef __win32__ |
23743 | 6380 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 6381 |
# endif |
23743 | 6382 |
error = __mkSmallInteger(__threadErrno); |
6383 |
} |
|
6384 |
} |
|
6385 |
} else { |
|
6386 |
if (__isSmallInteger(aCharacter)) { |
|
6387 |
unsigned char c = __intVal(aCharacter); |
|
6388 |
buff[0] = c; nBytes = 1; |
|
6389 |
goto doWrite; |
|
6390 |
} |
|
6391 |
} |
|
6392 |
} |
|
17332 | 6393 |
} |
6394 |
out: ; |
|
18364 | 6395 |
#endif /* not SCHTEAM */ |
17332 | 6396 |
%}. |
6397 |
error notNil ifTrue:[ |
|
23743 | 6398 |
lastErrorNumber := error. |
6399 |
self writeError:error. |
|
6400 |
^ self |
|
17332 | 6401 |
]. |
6402 |
handle isNil ifTrue:[self errorNotOpen. ^ self]. |
|
6403 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
|
21139 | 6404 |
binary == true ifTrue:[ |
23743 | 6405 |
aCharacter isInteger ifFalse:[ |
6406 |
self argumentMustBeInteger. |
|
6407 |
^ self. |
|
6408 |
]. |
|
21139 | 6409 |
] ifFalse:[ |
23743 | 6410 |
(aCharacter isCharacter not |
6411 |
or:[aCharacter codePoint > 16rFF]) ifTrue:[ |
|
6412 |
self argumentMustBeCharacter. |
|
6413 |
^ self. |
|
6414 |
]. |
|
17332 | 6415 |
]. |
6416 |
"/ migration support |
|
6417 |
self |
|
23743 | 6418 |
nextPutByte:aCharacter asInteger |
6419 |
toFile:handle |
|
23538 | 6420 |
|
6421 |
"Modified: / 22-11-2018 / 14:47:13 / Stefan Vogel" |
|
17332 | 6422 |
! |
6423 |
||
17418 | 6424 |
nextPutAll:aCollection |
6425 |
"write all elements of the argument, aCollection. |
|
6426 |
Reimplemented for speed when writing strings or byteArrays. |
|
6427 |
For others, falls back to general method in superclass." |
|
6428 |
||
6429 |
|error| |
|
6430 |
%{ |
|
18364 | 6431 |
#ifdef __SCHTEAM__ |
6432 |
STObject handle = self.instVarAt(I_handle); |
|
6433 |
||
6434 |
if ((handle != STObject.Nil) |
|
6435 |
&& (aCollection.isSTString())) { |
|
23743 | 6436 |
handle.writeCharacters( aCollection.asSTString().characters ); |
6437 |
self.instVarAt_put(I_position, STObject.Nil); |
|
6438 |
return __c__._RETURN_self(); |
|
18364 | 6439 |
} |
6440 |
#else |
|
17418 | 6441 |
|
6442 |
__INST(lastErrorNumber) = nil; |
|
6443 |
||
6444 |
if ((__INST(handleType) == nil) |
|
6445 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
6446 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
6447 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
6448 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
23743 | 6449 |
OBJ fp; |
6450 |
||
6451 |
if (((fp = __INST(handle)) != nil) |
|
6452 |
&& (__INST(mode) != @symbol(readonly)) |
|
6453 |
) { |
|
6454 |
INT len, cnt; |
|
6455 |
INT o_offs; |
|
6456 |
FILEPOINTER f = __FILEVal(fp); |
|
6457 |
int _buffered = (__INST(buffered) == true); |
|
6458 |
||
6459 |
if (! f) { |
|
6460 |
fprintf(stderr, "oops - fileHandle is NULL in nextPutAll:\n"); |
|
6461 |
__INST(handle) = nil; |
|
6462 |
goto out; |
|
6463 |
} |
|
6464 |
if (_buffered) { |
|
6465 |
__WRITING__(f) |
|
6466 |
} |
|
6467 |
||
6468 |
if (__isStringLike(aCollection)) { |
|
6469 |
OBJ mode = __INST(eolMode); |
|
6470 |
char *stringP = __stringVal(aCollection); |
|
6471 |
len = __stringSize(aCollection); |
|
6472 |
||
6473 |
if (__INST(binary) != true |
|
6474 |
&& ((mode == @symbol(cr)) |
|
6475 |
|| (mode == @symbol(etx)) |
|
6476 |
|| (mode == @symbol(eot)) |
|
6477 |
|| (mode == @symbol(crlf))) |
|
6478 |
&& memchr(stringP, '\n', len) != NULL) |
|
6479 |
{ |
|
6480 |
// there is a '\n' to be translated, replace it into a buffer |
|
6481 |
||
6482 |
char *end; |
|
6483 |
char sep[2]; |
|
6484 |
int sepLen = 1; |
|
6485 |
int bufLen; |
|
6486 |
char *buf, *endBuf, *sp, *dp; |
|
6487 |
||
6488 |
sep[0] = '\n'; |
|
6489 |
if (mode == @symbol(crlf)) { |
|
6490 |
sep[0] = '\r'; sep[1] = '\n'; sepLen = 2; |
|
6491 |
} else if (mode == @symbol(cr)) { |
|
6492 |
sep[0] = '\r'; |
|
6493 |
} else if (mode == @symbol(eot)) { |
|
6494 |
sep[0] = '\004'; |
|
6495 |
} else if (mode == @symbol(etx)) { |
|
6496 |
sep[0] = '\003'; |
|
6497 |
} |
|
6498 |
||
6499 |
// estimate size of buffer - assume every 4th char is a separator |
|
6500 |
bufLen = (sepLen == 1) ? len : (len + ((len/4) + 1) * sepLen); |
|
6501 |
buf = (char *)malloc(bufLen); |
|
6502 |
if (buf == NULL) { |
|
6503 |
error = __mkSmallInteger(ENOMEM); |
|
6504 |
goto out; |
|
6505 |
} |
|
6506 |
||
6507 |
endBuf = buf + bufLen; |
|
6508 |
end = stringP + len; |
|
6509 |
for (sp = stringP, dp = buf; sp < end; sp++) { |
|
6510 |
char c; |
|
6511 |
||
6512 |
if ((dp+sepLen) >= endBuf) { |
|
6513 |
char *newBuf; |
|
6514 |
||
6515 |
bufLen = bufLen * 2; |
|
6516 |
newBuf = (char *)realloc(buf, bufLen); |
|
6517 |
if (newBuf == NULL) { |
|
6518 |
free(buf); |
|
6519 |
error = __mkSmallInteger(ENOMEM); |
|
6520 |
goto out; |
|
6521 |
} |
|
6522 |
endBuf = newBuf + bufLen; |
|
6523 |
dp = newBuf + (dp-buf); |
|
6524 |
buf = newBuf; |
|
6525 |
} |
|
6526 |
||
6527 |
if ((c = *sp) != '\n') { |
|
6528 |
*dp++ = c; |
|
6529 |
} else { |
|
6530 |
*dp++ = sep[0]; |
|
6531 |
if (sepLen == 2) { |
|
6532 |
*dp++ = sep[1]; |
|
6533 |
}; |
|
6534 |
} |
|
6535 |
} |
|
6536 |
||
6537 |
len = dp - buf; |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6538 |
# ifdef __win32__ |
23743 | 6539 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6540 |
cnt = __win32_fwrite(buf, 1, len, f); |
|
6541 |
} else |
|
18364 | 6542 |
# endif |
23743 | 6543 |
{ |
6544 |
__WRITEBYTES__(cnt, f, buf, len, _buffered, __INST(handleType)); |
|
6545 |
} |
|
6546 |
free(buf); |
|
6547 |
} else { // No EOL conversion needed |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6548 |
# ifdef __win32__ |
23743 | 6549 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6550 |
cnt = __win32_fwrite(stringP, 1, len, f); |
|
6551 |
} else |
|
18364 | 6552 |
# endif |
23743 | 6553 |
{ |
6554 |
o_offs = stringP - (char *)__InstPtr(aCollection); |
|
6555 |
__WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs, len, _buffered, __INST(handleType)); |
|
6556 |
} |
|
6557 |
} |
|
6558 |
} else { // Not a String |
|
6559 |
if (__INST(binary) == true) { |
|
6560 |
INT offs; |
|
6561 |
||
6562 |
if (__isByteArrayLike(aCollection)) { |
|
6563 |
offs = 0; |
|
6564 |
len = __byteArraySize(aCollection); |
|
6565 |
} else if (__isBytes(aCollection)) { |
|
6566 |
offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars)); |
|
6567 |
len = __byteArraySize(aCollection) - offs; |
|
6568 |
} else |
|
6569 |
goto out; |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6570 |
# ifdef __win32__ |
23743 | 6571 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6572 |
cnt = __win32_fwrite(__stringVal(aCollection), 1, len, f); |
|
6573 |
} else |
|
18364 | 6574 |
# endif |
23743 | 6575 |
{ |
6576 |
o_offs = (char *)(__ByteArrayInstPtr(aCollection)->ba_element) - (char *)__InstPtr(aCollection); |
|
6577 |
o_offs += offs; |
|
6578 |
__WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs, len, _buffered, __INST(handleType)); |
|
6579 |
} |
|
6580 |
} else // Not binary mode |
|
6581 |
goto out; |
|
6582 |
} |
|
6583 |
||
6584 |
// Now check for errors |
|
6585 |
if (cnt == len) { |
|
6586 |
if (__isSmallInteger(__INST(position))) { |
|
6587 |
INT np = __intVal(__INST(position)) + len; |
|
6588 |
OBJ t; |
|
6589 |
||
6590 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
6591 |
} else { |
|
6592 |
__INST(position) = nil; /* i.e. do not know */ |
|
6593 |
} |
|
6594 |
RETURN (self); |
|
6595 |
} |
|
23538 | 6596 |
# ifdef __win32__ |
23743 | 6597 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 6598 |
# endif |
23743 | 6599 |
error = __mkSmallInteger(__threadErrno); |
6600 |
fprintf(stderr, "cnt=%"_ld_" len=%"_ld_"\n", (INT)cnt, (INT)len); |
|
6601 |
} |
|
17418 | 6602 |
} |
6603 |
out: ; |
|
18364 | 6604 |
#endif /* not SCHTEAM */ |
17418 | 6605 |
%}. |
6606 |
error notNil ifTrue:[ |
|
23743 | 6607 |
lastErrorNumber := error. |
6608 |
self writeError:error. |
|
6609 |
^ self |
|
17418 | 6610 |
]. |
6611 |
handle isNil ifTrue:[self errorNotOpen. ^ self]. |
|
6612 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
|
6613 |
||
6614 |
^ super nextPutAll:aCollection |
|
23538 | 6615 |
|
6616 |
"Modified: / 22-11-2018 / 11:16:12 / Stefan Vogel" |
|
17418 | 6617 |
! |
6618 |
||
17608 | 6619 |
nextPutAll:initialWriteCount from:buffer startingAt:initialOffset |
22232 | 6620 |
"append count elements with index starting at initialOffset |
6621 |
of the argument, buffer onto the receiver. |
|
6622 |
This is only allowed, if the receiver supports writing. |
|
6623 |
Answer the number of elements that were appended. |
|
6624 |
Buffer should be a byte collection. |
|
20270 | 6625 |
I don't know how to write non-bytes to an external stream, but let superclass handle this." |
17608 | 6626 |
|
22234 | 6627 |
buffer isSingleByteCollection ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
6628 |
^ self nextPutBytes:initialWriteCount from:buffer startingAt:initialOffset. |
17608 | 6629 |
]. |
6630 |
||
6631 |
^ super nextPutAll:initialWriteCount from:buffer startingAt:initialOffset |
|
6632 |
! |
|
6633 |
||
17418 | 6634 |
nextPutAll:aCollection startingAt:start to:stop |
6635 |
"write a range of elements of the argument, aCollection. |
|
6636 |
Reimplemented for speed when writing strings or byteArrays. |
|
6637 |
For others, falls back to general method in superclass." |
|
6638 |
||
6639 |
|error| |
|
6640 |
||
6641 |
%{ |
|
6642 |
__INST(lastErrorNumber) = nil; |
|
6643 |
if ((__INST(handleType) == nil) |
|
6644 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
6645 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
6646 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
6647 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
23743 | 6648 |
OBJ fp = __INST(handle); |
6649 |
||
6650 |
if ((fp != nil) |
|
6651 |
&& (__INST(mode) != @symbol(readonly)) |
|
6652 |
&& __bothSmallInteger(start, stop) |
|
6653 |
) { |
|
6654 |
int _buffered = (__INST(buffered) == true); |
|
6655 |
FILEPOINTER f = __FILEVal(fp); |
|
6656 |
int offs, len, cnt; |
|
6657 |
int iStart = __intVal(start); |
|
6658 |
int iStop = __intVal(stop); |
|
6659 |
int o_offs; |
|
6660 |
||
6661 |
if (_buffered ) { |
|
6662 |
__WRITING__(f) |
|
6663 |
} |
|
6664 |
||
6665 |
if ((iStart < 1) || (iStop < iStart)) { |
|
6666 |
RETURN(self); |
|
6667 |
} |
|
6668 |
if (__isStringLike(aCollection)) { |
|
6669 |
char *stringP; |
|
6670 |
OBJ mode = __INST(eolMode); |
|
6671 |
||
6672 |
len = __stringSize(aCollection); |
|
6673 |
if (iStop > len) { |
|
6674 |
RETURN(self); |
|
6675 |
} |
|
6676 |
if (iStop > len) |
|
6677 |
iStop = len; |
|
6678 |
len = iStop - iStart + 1; |
|
6679 |
stringP = __stringVal(aCollection) + iStart - 1; |
|
6680 |
||
6681 |
if (__INST(binary) != true |
|
6682 |
&& ((mode == @symbol(cr)) |
|
6683 |
|| (mode == @symbol(etx)) |
|
6684 |
|| (mode == @symbol(eot)) |
|
6685 |
|| (mode == @symbol(crlf))) |
|
6686 |
&& memchr(stringP, '\n', len) != NULL) |
|
6687 |
{ |
|
6688 |
// see if there is a \n which needs to be translated, replace it |
|
6689 |
||
6690 |
char *end = stringP + len; |
|
6691 |
char sep[2]; |
|
6692 |
int sepLen = 1; |
|
6693 |
int bufLen; |
|
6694 |
char *buf, *endBuf, *sp, *dp; |
|
6695 |
||
6696 |
sep[0] = '\n'; |
|
6697 |
if (mode == @symbol(crlf)) { |
|
6698 |
sep[0] = '\r'; sep[1] = '\n'; sepLen = 2; |
|
6699 |
} else if (mode == @symbol(cr)) { |
|
6700 |
sep[0] = '\r'; |
|
6701 |
} else if (mode == @symbol(eot)) { |
|
6702 |
sep[0] = '\004'; |
|
6703 |
} else if (mode == @symbol(etx)) { |
|
6704 |
sep[0] = '\003'; |
|
6705 |
} |
|
6706 |
||
6707 |
// estimate size of buffer - assume every 4th char is a separator |
|
6708 |
bufLen = (sepLen == 1) ? len : (len + ((len/4) + 1) * sepLen); |
|
6709 |
buf = (char *)malloc(bufLen); |
|
6710 |
if (buf == NULL) { |
|
6711 |
error = __mkSmallInteger(ENOMEM); |
|
6712 |
goto out; |
|
6713 |
} |
|
6714 |
||
6715 |
endBuf = buf + bufLen; |
|
6716 |
||
6717 |
for (sp = stringP, dp = buf; sp < end; sp++) { |
|
6718 |
char c; |
|
6719 |
||
6720 |
if ((dp+sepLen) >= endBuf) { |
|
6721 |
char *newBuf; |
|
6722 |
||
6723 |
bufLen = bufLen * 2; |
|
6724 |
newBuf = (char *)realloc(buf, bufLen); |
|
6725 |
if (newBuf == NULL) { |
|
6726 |
free(buf); |
|
6727 |
error = __mkSmallInteger(ENOMEM); |
|
6728 |
goto out; |
|
6729 |
} |
|
6730 |
endBuf = newBuf + bufLen; |
|
6731 |
dp = newBuf + (dp-buf); |
|
6732 |
buf = newBuf; |
|
6733 |
} |
|
6734 |
||
6735 |
if ((c = *sp) == '\n') { |
|
6736 |
*dp++ = sep[0]; |
|
6737 |
if (sepLen == 2) { |
|
6738 |
*dp++ = sep[1]; |
|
6739 |
}; |
|
6740 |
} else { |
|
6741 |
*dp++ = c; |
|
6742 |
} |
|
6743 |
} |
|
6744 |
||
6745 |
len = dp - buf; |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6746 |
#ifdef __win32__ |
23743 | 6747 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6748 |
cnt = __win32_fwrite(buf, 1, len, f); |
|
6749 |
} else |
|
17420 | 6750 |
#endif |
23743 | 6751 |
{ |
6752 |
__WRITEBYTES__(cnt, f, buf, len, _buffered, __INST(handleType)); |
|
6753 |
} |
|
6754 |
free(buf); |
|
6755 |
} else { // No EOL conversion needed |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6756 |
#ifdef __win32__ |
23743 | 6757 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6758 |
cnt = __win32_fwrite(stringP, 1, len, f); |
|
6759 |
} else |
|
17420 | 6760 |
#endif |
23743 | 6761 |
{ |
6762 |
o_offs = (char *)__stringVal(aCollection)-(char *)__InstPtr(aCollection); |
|
6763 |
__WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs+iStart-1, len, _buffered, __INST(handleType)); |
|
6764 |
} |
|
6765 |
} |
|
6766 |
} else { // Not a string |
|
6767 |
if (__INST(binary) == true) { |
|
6768 |
int offs; |
|
6769 |
||
6770 |
if (__isByteArrayLike(aCollection)) { |
|
6771 |
offs = 0; |
|
6772 |
len = __byteArraySize(aCollection); |
|
6773 |
} else if (__isBytes(aCollection)) { |
|
6774 |
offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars)); |
|
6775 |
len = __byteArraySize(aCollection) - offs; |
|
6776 |
} else |
|
6777 |
goto out; |
|
6778 |
||
6779 |
if (iStop > len) { |
|
6780 |
RETURN(self); |
|
6781 |
} |
|
6782 |
if (iStop > len) |
|
6783 |
iStop = len; |
|
6784 |
len = iStop - iStart + 1; |
|
6785 |
offs += iStart - 1; |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6786 |
#ifdef __win32__ |
23743 | 6787 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6788 |
cnt = __win32_fwrite(__stringVal(aCollection)+iStart-1, 1, len, f); |
|
6789 |
} else |
|
17418 | 6790 |
#endif |
23743 | 6791 |
{ |
6792 |
o_offs = (char *)(__ByteArrayInstPtr(aCollection)->ba_element)-(char *)__InstPtr(aCollection); |
|
6793 |
__WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs+offs, len, _buffered, __INST(handleType)); |
|
6794 |
} |
|
6795 |
} else |
|
6796 |
goto out; |
|
6797 |
} |
|
6798 |
if (cnt == len) { |
|
6799 |
if (__isSmallInteger(__INST(position))) { |
|
6800 |
INT np = __intVal(__INST(position)) + len; |
|
6801 |
OBJ t; |
|
6802 |
||
6803 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
6804 |
} else { |
|
6805 |
__INST(position) = nil; /* i.e. do not know */ |
|
6806 |
} |
|
6807 |
RETURN (self); |
|
6808 |
} |
|
23538 | 6809 |
# ifdef __win32__ |
23743 | 6810 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 6811 |
# endif |
23743 | 6812 |
error = __mkSmallInteger(__threadErrno); |
6813 |
} |
|
17418 | 6814 |
} |
6815 |
out: ; |
|
6816 |
%}. |
|
6817 |
error notNil ifTrue:[ |
|
23743 | 6818 |
lastErrorNumber := error. |
6819 |
self writeError:error. |
|
6820 |
^ self |
|
17418 | 6821 |
]. |
23538 | 6822 |
super nextPutAll:aCollection startingAt:start to:stop |
6823 |
||
6824 |
"Modified: / 22-11-2018 / 12:52:13 / Stefan Vogel" |
|
17418 | 6825 |
! |
6826 |
||
6827 |
nextPutAllUnicode:aString |
|
6828 |
"normal streams can not handle multi-byte characters, so convert them to utf8. |
|
6829 |
This is needed, so that you can do ('something' asUnicode16String errorPrintCR)" |
|
6830 |
||
6831 |
aString do:[:eachCharacter| |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
6832 |
self nextPutUtf8:eachCharacter. |
17418 | 6833 |
]. |
6834 |
||
6835 |
" |
|
23934 | 6836 |
'Bönnigheim' asUnicode16String errorPrintCR |
17418 | 6837 |
" |
6838 |
! |
|
6839 |
||
17608 | 6840 |
nextPutBytes:count from:anObject startingAt:start |
6841 |
"write count bytes from an object starting at index start. |
|
6842 |
return the number of bytes written - which could be 0. |
|
6843 |
The object must have non-pointer indexed instvars |
|
6844 |
(i.e. be a ByteArray, String, Float- or DoubleArray), |
|
6845 |
or an externalBytes object (with known size). |
|
6846 |
||
6847 |
Use with care - non object oriented i/o. |
|
6848 |
Warning: |
|
23743 | 6849 |
in general, you cannot use this method to pass non-byte data to other |
6850 |
architectures (unless you prepared the buffer with care), |
|
6851 |
since it does not care for byte order or float representation." |
|
17608 | 6852 |
|
6853 |
|error| |
|
6854 |
||
6855 |
%{ |
|
18312 | 6856 |
#ifdef __SCHTEAM__ |
6857 |
byte[] bytes; |
|
6858 |
STObject handle = self.instVarAt(I_handle); |
|
6859 |
||
6860 |
if (anObject.isSTString()) { |
|
23743 | 6861 |
char[] chars = anObject.asSTString().characters; |
6862 |
handle.writeCharacters(chars, start.intValue()-1, count.intValue()); |
|
6863 |
self.instVarAt_put(I_position, STObject.Nil); |
|
6864 |
return context._RETURN(count); |
|
18364 | 6865 |
} |
6866 |
if (anObject.isSymbol()) { |
|
23743 | 6867 |
java.lang.String chars = anObject.asSTSymbol().characters; |
6868 |
handle.writeString(chars, start.intValue()-1, count.intValue()); |
|
6869 |
self.instVarAt_put(I_position, STObject.Nil); |
|
6870 |
return context._RETURN(count); |
|
18312 | 6871 |
} |
6872 |
#else |
|
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
6873 |
int ret; |
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
6874 |
int objSize, nInstBytes; |
17608 | 6875 |
char *extPtr; |
6876 |
OBJ fp; |
|
6877 |
||
6878 |
__INST(lastErrorNumber) = nil; |
|
6879 |
if ((__INST(handleType) == nil) |
|
6880 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
6881 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
6882 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
6883 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
23743 | 6884 |
if (((fp = __INST(handle)) != nil) |
6885 |
&& (__INST(mode) != @symbol(readonly)) |
|
6886 |
&& __bothSmallInteger(count, start) |
|
6887 |
) { |
|
6888 |
int _buffered = (__INST(buffered) == true); |
|
6889 |
FILEPOINTER f = __FILEVal(fp); |
|
6890 |
int len = __intVal(count); |
|
6891 |
int offs = __intVal(start) - 1; |
|
6892 |
||
6893 |
if (__isExternalBytesLike(anObject)) { |
|
6894 |
OBJ sz; |
|
6895 |
||
6896 |
nInstBytes = 0; |
|
6897 |
extPtr = (char *)__externalBytesAddress(anObject); |
|
6898 |
if (extPtr == NULL) goto bad; |
|
6899 |
sz = __externalBytesSize(anObject); |
|
6900 |
if (__isSmallInteger(sz)) { |
|
6901 |
objSize = __intVal(sz); |
|
6902 |
} else { |
|
6903 |
objSize = 0; /* unknown */ |
|
6904 |
} |
|
6905 |
} else { |
|
6906 |
OBJ oClass = __Class(anObject); |
|
6907 |
int nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
6908 |
||
6909 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
6910 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
|
6911 |
case BYTEARRAY: |
|
6912 |
case WORDARRAY: |
|
6913 |
case LONGARRAY: |
|
6914 |
case SWORDARRAY: |
|
6915 |
case SLONGARRAY: |
|
6916 |
case FLOATARRAY: |
|
6917 |
break; |
|
6918 |
case DOUBLEARRAY: |
|
18312 | 6919 |
# ifdef __NEED_DOUBLE_ALIGN |
23743 | 6920 |
nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1); |
18312 | 6921 |
# endif |
23743 | 6922 |
break; |
6923 |
case LONGLONGARRAY: |
|
6924 |
case SLONGLONGARRAY: |
|
18312 | 6925 |
# ifdef __NEED_LONGLONG_ALIGN |
23743 | 6926 |
nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1); |
18312 | 6927 |
# endif |
23743 | 6928 |
break; |
6929 |
default: |
|
6930 |
goto bad; |
|
6931 |
} |
|
6932 |
extPtr = (char *)0; |
|
6933 |
objSize = __Size(anObject) - nInstBytes; |
|
6934 |
} |
|
6935 |
if ( (offs >= 0) && (len >= 0) && (objSize >= (len + offs)) ) { |
|
6936 |
int cnt; |
|
6937 |
||
6938 |
if (_buffered) { |
|
6939 |
__WRITING__(f) |
|
6940 |
} |
|
6941 |
||
6942 |
if (extPtr) { |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6943 |
# ifdef __win32__ |
23743 | 6944 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6945 |
cnt = __win32_fwrite(extPtr+offs, 1, len, f); |
|
6946 |
} else |
|
18312 | 6947 |
# endif |
23743 | 6948 |
{ |
6949 |
__WRITEBYTES__(cnt, f, extPtr+offs, len, _buffered, __INST(handleType)); |
|
6950 |
} |
|
6951 |
} else { |
|
6952 |
/* |
|
6953 |
* on interrupt, anObject may be moved to another location. |
|
6954 |
* So we pass anObject, and the offset to the __WRITEBYTES_OBJ__ macro. |
|
6955 |
*/ |
|
6956 |
offs += nInstBytes; |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6957 |
# ifdef __win32__ |
23743 | 6958 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6959 |
cnt = __win32_fwrite((char *)anObject+offs, 1, len, f); |
|
6960 |
} else |
|
18312 | 6961 |
# endif |
23743 | 6962 |
{ |
6963 |
__WRITEBYTES_OBJ__(cnt, f, anObject, offs, len, _buffered, __INST(handleType)); |
|
6964 |
} |
|
6965 |
} |
|
6966 |
||
6967 |
if (cnt >= 0) { |
|
6968 |
if (__isSmallInteger(__INST(position))) { |
|
6969 |
INT np = __intVal(__INST(position)) + cnt; |
|
6970 |
OBJ t; |
|
6971 |
||
6972 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
6973 |
} else { |
|
6974 |
__INST(position) = nil; /* i.e. do not know */ |
|
6975 |
} |
|
6976 |
RETURN ( __mkSmallInteger(cnt) ); |
|
6977 |
} else /* cnt < 0 */ { |
|
6978 |
if ( |
|
18312 | 6979 |
# ifdef EWOULDBLOCK |
23743 | 6980 |
(__threadErrno == EWOULDBLOCK) || |
18312 | 6981 |
# endif |
23743 | 6982 |
(__threadErrno == EAGAIN) |
6983 |
) { |
|
6984 |
RETURN ( __mkSmallInteger(0) ); |
|
6985 |
} |
|
6986 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 6987 |
# ifdef __win32__ |
23743 | 6988 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 6989 |
# endif |
23743 | 6990 |
error = __mkSmallInteger(__threadErrno); |
6991 |
} |
|
6992 |
} |
|
6993 |
} |
|
17608 | 6994 |
} |
6995 |
bad: ; |
|
18312 | 6996 |
#endif /* not SCHTEAM */ |
17608 | 6997 |
%}. |
6998 |
error notNil ifTrue:[ |
|
23743 | 6999 |
lastErrorNumber := error. |
7000 |
self writeError:error. |
|
7001 |
^ 0 |
|
17608 | 7002 |
]. |
17634 | 7003 |
handle isNil ifTrue:[self errorNotOpen. ^ 0]. |
7004 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ 0]. |
|
7005 |
self primitiveFailed. |
|
7006 |
^ 0. |
|
23538 | 7007 |
|
7008 |
"Modified: / 22-11-2018 / 14:47:58 / Stefan Vogel" |
|
17608 | 7009 |
! |
7010 |
||
17418 | 7011 |
nextPutUnicode:aCharacter |
7012 |
"normal streams can not handle multi-byte characters, so convert them to utf8" |
|
7013 |
||
7014 |
self nextPutUtf8:aCharacter. |
|
612 | 7015 |
! ! |
7016 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
7017 |
!ExternalStream class methodsFor:'documentation'! |
730 | 7018 |
|
7019 |
version |
|
18636 | 7020 |
^ '$Header$' |
12398 | 7021 |
! |
7022 |
||
7023 |
version_CVS |
|
18636 | 7024 |
^ '$Header$' |
730 | 7025 |
! ! |
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6758
diff
changeset
|
7026 |
|
14603 | 7027 |
|
612 | 7028 |
ExternalStream initialize! |