author | Stefan Vogel <sv@exept.de> |
Tue, 28 Apr 2020 16:22:44 +0200 | |
changeset 25376 | 88a3329875ba |
parent 25317 | 245086b1bfe6 |
permissions | -rw-r--r-- |
25134 | 1 |
"{ Encoding: utf8 }" |
2 |
||
1 | 3 |
" |
5 | 4 |
COPYRIGHT (c) 1988 by Claus Gittinger |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5 |
All Rights Reserved |
1 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
5414 | 14 |
"{ Package: 'stx:libbasic' }" |
15 |
||
17418 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
1 | 18 |
ReadWriteStream subclass:#ExternalStream |
22848 | 19 |
instanceVariableNames:'handleType handle mode buffered binary eolMode hitEOF didWrite |
23744 | 20 |
lastErrorNumber readAhead dependents' |
22848 | 21 |
classVariableNames:'Lobby LastErrorNumber InvalidReadSignal InvalidWriteSignal |
22 |
InvalidModeSignal OpenErrorSignal StreamNotOpenSignal |
|
23 |
InvalidOperationSignal DefaultEOLMode ReadMode ReadWriteMode |
|
24 |
WriteMode AppendMode CreateReadWriteMode StreamIOErrorSignal |
|
25 |
FileOpenTrace MaxNonTenurableExecutors DefaultCopyBufferSize' |
|
26 |
poolDictionaries:'' |
|
27 |
category:'Streams-External' |
|
1 | 28 |
! |
29 |
||
216 | 30 |
!ExternalStream primitiveDefinitions! |
1 | 31 |
%{ |
10328
ad731a7584a3
ensure that win32_fwrite is used for stdout and stderr
Claus Gittinger <cg@exept.de>
parents:
9053
diff
changeset
|
32 |
#undef fwrite |
ad731a7584a3
ensure that win32_fwrite is used for stdout and stderr
Claus Gittinger <cg@exept.de>
parents:
9053
diff
changeset
|
33 |
|
17078 | 34 |
#include "stxOSDefs.h" |
35 |
||
1 | 36 |
#include <stdio.h> |
437 | 37 |
#define _STDIO_H_INCLUDED_ |
38 |
||
2903 | 39 |
#ifndef NO_FCNTL_H |
40 |
# include <fcntl.h> |
|
41 |
# define _FCNTL_H_INCLUDED_ |
|
42 |
#endif |
|
437 | 43 |
|
10 | 44 |
#include <errno.h> |
437 | 45 |
#define _ERRNO_H_INCLUDED_ |
42 | 46 |
|
1141 | 47 |
#ifdef LINUX |
48 |
/* use inline string macros */ |
|
49 |
# define __STRINGDEFS__ |
|
50 |
# include <linuxIntern.h> |
|
51 |
#endif |
|
52 |
||
16508 | 53 |
#if !defined(MSDOS_LIKE) && !defined(__openVMS__) |
54 |
# include <termios.h> |
|
55 |
#endif |
|
56 |
||
42 | 57 |
#ifdef hpux |
58 |
# define fileno(f) ((f->__fileH << 8) | (f->__fileL)) |
|
59 |
#endif |
|
216 | 60 |
|
933
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
61 |
#ifndef SEEK_SET |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
62 |
# define SEEK_SET 0 |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
63 |
#endif |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
64 |
#ifndef SEEK_CUR |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
65 |
# define SEEK_CUR 1 |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
66 |
#endif |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
67 |
#ifndef SEEK_END |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
68 |
# define SEEK_END 2 |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
69 |
#endif |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
70 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
71 |
#if defined(__VMS__) || defined(__sparc__) || defined(__win32__) |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
5101
diff
changeset
|
72 |
# define CLEAR_ERRNO __threadErrno = 0; |
2961 | 73 |
#else |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
74 |
# define CLEAR_ERRNO /* nothing */ |
2961 | 75 |
#endif |
76 |
||
3420 | 77 |
#ifdef LATER |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
78 |
# define __isFilePointer(x) (__Class(x) == ExternalStream__FilePointer) |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
79 |
# define __CHANGECLASS(o, x) (__qClass(o) = (x), o) |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
80 |
# define __MKFILEPOINTER(f) __CHANGECLASS(__MKEXTERNALADDRESS(f), ExternalStream__FilePointer) |
3420 | 81 |
#else |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
82 |
# define __MKFILEPOINTER(f) __MKEXTERNALADDRESS(f) |
3420 | 83 |
#endif |
84 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
85 |
#ifdef __win32__ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
86 |
# define NO_STDIO |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
87 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
88 |
# undef __HANDLE_INTERRUPTS__ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
89 |
# define __HANDLE_INTERRUPTS__ /* nothing */ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
90 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
91 |
# undef __BEGIN_INTERRUPTABLE__ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
92 |
# define __BEGIN_INTERRUPTABLE__ /* nothing */ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
93 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
94 |
# undef __END_INTERRUPTABLE__ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
95 |
# define __END_INTERRUPTABLE__ /* nothing */ |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
96 |
#endif |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
97 |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
98 |
# ifdef __i386__ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
99 |
# define _X86_ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
100 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
101 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
102 |
#ifdef __win32__ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
103 |
# undef INT |
14644 | 104 |
# undef UINT |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
105 |
# undef Array |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
106 |
# undef Number |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
107 |
# undef Method |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
108 |
# undef Point |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
109 |
# undef Rectangle |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
110 |
# undef Block |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
111 |
# undef Time |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
112 |
# undef Date |
7832 | 113 |
# undef Delay |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
114 |
# undef Set |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
115 |
# undef Signal |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
116 |
# undef Context |
9023 | 117 |
# undef Message |
9024 | 118 |
# undef Process |
10339 | 119 |
# undef Processor |
14632 | 120 |
# undef String |
121 |
# undef Character |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
122 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
123 |
# define NOATOM |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
124 |
# define NOGDICAPMASKS |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
125 |
# define NOMETAFILE |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
126 |
# define NOMINMAX |
14068 | 127 |
//# define NOOPENFILE |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
128 |
# define NOSOUND |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
129 |
# define NOWH |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
130 |
//# define NOCOMM |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
131 |
# define NOKANJI |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
132 |
# define NOCRYPT |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
133 |
//# define NOMCX |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
134 |
# define WIN32_LEAN_AND_MEAN |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
135 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
136 |
# include <windows.h> |
15435
fc902ce16af0
typecasts in printf for 64bit
Claus Gittinger <cg@exept.de>
parents:
15361
diff
changeset
|
137 |
# include <winsock2.h> |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
138 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
139 |
# ifdef __DEF_Array |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
140 |
# define Array __DEF_Array |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
141 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
142 |
# ifdef __DEF_Number |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
143 |
# define Number __DEF_Number |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
144 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
145 |
# ifdef __DEF_Method |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
146 |
# define Method __DEF_Method |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
147 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
148 |
# ifdef __DEF_Point |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
149 |
# define Point __DEF_Point |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
150 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
151 |
# ifdef __DEF_Block |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
152 |
# define Block __DEF_Block |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
153 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
154 |
# ifdef __DEF_Time |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
155 |
# define Time __DEF_Time |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
156 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
157 |
# ifdef __DEF_Date |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
158 |
# define Date __DEF_Date |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
159 |
# endif |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
160 |
# ifdef __DEF_Set |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
161 |
# define Set __DEF_Set |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
162 |
# endif |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
163 |
# ifdef __DEF_Signal |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
164 |
# define Signal __DEF_Signal |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
165 |
# endif |
7832 | 166 |
# ifdef __DEF_Delay |
167 |
# define Delay __DEF_Delay |
|
168 |
# endif |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
169 |
# ifdef __DEF_Context |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
170 |
# define Context __DEF_Context |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
171 |
# endif |
9023 | 172 |
# ifdef __DEF_Message |
173 |
# define Message __DEF_Message |
|
174 |
# endif |
|
9024 | 175 |
# ifdef __DEF_Process |
176 |
# define Process __DEF_Process |
|
177 |
# endif |
|
10339 | 178 |
# ifdef __DEF_Processor |
179 |
# define Processor __DEF_Processor |
|
180 |
# endif |
|
14632 | 181 |
# ifdef __DEF_String |
182 |
# define String __DEF_String |
|
183 |
# endif |
|
184 |
# ifdef __DEF_Character |
|
185 |
# define Character __DEF_Character |
|
186 |
# endif |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
187 |
|
14644 | 188 |
# define INT STX_INT |
189 |
# define UINT STX_UINT |
|
190 |
# ifndef off_t |
|
191 |
# define off_t long |
|
192 |
# endif |
|
23110 | 193 |
|
23111 | 194 |
size_t __win32_fwrite(char *, size_t , size_t , FILE *); |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
195 |
#endif /* __win32__ */ |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
196 |
|
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
197 |
#ifndef NO_STDIO /* use STDIO */ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
198 |
# define STDIO_NEEDS_FSEEK |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
199 |
# define FILEPOINTER FILE * |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
200 |
# define READ(f, cp, n) read(f, cp, n) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
201 |
# define WRITE(f, cp, n) write(f, cp, n) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
202 |
# define FFLUSH(fp) fflush(fp) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
203 |
# define FILENO(f) fileno(f) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
204 |
#endif /* use STDIO */ |
3681 | 205 |
|
3682 | 206 |
#ifdef DEBUGGING |
4092 | 207 |
extern char *__survStartPtr, *__survEndPtr; |
3682 | 208 |
# define DEBUGBUFFER(buf) \ |
3681 | 209 |
if (((char *)(buf) >= __survStartPtr) \ |
210 |
&& ((char *)(buf) < __survEndPtr)) { \ |
|
23743 | 211 |
__fatal0("read into survivor\n"); \ |
3681 | 212 |
} |
213 |
||
3682 | 214 |
#else |
215 |
# define DEBUGBUFFER(buf) /* nothing */ |
|
216 |
#endif |
|
217 |
||
216 | 218 |
/* |
219 |
* stdio library requires an fseek before reading whenever a file |
|
220 |
* is open for read/write and the last operation was a write. |
|
221 |
* (also vice-versa). |
|
222 |
* All code should use the following macro before doing reads: |
|
223 |
*/ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
224 |
#ifdef STDIO_NEEDS_FSEEK |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
225 |
# define OPT_FSEEK(f, pos, whence) fseek(f, pos, whence) |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
226 |
#else |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
227 |
# define OPT_FSEEK(f, pos, whence) /* nothing */ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
228 |
#endif |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
229 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
230 |
#ifdef __win32__ |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
231 |
# define READ(ret, f, cp, n, handleType) { \ |
23743 | 232 |
if (handleType == @symbol(socketHandle)) { \ |
233 |
(ret) = __STX_WSA_NOINT_CALL4("recv", recv, (f), (cp), (n), 0); \ |
|
234 |
} else { \ |
|
235 |
HANDLE h = _get_osfhandle(fileno(f)); \ |
|
236 |
if (handleType == @symbol(socketFilePointer)) { \ |
|
237 |
(ret) = __STX_WSA_NOINT_CALL4("recv", recv, h, (cp), (n), 0);\ |
|
238 |
} else { \ |
|
239 |
int __res; \ |
|
240 |
(ret) = __STX_API_NOINT_CALL5("ReadFile", ReadFile, h, (cp), (n), &__res, 0);\ |
|
241 |
(ret) = (ret) > 0 ? __res : (__threadErrno == __WIN32_ERR(ERROR_BROKEN_PIPE) ? 0 : -1); \ |
|
242 |
} \ |
|
243 |
} \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
244 |
} |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
245 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
246 |
# define WRITE(ret, f, cp, n, handleType) { \ |
23743 | 247 |
if (handleType == @symbol(socketHandle)) { \ |
248 |
(ret) = __STX_WSA_NOINT_CALL4("send", send, (f), (cp), (n), 0); \ |
|
249 |
} else {\ |
|
250 |
HANDLE h = _get_osfhandle(fileno(f)); \ |
|
251 |
if (handleType == @symbol(socketFilePointer)) { \ |
|
252 |
(ret) = __STX_WSA_NOINT_CALL4("send", send, h, (cp), (n), 0);\ |
|
253 |
} else {\ |
|
254 |
int __res; \ |
|
255 |
(ret) = __STX_API_NOINT_CALL5("WriteFile", WriteFile, h, (cp), (n), &__res, 0);\ |
|
256 |
(ret) = (ret) ? __res : -1; \ |
|
257 |
} \ |
|
258 |
} \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
259 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
260 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
261 |
# define FFLUSH(fp) fflush(fp) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
262 |
# undef STDIO_NEEDS_FSEEK |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
263 |
# define FILEPOINTER FILE * |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
264 |
# define FILENO(f) fileno(f) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
265 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
266 |
# define __READING__(f) \ |
1133 | 267 |
if ((__INST(didWrite) != false) \ |
268 |
&& (__INST(mode) == @symbol(readwrite))) { \ |
|
23743 | 269 |
__INST(didWrite) = false; \ |
270 |
OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */ \ |
|
216 | 271 |
} |
272 |
||
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
273 |
# define __WRITING__(f) \ |
1133 | 274 |
if ((__INST(didWrite) != true) \ |
275 |
&& (__INST(mode) == @symbol(readwrite))) { \ |
|
23743 | 276 |
__INST(didWrite) = true; \ |
277 |
OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */ \ |
|
216 | 278 |
} |
279 |
||
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
280 |
# define __UNGETC__(c, f, isBuffered) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
281 |
if (isBuffered) { \ |
23743 | 282 |
ungetc((c), (f)); \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
283 |
} else { \ |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
284 |
__INST(readAhead) = __mkSmallInteger((c)); \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
285 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
286 |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
287 |
# define __READBYTE__(ret, f, buf, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
288 |
if (isBuffered) { \ |
23743 | 289 |
for (;;) { \ |
290 |
CLEAR_ERRNO; \ |
|
291 |
(ret) = getc(f); \ |
|
292 |
if ((ret) >= 0) { \ |
|
293 |
*(buf) = (ret); \ |
|
294 |
(ret) = 1; \ |
|
295 |
} else if (ferror(f)) { \ |
|
296 |
if (__threadErrno == EINTR) { \ |
|
297 |
clearerr(f); \ |
|
298 |
continue; \ |
|
299 |
} \ |
|
25142
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
300 |
(ret) = -1; \ |
23743 | 301 |
} else { \ |
302 |
(ret) = 0; \ |
|
303 |
} \ |
|
304 |
break; \ |
|
305 |
} \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
306 |
} else { \ |
23743 | 307 |
OBJ rA = __INST(readAhead); \ |
308 |
if (rA != nil) { \ |
|
309 |
*(buf) = (char)__intVal(rA); \ |
|
310 |
__INST(readAhead) = nil; \ |
|
311 |
(ret) = 1; \ |
|
312 |
} else { \ |
|
313 |
for (;;) { \ |
|
314 |
CLEAR_ERRNO; \ |
|
315 |
READ((ret), f, buf, 1, handleType); \ |
|
316 |
if ((ret) >= 0 || __threadErrno != EINTR) \ |
|
317 |
break; \ |
|
318 |
} \ |
|
319 |
} \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
320 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
321 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
322 |
/* |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
323 |
* read_bytes into a c-buffer |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
324 |
* (which may NOT move) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
325 |
*/ |
12548 | 326 |
# define __READBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
327 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
328 |
if (isBuffered) { \ |
23743 | 329 |
int __offs = 0; \ |
330 |
while (__offs < (cnt)) { \ |
|
331 |
CLEAR_ERRNO; \ |
|
332 |
(ret) = getc(f); \ |
|
333 |
if ((ret) < 0) { \ |
|
334 |
if (ferror(f)) { \ |
|
335 |
if (__threadErrno == EINTR) { \ |
|
336 |
clearerr(f); \ |
|
337 |
continue; \ |
|
338 |
} \ |
|
339 |
} else { \ |
|
340 |
(ret) = 0; \ |
|
341 |
} \ |
|
342 |
break; \ |
|
343 |
} \ |
|
344 |
(buf)[__offs++] = (ret); \ |
|
345 |
} \ |
|
346 |
if (__offs > 0) \ |
|
347 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
348 |
} else { \ |
23743 | 349 |
int __offs = 0; \ |
350 |
\ |
|
351 |
while (__offs < (cnt)) { \ |
|
352 |
OBJ rA = __INST(readAhead); \ |
|
353 |
if (rA != nil) { \ |
|
354 |
(buf)[__offs] = __intVal(rA); \ |
|
355 |
__INST(readAhead) = nil; \ |
|
356 |
(ret) = 1; \ |
|
357 |
} else { \ |
|
358 |
CLEAR_ERRNO; \ |
|
359 |
READ((ret), f, (buf)+__offs, (cnt)-__offs, handleType); \ |
|
360 |
if ((ret) <= 0) { \ |
|
361 |
if ((ret) < 0 && __threadErrno == EINTR) { \ |
|
362 |
continue; \ |
|
363 |
} \ |
|
364 |
break; \ |
|
365 |
} \ |
|
366 |
} \ |
|
367 |
__offs += (ret); \ |
|
368 |
} \ |
|
369 |
if (__offs > 0) \ |
|
370 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
371 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
372 |
|
12548 | 373 |
# define __READAVAILBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
374 |
{ \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
375 |
int __offs = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
376 |
int oldFlags; \ |
23743 | 377 |
\ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
378 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
379 |
if (isBuffered) { \ |
23743 | 380 |
while (__offs < (cnt)) { \ |
381 |
CLEAR_ERRNO; \ |
|
382 |
(ret) = getc(f); \ |
|
383 |
if ((ret) < 0) { \ |
|
384 |
if (ferror(f)) { \ |
|
385 |
if (__threadErrno == EINTR) { \ |
|
386 |
clearerr(f); \ |
|
387 |
continue; \ |
|
388 |
} \ |
|
389 |
} else { \ |
|
390 |
(ret) = 0; \ |
|
391 |
} \ |
|
392 |
break; \ |
|
393 |
} \ |
|
394 |
(buf)[__offs++] = (ret); \ |
|
395 |
} \ |
|
396 |
if (__offs > 0) \ |
|
397 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
398 |
} else { \ |
23743 | 399 |
while (__offs < (cnt)) { \ |
400 |
OBJ rA = __INST(readAhead); \ |
|
401 |
if (rA != nil) { \ |
|
402 |
(buf)[__offs] = __intVal(rA); \ |
|
403 |
__INST(readAhead) = nil; \ |
|
404 |
(ret) = 1; \ |
|
405 |
__offs ++; \ |
|
406 |
continue; \ |
|
407 |
} \ |
|
408 |
CLEAR_ERRNO; \ |
|
409 |
{ \ |
|
410 |
int res = -1, ok = 0; \ |
|
411 |
SOCKET sock = 0; \ |
|
412 |
if ((handleType == @symbol(socketFilePointer) && ((ok = ioctlsocket(sock = (SOCKET)_get_osfhandle(fileno(f)),FIONREAD,&res) == 0), 1)) \ |
|
413 |
|| (handleType == @symbol(socketHandle) && ((ok = ioctlsocket(sock = (SOCKET)(f), FIONREAD, &res) == 0), 1)) \ |
|
414 |
|| (handleType == @symbol(pipeFilePointer) && ((ok = PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0, 0,0,&res,0)), 1))) { \ |
|
415 |
if (!ok) { \ |
|
416 |
__threadErrno = sock ? WSAGetLastError() : __WIN32_ERR(GetLastError()); \ |
|
417 |
(ret) = __threadErrno == __WIN32_ERR(ERROR_BROKEN_PIPE) ? 0 : -1; \ |
|
418 |
break; \ |
|
419 |
} \ |
|
420 |
if (res > 0) { \ |
|
421 |
if (res > ((cnt)-__offs)) \ |
|
422 |
res = (cnt)-__offs; \ |
|
423 |
READ((ret), f, (buf)+__offs, res, handleType); \ |
|
424 |
} else { \ |
|
425 |
if (sock && send(sock, NULL, 0, 0) == SOCKET_ERROR) { \ |
|
426 |
(ret) = -1; __threadErrno = WSAGetLastError(); \ |
|
427 |
} else { \ |
|
428 |
(ret) = 0; \ |
|
429 |
} \ |
|
430 |
break; \ |
|
431 |
} \ |
|
432 |
} else { \ |
|
433 |
READ((ret), f, (buf)+__offs, (cnt)-__offs, handleType); \ |
|
434 |
} \ |
|
435 |
} \ |
|
436 |
if ((ret) <= 0) { \ |
|
437 |
if ((ret) < 0 && __threadErrno == EINTR)\ |
|
438 |
continue; \ |
|
439 |
break; \ |
|
440 |
} \ |
|
441 |
__offs += (ret); \ |
|
442 |
} \ |
|
443 |
if (__offs > 0) \ |
|
444 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
445 |
} \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
446 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
447 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
448 |
# define IO_BUFFER_SIZE (8*1024) |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
449 |
|
12548 | 450 |
# define __READBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
451 |
{ \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
452 |
int __ooffs = obj_offs; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
453 |
int __offs = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
454 |
char *buf = (char *)(obj); \ |
23743 | 455 |
\ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
456 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
457 |
if (isBuffered) { \ |
23743 | 458 |
while (__offs < (cnt)) { \ |
459 |
CLEAR_ERRNO; \ |
|
460 |
(ret) = getc(f); \ |
|
461 |
if ((ret) < 0) { \ |
|
462 |
if (ferror(f)) { \ |
|
463 |
if (__threadErrno == EINTR) { \ |
|
464 |
clearerr(f); \ |
|
465 |
/* refetch */ \ |
|
466 |
buf = (char *)(obj); \ |
|
467 |
continue; \ |
|
468 |
} \ |
|
469 |
} else { \ |
|
470 |
(ret) = 0; \ |
|
471 |
} \ |
|
472 |
break; \ |
|
473 |
} \ |
|
474 |
(buf)[__ooffs+__offs] = (ret); \ |
|
475 |
__offs++; \ |
|
476 |
} \ |
|
477 |
if (__offs > 0) \ |
|
478 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
479 |
} else { \ |
23743 | 480 |
while (__offs < (cnt)) { \ |
481 |
char __buf[IO_BUFFER_SIZE]; \ |
|
482 |
OBJ rA = __INST(readAhead); \ |
|
483 |
if (rA != nil) { \ |
|
484 |
(buf)[__ooffs+__offs] = __intVal(rA); \ |
|
485 |
__INST(readAhead) = nil; \ |
|
486 |
(ret) = 1; \ |
|
487 |
} else { \ |
|
488 |
int l; \ |
|
489 |
CLEAR_ERRNO; \ |
|
490 |
l = (cnt)-__offs; \ |
|
491 |
if ( l > IO_BUFFER_SIZE) \ |
|
492 |
l = IO_BUFFER_SIZE; \ |
|
493 |
READ((ret),f, __buf, l, handleType); \ |
|
494 |
if ((ret) <= 0) { \ |
|
495 |
if ((ret) < 0 && __threadErrno == EINTR) { \ |
|
496 |
continue; \ |
|
497 |
} \ |
|
498 |
break; \ |
|
499 |
} \ |
|
500 |
} \ |
|
501 |
if ((ret) > 0 ) { \ |
|
502 |
/* refetch */ \ |
|
503 |
buf = (char *)(obj); \ |
|
504 |
memcpy((buf)+__ooffs+__offs,__buf,(ret)); \ |
|
505 |
__offs += (ret); \ |
|
506 |
} else { \ |
|
507 |
(ret) = 0; \ |
|
508 |
} \ |
|
509 |
} \ |
|
510 |
if (__offs > 0) \ |
|
511 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
512 |
} \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
513 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
514 |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
515 |
# define __READAVAILBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
516 |
{ \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
517 |
int __ooffs = obj_offs; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
518 |
int __offs = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
519 |
char *buf = (char *)(obj); \ |
23743 | 520 |
\ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
521 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
522 |
if (isBuffered) { \ |
23743 | 523 |
while (__offs < (cnt)) { \ |
524 |
CLEAR_ERRNO; \ |
|
525 |
(ret) = getc(f); \ |
|
526 |
if ((ret) < 0) { \ |
|
527 |
if (ferror(f)) { \ |
|
528 |
if (__threadErrno == EINTR) { \ |
|
529 |
clearerr(f); \ |
|
530 |
/* refetch */ \ |
|
531 |
buf = (char *)(obj); \ |
|
532 |
continue; \ |
|
533 |
} \ |
|
534 |
} else { \ |
|
535 |
(ret) = 0; \ |
|
536 |
} \ |
|
537 |
break; \ |
|
538 |
} \ |
|
539 |
(buf)[__ooffs+__offs] = (ret); \ |
|
540 |
__offs++; \ |
|
541 |
} \ |
|
542 |
if (__offs > 0) \ |
|
543 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
544 |
} else { \ |
23743 | 545 |
while (__offs < (cnt)) { \ |
546 |
char __buf[IO_BUFFER_SIZE]; \ |
|
547 |
OBJ rA = __INST(readAhead); \ |
|
548 |
if (rA != nil) { \ |
|
549 |
(buf)[__ooffs+__offs] = __intVal(rA);\ |
|
550 |
__INST(readAhead) = nil; \ |
|
551 |
(ret) = 1; \ |
|
552 |
__offs++; \ |
|
553 |
continue; \ |
|
554 |
} \ |
|
555 |
{ \ |
|
556 |
int res = -1, ok = 0; \ |
|
557 |
SOCKET sock = 0; \ |
|
558 |
int l = (cnt)-__offs; \ |
|
559 |
CLEAR_ERRNO; \ |
|
560 |
if (l > IO_BUFFER_SIZE) l = IO_BUFFER_SIZE; \ |
|
561 |
if ((handleType == @symbol(socketFilePointer) && ((ok = ioctlsocket(sock = (SOCKET)_get_osfhandle(fileno(f)),FIONREAD,&res) == 0), 1)) \ |
|
562 |
|| (handleType == @symbol(socketHandle) && ((ok = ioctlsocket(sock = (SOCKET)(f), FIONREAD, &res) == 0), 1)) \ |
|
563 |
|| (handleType == @symbol(pipeFilePointer) && ((ok = PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0, 0,0,&res,0)), 1))) { \ |
|
564 |
if (!ok) { \ |
|
565 |
__threadErrno = sock ? WSAGetLastError() : __WIN32_ERR(GetLastError()); \ |
|
566 |
(ret) = __threadErrno == __WIN32_ERR(ERROR_BROKEN_PIPE) ? 0 : -1; \ |
|
567 |
break; \ |
|
568 |
} \ |
|
569 |
if (res > 0) { \ |
|
570 |
if (res > l) res = l; \ |
|
571 |
READ((ret), f, __buf, res, handleType); \ |
|
572 |
} else { \ |
|
573 |
if (sock && send(sock, NULL, 0, 0) == SOCKET_ERROR) { \ |
|
574 |
(ret) = -1; __threadErrno = WSAGetLastError(); \ |
|
575 |
} else { \ |
|
576 |
(ret) = 0; \ |
|
577 |
} \ |
|
578 |
break; \ |
|
579 |
} \ |
|
580 |
} else { \ |
|
581 |
READ((ret), f, __buf, l, handleType); \ |
|
582 |
} \ |
|
583 |
if ((ret) <= 0) { \ |
|
584 |
if ((ret) < 0 && __threadErrno == EINTR) \ |
|
585 |
continue; \ |
|
586 |
break; \ |
|
587 |
} \ |
|
588 |
} \ |
|
589 |
if ((ret) > 0) { \ |
|
590 |
buf = (char *)(obj); \ |
|
591 |
memcpy((buf)+__ooffs+__offs, __buf, (ret)); \ |
|
592 |
__offs += (ret); \ |
|
593 |
} else { \ |
|
594 |
(ret) = 0; \ |
|
595 |
} \ |
|
596 |
} \ |
|
597 |
if (__offs > 0) \ |
|
598 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
599 |
} \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
600 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
601 |
|
12548 | 602 |
# define __WRITEBYTE__(ret, f, buf, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
603 |
if (isBuffered) { \ |
23743 | 604 |
for (;;) { \ |
605 |
CLEAR_ERRNO; \ |
|
606 |
ret = putc(*(buf), f); \ |
|
607 |
if ((ret) >= 0) { \ |
|
608 |
(ret) = 1; \ |
|
609 |
} else if (ferror(f)) { \ |
|
610 |
if (__threadErrno == EINTR) { \ |
|
611 |
clearerr(f); \ |
|
612 |
continue; \ |
|
613 |
} \ |
|
614 |
} else \ |
|
615 |
(ret) = 0; \ |
|
616 |
break; \ |
|
617 |
} \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
618 |
} else { \ |
23743 | 619 |
for (;;) { \ |
620 |
CLEAR_ERRNO; \ |
|
621 |
WRITE(ret,f, buf, 1, handleType); \ |
|
622 |
if ((ret) >= 0 || __threadErrno != EINTR) \ |
|
623 |
break; \ |
|
624 |
} \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
625 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
626 |
|
12548 | 627 |
# define __WRITEBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
628 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
629 |
if (isBuffered) { \ |
23743 | 630 |
int __offs = 0; \ |
631 |
while (__offs < (cnt)) { \ |
|
632 |
CLEAR_ERRNO; \ |
|
633 |
(ret) = fwrite((buf)+__offs, 1, (cnt)-__offs, f);\ |
|
634 |
if ((ret) <= 0) { \ |
|
635 |
if (ferror(f)) { \ |
|
636 |
if (__threadErrno == EINTR) { \ |
|
637 |
clearerr(f); \ |
|
638 |
continue; \ |
|
639 |
} \ |
|
25142
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
640 |
(ret) = -1; \ |
23743 | 641 |
break; \ |
642 |
} else { \ |
|
643 |
(ret) = 0; \ |
|
644 |
} \ |
|
645 |
} \ |
|
646 |
__offs += (ret); \ |
|
647 |
} \ |
|
648 |
if (__offs > 0) \ |
|
649 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
650 |
} else { \ |
23743 | 651 |
int __offs = 0; \ |
652 |
while (__offs < (cnt)) { \ |
|
653 |
CLEAR_ERRNO; \ |
|
654 |
WRITE((ret),f, (buf)+__offs, (cnt)-__offs, handleType); \ |
|
655 |
if ((ret) <= 0) { \ |
|
656 |
if ((ret) < 0 && __threadErrno == EINTR) { \ |
|
657 |
continue; \ |
|
658 |
} \ |
|
659 |
break; \ |
|
660 |
} \ |
|
661 |
__offs += (ret); \ |
|
662 |
} \ |
|
663 |
if (__offs > 0) \ |
|
664 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
665 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
666 |
|
12548 | 667 |
# define __WRITEBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered, handleType) \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
668 |
{ \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
669 |
int __ooffs = obj_offs; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
670 |
int __offs = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
671 |
char *buf = (char *)(obj); \ |
23743 | 672 |
\ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
673 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
674 |
if (isBuffered) { \ |
23743 | 675 |
while (__offs < (cnt)) { \ |
676 |
CLEAR_ERRNO; \ |
|
677 |
ret = fwrite((buf)+__ooffs+__offs, 1, (cnt)-__offs, f); \ |
|
678 |
if ((ret) <= 0) { \ |
|
679 |
if (ferror(f)) { \ |
|
680 |
if (__threadErrno == EINTR) { \ |
|
681 |
/* refetch */ \ |
|
682 |
buf = (char *)(obj); \ |
|
683 |
clearerr(f); \ |
|
684 |
continue; \ |
|
685 |
} \ |
|
25142
bd49177015de
error returns from WRITE macros
Claus Gittinger <cg@exept.de>
parents:
25136
diff
changeset
|
686 |
(ret) = -1; \ |
23743 | 687 |
break; \ |
688 |
} else { \ |
|
689 |
(ret) = 0; \ |
|
690 |
} \ |
|
691 |
} \ |
|
692 |
__offs += (ret); \ |
|
693 |
} \ |
|
694 |
if (__offs > 0) \ |
|
695 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
696 |
} else { \ |
23743 | 697 |
while (__offs < (cnt)) { \ |
698 |
char __buf[IO_BUFFER_SIZE]; \ |
|
699 |
int l; \ |
|
700 |
CLEAR_ERRNO; \ |
|
701 |
l = (cnt)-__offs; \ |
|
702 |
if ( l > IO_BUFFER_SIZE) \ |
|
703 |
l = IO_BUFFER_SIZE; \ |
|
704 |
/* refetch */ \ |
|
705 |
buf = (char *)(obj); \ |
|
706 |
memcpy(__buf,(buf)+__ooffs+__offs,l); \ |
|
707 |
WRITE(ret,f, __buf, l, handleType); \ |
|
708 |
if ((ret) <= 0) { \ |
|
709 |
if ((ret) < 0 && __threadErrno == EINTR) { \ |
|
710 |
continue; \ |
|
711 |
} \ |
|
712 |
break; \ |
|
713 |
} \ |
|
714 |
__offs += (ret); \ |
|
715 |
} \ |
|
716 |
if (__offs > 0) \ |
|
717 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
718 |
} \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
719 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
720 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
721 |
#else /* ! __win32__ */ |
16296 | 722 |
/* ======================== UNIX / LINUX ====================================================== */ |
16373
9b9827530bf4
Adapt previous change for linux
Stefan Vogel <sv@exept.de>
parents:
16368
diff
changeset
|
723 |
typedef int SOCKET; |
9b9827530bf4
Adapt previous change for linux
Stefan Vogel <sv@exept.de>
parents:
16368
diff
changeset
|
724 |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
725 |
# define __READING__(f) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
726 |
if ((__INST(didWrite) != false) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
727 |
&& (__INST(mode) == @symbol(readwrite))) { \ |
23743 | 728 |
__INST(didWrite) = false; \ |
729 |
OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */ \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
730 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
731 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
732 |
# define __WRITING__(f) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
733 |
if ((__INST(didWrite) != true) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
734 |
&& (__INST(mode) == @symbol(readwrite))) { \ |
23743 | 735 |
__INST(didWrite) = true; \ |
736 |
OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */ \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
737 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
738 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
739 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
740 |
# ifdef NO_STDIO |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
741 |
# define __UNGETC__(c, f, isBuffered) \ |
8913 | 742 |
__INST(readAhead) = __mkSmallInteger((c)); |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
743 |
# else /* use STDIO */ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
744 |
# define __UNGETC__(c, f, isBuffered) \ |
2264 | 745 |
if (isBuffered) { \ |
23743 | 746 |
ungetc((c), (f)); \ |
2264 | 747 |
} else { \ |
23743 | 748 |
__INST(readAhead) = __mkSmallInteger((c)); \ |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
749 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
750 |
# endif /* use STDIO */ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
751 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
752 |
# ifdef NO_STDIO |
12548 | 753 |
# define __READBYTE__(ret, f, buf, isBuffered, handleType) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
754 |
{ \ |
23743 | 755 |
OBJ rA = __INST(readAhead); \ |
756 |
if (rA != nil) { \ |
|
757 |
*(buf) = __intVal(rA); \ |
|
758 |
DEBUGBUFFER(buf); \ |
|
759 |
__INST(readAhead) = nil; \ |
|
760 |
(ret) = 1; \ |
|
761 |
} else { \ |
|
762 |
for (;;) { \ |
|
763 |
CLEAR_ERRNO; \ |
|
764 |
(ret) = READ(f, buf, 1, handleType); \ |
|
765 |
DEBUGBUFFER(buf); \ |
|
766 |
if ((ret) >= 0) break; \ |
|
767 |
if (errno != EINTR) { \ |
|
768 |
break; \ |
|
769 |
} \ |
|
770 |
__HANDLE_INTERRUPTS__; \ |
|
771 |
} \ |
|
772 |
} \ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
773 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
774 |
# else /* use STDIO */ |
12548 | 775 |
# define __READBYTE__(ret, f, buf, isBuffered, handleType) \ |
2264 | 776 |
if (isBuffered) { \ |
23743 | 777 |
for (;;) { \ |
778 |
CLEAR_ERRNO; \ |
|
779 |
(ret) = getc(f); \ |
|
780 |
if ((ret) >= 0) { \ |
|
781 |
DEBUGBUFFER(buf); \ |
|
782 |
*(buf) = (ret); \ |
|
783 |
(ret) = 1; \ |
|
784 |
} else if (ferror(f)) { \ |
|
785 |
if (errno == EINTR) { \ |
|
786 |
__HANDLE_INTERRUPTS__; \ |
|
787 |
clearerr(f); \ |
|
788 |
continue; \ |
|
789 |
} \ |
|
790 |
} else \ |
|
791 |
(ret) = 0; \ |
|
792 |
break; \ |
|
793 |
} \ |
|
2264 | 794 |
} else { \ |
23743 | 795 |
OBJ rA = __INST(readAhead); \ |
796 |
if (rA != nil) { \ |
|
797 |
*(buf) = __intVal(rA); \ |
|
798 |
DEBUGBUFFER(buf); \ |
|
799 |
__INST(readAhead) = nil; \ |
|
800 |
(ret) = 1; \ |
|
801 |
} else { \ |
|
802 |
for (;;) { \ |
|
803 |
CLEAR_ERRNO; \ |
|
804 |
(ret) = read(fileno(f), buf, 1); \ |
|
805 |
DEBUGBUFFER(buf); \ |
|
806 |
if ((ret) >= 0) break; \ |
|
807 |
if (errno != EINTR) { \ |
|
808 |
break; \ |
|
809 |
} \ |
|
810 |
__HANDLE_INTERRUPTS__; \ |
|
811 |
} \ |
|
812 |
} \ |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
813 |
} |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
814 |
# endif /* use STDIO */ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
815 |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
816 |
/* |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
817 |
* read_bytes into a c-buffer |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
818 |
* (which may NOT move) |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
819 |
*/ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
820 |
# ifdef NO_STDIO |
12548 | 821 |
# define __READBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
822 |
{ \ |
23743 | 823 |
int __offs = 0, __cnt; \ |
824 |
\ |
|
825 |
while (__offs < (cnt)) { \ |
|
826 |
OBJ rA = __INST(readAhead); \ |
|
827 |
if (rA != nil) { \ |
|
828 |
(buf)[__offs] = __intVal(rA); \ |
|
829 |
DEBUGBUFFER(buf); \ |
|
830 |
__INST(readAhead) = nil; \ |
|
831 |
__offs++; \ |
|
832 |
} else { \ |
|
833 |
CLEAR_ERRNO; \ |
|
834 |
__cnt = READ(f, (buf)+__offs, (cnt)-__offs, handleType); \ |
|
835 |
DEBUGBUFFER(buf); \ |
|
836 |
if (__cnt <= 0) { \ |
|
837 |
if (__cnt < 0 && errno == EINTR) { \ |
|
838 |
__HANDLE_INTERRUPTS__; \ |
|
839 |
continue; \ |
|
840 |
} \ |
|
841 |
break; \ |
|
842 |
} \ |
|
843 |
__offs += __cnt; \ |
|
844 |
} \ |
|
845 |
} \ |
|
846 |
if (__offs > 0) \ |
|
847 |
(ret) = __offs; \ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
848 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
849 |
# else /* use STDIO */ |
12548 | 850 |
# define __READBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
851 |
(ret) = 0; \ |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
852 |
if (isBuffered) { \ |
23743 | 853 |
int __offs = 0; \ |
854 |
while (__offs < (cnt)) { \ |
|
855 |
CLEAR_ERRNO; \ |
|
856 |
(ret) = getc(f); \ |
|
857 |
if ((ret) < 0) { \ |
|
858 |
if (ferror(f)) { \ |
|
859 |
if (errno == EINTR) { \ |
|
860 |
__HANDLE_INTERRUPTS__; \ |
|
861 |
clearerr(f); \ |
|
862 |
continue; \ |
|
863 |
} \ |
|
864 |
} else { \ |
|
865 |
(ret) = 0; \ |
|
866 |
} \ |
|
867 |
break; \ |
|
868 |
} \ |
|
869 |
DEBUGBUFFER(buf); \ |
|
870 |
(buf)[__offs++] = (ret); \ |
|
871 |
} \ |
|
872 |
if (__offs > 0) \ |
|
873 |
(ret) = __offs; \ |
|
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
874 |
} else { \ |
23743 | 875 |
int __offs = 0, __cnt; \ |
876 |
int fd = fileno(f); \ |
|
877 |
\ |
|
878 |
while (__offs < (cnt)) { \ |
|
879 |
OBJ rA = __INST(readAhead); \ |
|
880 |
if (rA != nil) { \ |
|
881 |
DEBUGBUFFER(buf); \ |
|
882 |
(buf)[__offs] = __intVal(rA); \ |
|
883 |
__INST(readAhead) = nil; \ |
|
884 |
__offs++; \ |
|
885 |
} else { \ |
|
886 |
CLEAR_ERRNO; \ |
|
887 |
__cnt = read(fd, (buf)+__offs, (cnt)-__offs); \ |
|
888 |
DEBUGBUFFER(buf); \ |
|
889 |
if (__cnt <= 0) { \ |
|
890 |
if (__cnt < 0 && errno == EINTR) { \ |
|
891 |
__HANDLE_INTERRUPTS__; \ |
|
892 |
continue; \ |
|
893 |
} \ |
|
894 |
break; \ |
|
895 |
} \ |
|
896 |
__offs += __cnt; \ |
|
897 |
} \ |
|
898 |
} \ |
|
899 |
if (__offs > 0) \ |
|
900 |
(ret) = __offs; \ |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
901 |
} |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
902 |
|
6563
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
903 |
|
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
904 |
/* |
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
905 |
* FNDELAY and O_NDELAY is deprecated, O_NONBLOCK is used in POSIX, XPG, etc... |
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
906 |
*/ |
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
907 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
908 |
# if defined(F_GETFL) && defined(F_SETFL) && (defined(O_NONBLOCK) || defined(O_NDELAY) || defined(FNDELAY)) |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
909 |
# define SETFLAGS(fd, flags) \ |
23743 | 910 |
fcntl(fd, F_SETFL, flags) |
6563
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
911 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
912 |
# if defined(O_NONBLOCK) |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
913 |
# define __STX_NONBLOCK_FLAG O_NONBLOCK |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
914 |
# else |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
915 |
# if defined(O_NDELAY) |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
916 |
# define __STX_NONBLOCK_FLAG O_NDELAY |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
917 |
# else |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
918 |
# define __STX_NONBLOCK_FLAG FNDELAY |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
919 |
# endif |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
920 |
# endif |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
921 |
|
15342 | 922 |
# define SETNONBLOCKING(fd, oldFlags) \ |
23743 | 923 |
{ \ |
924 |
int flags = fcntl(fd, F_GETFL, 0); \ |
|
925 |
if (flags >= 0) { \ |
|
926 |
fcntl(fd, F_SETFL, flags | __STX_NONBLOCK_FLAG); \ |
|
927 |
} \ |
|
928 |
oldFlags = flags; \ |
|
929 |
} |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
930 |
# else |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
931 |
# define SETFLAGS(fd, flags) /* nothing */ |
15342 | 932 |
# define SETNONBLOCKING(fd, oldFlags) /* nothing */ |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
933 |
# endif |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
934 |
|
12548 | 935 |
# define __READAVAILBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
936 |
{ \ |
15342 | 937 |
int __offs = 0, __cnt; \ |
3681 | 938 |
int oldFlags; \ |
23743 | 939 |
\ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
940 |
(ret) = 0; \ |
15342 | 941 |
SETNONBLOCKING(fileno(f), oldFlags); \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
942 |
if (isBuffered) { \ |
23743 | 943 |
while (__offs < (cnt)) { \ |
944 |
CLEAR_ERRNO; \ |
|
945 |
(ret) = getc(f); \ |
|
946 |
if ((ret) < 0) { \ |
|
947 |
if (ferror(f)) { \ |
|
948 |
if (errno == EINTR) { \ |
|
949 |
(ret) = 0; \ |
|
950 |
clearerr(f); \ |
|
951 |
break; \ |
|
952 |
} \ |
|
953 |
} else { \ |
|
954 |
(ret) = 0; \ |
|
955 |
} \ |
|
956 |
break; \ |
|
957 |
} \ |
|
958 |
(buf)[__offs++] = (ret); \ |
|
959 |
DEBUGBUFFER(buf); \ |
|
960 |
} \ |
|
961 |
if (__offs > 0) \ |
|
962 |
(ret) = __offs; \ |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
963 |
} else { \ |
23743 | 964 |
int fd = fileno(f); \ |
965 |
\ |
|
966 |
while (__offs < (cnt)) { \ |
|
967 |
OBJ rA = __INST(readAhead); \ |
|
968 |
if (rA != nil) { \ |
|
969 |
(buf)[__offs] = __intVal(rA); \ |
|
970 |
DEBUGBUFFER(buf); \ |
|
971 |
__INST(readAhead) = nil; \ |
|
972 |
__offs++; \ |
|
973 |
continue; \ |
|
974 |
} \ |
|
975 |
CLEAR_ERRNO; \ |
|
976 |
__cnt = read(fd, (buf)+__offs, (cnt)-__offs); \ |
|
977 |
DEBUGBUFFER(buf); \ |
|
978 |
if (__cnt > 0) { \ |
|
979 |
__offs += __cnt; \ |
|
980 |
} \ |
|
981 |
break; \ |
|
982 |
} \ |
|
983 |
if (__offs > 0) \ |
|
984 |
(ret) = __offs; \ |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
985 |
} \ |
3681 | 986 |
SETFLAGS(fileno(f), oldFlags); \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
987 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
988 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
989 |
# endif /* use STDIO */ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
990 |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
991 |
/* |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
992 |
* read_bytes into an object |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
993 |
* (which may be moved by GC) |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
994 |
*/ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
995 |
# ifdef NO_STDIO |
12548 | 996 |
# define __READBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered, handleType) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
997 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
998 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
999 |
int __offs = 0; \ |
7540
7cd542f29024
Fix reading when readAheadBuffer is filled and following read fails
Stefan Vogel <sv@exept.de>
parents:
7503
diff
changeset
|
1000 |
int __cnt; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1001 |
char *buf = (char *)(obj); \ |
23743 | 1002 |
\ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1003 |
(ret) = 0; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1004 |
{ \ |
23743 | 1005 |
while (__offs < (cnt)) { \ |
1006 |
OBJ rA = __INST(readAhead); \ |
|
1007 |
if (rA != nil) { \ |
|
1008 |
(buf)[__ooffs+__offs] = __intVal(rA); \ |
|
1009 |
DEBUGBUFFER(buf); \ |
|
1010 |
__INST(readAhead) = nil; \ |
|
1011 |
__offs++; \ |
|
1012 |
} else { \ |
|
1013 |
CLEAR_ERRNO; \ |
|
1014 |
__cnt = READ(f, (buf)+__ooffs+__offs, (cnt)-__offs, handleType); \ |
|
1015 |
DEBUGBUFFER(buf); \ |
|
1016 |
if (__cnt <= 0) { \ |
|
1017 |
if (__cnt < 0 && errno == EINTR) { \ |
|
1018 |
__HANDLE_INTERRUPTS__; \ |
|
1019 |
/* refetch */ \ |
|
1020 |
buf = (char *)(obj); \ |
|
1021 |
continue; \ |
|
1022 |
} \ |
|
1023 |
break; \ |
|
1024 |
} \ |
|
1025 |
__offs += __cnt; \ |
|
1026 |
} \ |
|
1027 |
} \ |
|
1028 |
if (__offs > 0) \ |
|
1029 |
(ret) = __offs; \ |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1030 |
} \ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1031 |
} |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
1032 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1033 |
# else /* use STDIO */ |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
1034 |
|
12548 | 1035 |
# define __READBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered, handleType) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1036 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1037 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1038 |
int __offs = 0; \ |
7540
7cd542f29024
Fix reading when readAheadBuffer is filled and following read fails
Stefan Vogel <sv@exept.de>
parents:
7503
diff
changeset
|
1039 |
int __cnt; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1040 |
char *buf = (char *)(obj); \ |
23743 | 1041 |
\ |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1042 |
(ret) = 0; \ |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1043 |
if (isBuffered) { \ |
23743 | 1044 |
while (__offs < (cnt)) { \ |
1045 |
CLEAR_ERRNO; \ |
|
1046 |
(ret) = getc(f); \ |
|
1047 |
if ((ret) < 0) { \ |
|
1048 |
if (ferror(f)) { \ |
|
1049 |
if (errno == EINTR) { \ |
|
1050 |
__HANDLE_INTERRUPTS__; \ |
|
1051 |
clearerr(f); \ |
|
1052 |
/* refetch */ \ |
|
1053 |
buf = (char *)(obj); \ |
|
1054 |
DEBUGBUFFER(buf); \ |
|
1055 |
continue; \ |
|
1056 |
} \ |
|
1057 |
} else { \ |
|
1058 |
(ret) = 0; \ |
|
1059 |
} \ |
|
1060 |
break; \ |
|
1061 |
} \ |
|
1062 |
(buf)[__ooffs+__offs] = (ret); \ |
|
1063 |
DEBUGBUFFER(buf); \ |
|
1064 |
__offs++; \ |
|
1065 |
} \ |
|
1066 |
if (__offs > 0) \ |
|
1067 |
(ret) = __offs; \ |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1068 |
} else { \ |
23743 | 1069 |
int fd = fileno(f); \ |
1070 |
\ |
|
1071 |
while (__offs < (cnt)) { \ |
|
1072 |
OBJ rA = __INST(readAhead); \ |
|
1073 |
if (rA != nil) { \ |
|
1074 |
(buf)[__ooffs+__offs] = __intVal(rA); \ |
|
1075 |
DEBUGBUFFER(buf); \ |
|
1076 |
__INST(readAhead) = nil; \ |
|
1077 |
__offs++; \ |
|
1078 |
} else { \ |
|
1079 |
CLEAR_ERRNO; \ |
|
1080 |
__cnt = read(fd, (buf)+__ooffs+__offs, (cnt)-__offs); \ |
|
1081 |
DEBUGBUFFER(buf); \ |
|
1082 |
if (__cnt <= 0) { \ |
|
1083 |
if (__cnt < 0 && errno == EINTR) { \ |
|
1084 |
__HANDLE_INTERRUPTS__; \ |
|
1085 |
/* refetch */ \ |
|
1086 |
buf = (char *)(obj); \ |
|
1087 |
continue; \ |
|
1088 |
} \ |
|
1089 |
break; \ |
|
1090 |
} \ |
|
1091 |
__offs += __cnt; \ |
|
1092 |
} \ |
|
1093 |
} \ |
|
1094 |
if (__offs > 0) \ |
|
1095 |
(ret) = __offs; \ |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1096 |
} \ |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1097 |
} |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1098 |
|
12548 | 1099 |
# define __READAVAILBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered, handleType) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1100 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1101 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1102 |
int __offs = 0; \ |
7540
7cd542f29024
Fix reading when readAheadBuffer is filled and following read fails
Stefan Vogel <sv@exept.de>
parents:
7503
diff
changeset
|
1103 |
int __cnt; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1104 |
char *buf = (char *)(obj); \ |
15342 | 1105 |
int oldFlags; \ |
23743 | 1106 |
\ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1107 |
(ret) = 0; \ |
15342 | 1108 |
SETNONBLOCKING(fileno(f), oldFlags); \ |
23743 | 1109 |
\ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1110 |
if (isBuffered) { \ |
23743 | 1111 |
while (__offs < (cnt)) { \ |
1112 |
CLEAR_ERRNO; \ |
|
1113 |
(ret) = getc(f); \ |
|
1114 |
if ((ret) < 0) { \ |
|
1115 |
if (ferror(f)) { \ |
|
1116 |
if (errno == EINTR) { \ |
|
1117 |
clearerr(f); \ |
|
1118 |
/* refetch */ \ |
|
1119 |
buf = (char *)(obj); \ |
|
1120 |
(ret) = 0; \ |
|
1121 |
break; \ |
|
1122 |
} \ |
|
1123 |
} else { \ |
|
1124 |
(ret) = 0; \ |
|
1125 |
} \ |
|
1126 |
break; \ |
|
1127 |
} \ |
|
1128 |
(buf)[__ooffs+__offs] = (ret); \ |
|
1129 |
DEBUGBUFFER(buf); \ |
|
1130 |
__offs++; \ |
|
1131 |
} \ |
|
1132 |
if (__offs > 0) \ |
|
1133 |
(ret) = __offs; \ |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1134 |
} else { \ |
23743 | 1135 |
int fd = fileno(f); \ |
1136 |
\ |
|
1137 |
while (__offs < (cnt)) { \ |
|
1138 |
OBJ rA = __INST(readAhead); \ |
|
1139 |
if (rA != nil) { \ |
|
1140 |
(buf)[__ooffs+__offs] = __intVal(rA); \ |
|
1141 |
DEBUGBUFFER(buf); \ |
|
1142 |
__INST(readAhead) = nil; \ |
|
1143 |
__offs++; \ |
|
1144 |
continue; \ |
|
1145 |
} \ |
|
1146 |
CLEAR_ERRNO; \ |
|
1147 |
__cnt = read(fd, (buf)+__ooffs+__offs, (cnt)-__offs); \ |
|
1148 |
DEBUGBUFFER(buf); \ |
|
1149 |
if (__cnt > 0) { \ |
|
1150 |
__offs += __cnt; \ |
|
1151 |
} \ |
|
1152 |
break; \ |
|
1153 |
} \ |
|
1154 |
if (__offs > 0) \ |
|
1155 |
(ret) = __offs; \ |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1156 |
} \ |
15342 | 1157 |
SETFLAGS(fileno(f), oldFlags); \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1158 |
} |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1159 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1160 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1161 |
# endif /* use STDIO */ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1162 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1163 |
# ifdef NO_STDIO |
12548 | 1164 |
# define __WRITEBYTE__(ret, f, buf, isBuffered, handleType) \ |
23743 | 1165 |
for (;;) { \ |
1166 |
CLEAR_ERRNO; \ |
|
1167 |
(ret) = WRITE(f, buf, 1, handleType); \ |
|
1168 |
if ((ret) >= 0) break; \ |
|
1169 |
if (errno != EINTR) { \ |
|
1170 |
break; \ |
|
1171 |
} \ |
|
1172 |
__HANDLE_INTERRUPTS__; \ |
|
1173 |
} |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1174 |
# else /* use STDIO */ |
12548 | 1175 |
# define __WRITEBYTE__(ret, f, buf, isBuffered, handleType) \ |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
1176 |
if (isBuffered) { \ |
23743 | 1177 |
for (;;) { \ |
1178 |
CLEAR_ERRNO; \ |
|
1179 |
ret = putc(*(buf), f); \ |
|
1180 |
if ((ret) >= 0) { \ |
|
1181 |
(ret) = 1; \ |
|
1182 |
} else if (ferror(f)) { \ |
|
1183 |
/* SOLARIS/SPARC (2.6) generates spurious errors with errno = 0 */ \ |
|
1184 |
if (errno == EINTR || errno == 0) { \ |
|
1185 |
__HANDLE_INTERRUPTS__; \ |
|
1186 |
clearerr(f); \ |
|
1187 |
continue; \ |
|
1188 |
} \ |
|
1189 |
} else \ |
|
1190 |
(ret) = 0; \ |
|
1191 |
break; \ |
|
1192 |
} \ |
|
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
1193 |
} else { \ |
23743 | 1194 |
for (;;) { \ |
1195 |
CLEAR_ERRNO; \ |
|
1196 |
(ret) = write(fileno(f), buf, 1); \ |
|
1197 |
if ((ret) >= 0) break; \ |
|
1198 |
if (errno != EINTR) { \ |
|
1199 |
break; \ |
|
1200 |
} \ |
|
1201 |
__HANDLE_INTERRUPTS__; \ |
|
1202 |
} \ |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1203 |
} |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1204 |
# endif /* use STDIO */ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1205 |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1206 |
/* |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1207 |
* write_bytes from a c-buffer |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1208 |
* (which may NOT move) |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1209 |
*/ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1210 |
# ifdef NO_STDIO |
12548 | 1211 |
# define __WRITEBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
2961 | 1212 |
(ret) = 0; \ |
1213 |
{ \ |
|
23743 | 1214 |
int __offs = 0; \ |
1215 |
while (__offs < (cnt)) { \ |
|
1216 |
CLEAR_ERRNO; \ |
|
1217 |
ret = WRITE(f, (buf)+__offs, (cnt)-__offs, handleType); \ |
|
1218 |
if (ret <= 0) { \ |
|
1219 |
if (ret < 0 && errno == EINTR) { \ |
|
1220 |
__HANDLE_INTERRUPTS__; \ |
|
1221 |
continue; \ |
|
1222 |
} \ |
|
1223 |
break; \ |
|
1224 |
} \ |
|
1225 |
__offs += (ret); \ |
|
1226 |
} \ |
|
1227 |
if (__offs > 0) \ |
|
1228 |
(ret) = __offs; \ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1229 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1230 |
# else /* use STDIO */ |
12548 | 1231 |
# define __WRITEBYTES__(ret, f, buf, cnt, isBuffered, handleType) \ |
2961 | 1232 |
(ret) = 0; \ |
1233 |
if (isBuffered) { \ |
|
23743 | 1234 |
int __offs = 0; \ |
1235 |
while (__offs < (cnt)) { \ |
|
1236 |
CLEAR_ERRNO; \ |
|
1237 |
(ret) = fwrite((buf)+__offs, 1, (cnt)-__offs, f);\ |
|
1238 |
if ((ret) <= 0) { \ |
|
1239 |
if (ferror(f)) { \ |
|
1240 |
if (errno == EINTR) { \ |
|
1241 |
__HANDLE_INTERRUPTS__; \ |
|
1242 |
clearerr(f); \ |
|
1243 |
continue; \ |
|
1244 |
} \ |
|
1245 |
} else { \ |
|
1246 |
(ret) = 0; \ |
|
1247 |
} \ |
|
1248 |
break; \ |
|
1249 |
} \ |
|
1250 |
__offs += (ret); \ |
|
1251 |
} \ |
|
1252 |
if (__offs > 0) \ |
|
1253 |
(ret) = __offs; \ |
|
2961 | 1254 |
} else { \ |
23743 | 1255 |
int __offs = 0; \ |
1256 |
while (__offs < (cnt)) { \ |
|
1257 |
CLEAR_ERRNO; \ |
|
1258 |
(ret) = write(fileno(f), (buf)+__offs, (cnt)-__offs);\ |
|
1259 |
if ((ret) <= 0) { \ |
|
1260 |
if ((ret) < 0) { \ |
|
1261 |
if (errno == EINTR) { \ |
|
1262 |
__HANDLE_INTERRUPTS__; \ |
|
1263 |
continue; \ |
|
1264 |
} \ |
|
1265 |
} \ |
|
1266 |
break; \ |
|
1267 |
} \ |
|
1268 |
__offs += (ret); \ |
|
1269 |
} \ |
|
1270 |
if (__offs > 0) \ |
|
1271 |
(ret) = __offs; \ |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1272 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1273 |
# endif /* use STDIO */ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1274 |
|
223 | 1275 |
/* |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1276 |
* write_bytes from an object |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1277 |
* (which may be moved around by GC) |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1278 |
*/ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1279 |
# ifdef NO_STDIO |
12548 | 1280 |
# define __WRITEBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered, handleType) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1281 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1282 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1283 |
int __offs = 0; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1284 |
char *buf = (char *)(obj); \ |
23743 | 1285 |
\ |
2961 | 1286 |
(ret) = 0; \ |
1287 |
{ \ |
|
23743 | 1288 |
while (__offs < (cnt)) { \ |
1289 |
CLEAR_ERRNO; \ |
|
1290 |
ret = WRITE(f, (buf)+__ooffs+__offs, (cnt)-__offs, handleType); \ |
|
1291 |
if (ret <= 0) { \ |
|
1292 |
if (ret < 0 && errno == EINTR) { \ |
|
1293 |
__HANDLE_INTERRUPTS__; \ |
|
1294 |
/* refetch */ \ |
|
1295 |
buf = (char *)(obj); \ |
|
1296 |
continue; \ |
|
1297 |
} \ |
|
1298 |
break; \ |
|
1299 |
} \ |
|
1300 |
__offs += (ret); \ |
|
1301 |
} \ |
|
1302 |
if (__offs > 0) \ |
|
1303 |
(ret) = __offs; \ |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1304 |
} \ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1305 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1306 |
# else /* use STDIO */ |
12548 | 1307 |
# define __WRITEBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered, handleType) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1308 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1309 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1310 |
int __offs = 0; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1311 |
char *buf = (char *)(obj); \ |
23743 | 1312 |
\ |
2961 | 1313 |
(ret) = 0; \ |
1314 |
if (isBuffered) { \ |
|
23743 | 1315 |
while (__offs < (cnt)) { \ |
1316 |
CLEAR_ERRNO; \ |
|
1317 |
(ret) = fwrite((buf)+__ooffs+__offs, 1, (cnt)-__offs, f); \ |
|
1318 |
if ((ret) <= 0) { \ |
|
1319 |
if (ferror(f)) { \ |
|
1320 |
if (errno == EINTR) { \ |
|
1321 |
__HANDLE_INTERRUPTS__; \ |
|
1322 |
/* refetch */ \ |
|
1323 |
buf = (char *)(obj); \ |
|
1324 |
clearerr(f); \ |
|
1325 |
continue; \ |
|
1326 |
} \ |
|
1327 |
break; \ |
|
1328 |
} else { \ |
|
1329 |
(ret) = 0; \ |
|
1330 |
} \ |
|
1331 |
} \ |
|
1332 |
__offs += (ret); \ |
|
1333 |
} \ |
|
2961 | 1334 |
} else { \ |
23743 | 1335 |
while (__offs < (cnt)) { \ |
1336 |
CLEAR_ERRNO; \ |
|
1337 |
(ret) = write(fileno(f), (buf)+__ooffs+__offs, (cnt)-__offs); \ |
|
1338 |
if ((ret) <= 0) { \ |
|
1339 |
if ((ret) < 0) { \ |
|
1340 |
if (errno == EINTR){ \ |
|
1341 |
__HANDLE_INTERRUPTS__; \ |
|
1342 |
/* refetch */ \ |
|
1343 |
buf = (char *)(obj); \ |
|
1344 |
continue; \ |
|
1345 |
} \ |
|
1346 |
} \ |
|
1347 |
break; \ |
|
1348 |
} \ |
|
1349 |
__offs += (ret); \ |
|
1350 |
} \ |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1351 |
} \ |
15845 | 1352 |
if (__offs > 0) \ |
23743 | 1353 |
(ret) = __offs; \ |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1354 |
} |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1355 |
# endif /* use STDIO */ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1356 |
#endif /* unix */ |
1 | 1357 |
%} |
188 | 1358 |
! ! |
1 | 1359 |
|
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1360 |
!ExternalStream class methodsFor:'documentation'! |
22 | 1361 |
|
88 | 1362 |
copyright |
1363 |
" |
|
1364 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1365 |
All Rights Reserved |
88 | 1366 |
|
1367 |
This software is furnished under a license and may be used |
|
1368 |
only in accordance with the terms of that license and with the |
|
1369 |
inclusion of the above copyright notice. This software may not |
|
1370 |
be provided or otherwise made available to, or used by, any |
|
1371 |
other person. No title to or ownership of the software is |
|
1372 |
hereby transferred. |
|
1373 |
" |
|
1374 |
! |
|
1375 |
||
22 | 1376 |
documentation |
1377 |
" |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1378 |
ExternalStream defines protocol common to Streams which have a file-descriptor and |
68 | 1379 |
represent some file or communicationChannel of the underlying OperatingSystem. |
1380 |
ExternalStream is abstract; concrete classes are FileStream, PipeStream etc. |
|
77 | 1381 |
|
159 | 1382 |
ExternalStreams can be in two modes: text- (the default) and binary-mode. |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1383 |
In text-mode, the elements read/written are characters; |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1384 |
while in binary-mode the basic elements are bytes which read/write as SmallIntegers |
68 | 1385 |
in the range 0..255. |
22 | 1386 |
|
68 | 1387 |
Also, the stream can be either in buffered or unbuffered mode. In buffered mode, |
1388 |
data is not written until either a cr is written (in text mode) or a synchronizeOutput |
|
1389 |
is sent (in both modes). |
|
22 | 1390 |
|
77 | 1391 |
The underlying OperatingSystem streams may either be closed explicitely (sending a close) |
68 | 1392 |
or just forgotten - in this case, the garbage collector will eventually collect the |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1393 |
object AND a close will be performed automatically (but you will NOT know when this |
77 | 1394 |
happens - so it is recommended, that you close your files when no longer needed). |
159 | 1395 |
Closing is also suggested, since if smalltalk is finished (be it by purpose, or due to |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1396 |
some crash) the data will not be in the file, if unclosed. |
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1397 |
All streams understand the close message, so it never hurts to use it (it is defined as |
77 | 1398 |
a noop in one of the superclasses). |
22 | 1399 |
|
68 | 1400 |
Most of the methods found here redefine inherited methods for better performance, |
1401 |
since I/O from/to files should be fast. |
|
22 | 1402 |
|
68 | 1403 |
Recovering a snapshot: |
1295 | 1404 |
not all streams can be restored to the state they had before - see the implementation of |
1405 |
reOpen in subclasses for more information. |
|
1406 |
For streams sitting on some communication channel (i.e. Pipes and Sockets) you should |
|
1407 |
reestablish the stream upon image restart (make someone dependent on ObjectMemory). |
|
1408 |
FileStreams are reopened and positioned to their offset they had at snapshot time. |
|
1409 |
This may fail, if the file was removed or renamed - or lead to confusion |
|
1410 |
if the contents changed in the meantime. |
|
1411 |
Therefore, it is a good idea to reopen files and check for these things at restart time. |
|
1412 |
||
1413 |
[Instance variables:] |
|
1414 |
||
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1415 |
handleType <Symbol> desribes what handle is: |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1416 |
win32: #fileHandle, #socketHandle, |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1417 |
#filePointer, #socketFilePointer, #pipeFilePointer |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1418 |
unix: #filePointer, #socketFilePointer, #pipeFilePointer |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1419 |
needed for win32, which uses different APIs for the different handles (sigh) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1420 |
handle <Integer> used to be always a filePointer somehow mapped to an integer (FILE* - not the fd); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1421 |
now, either a filePointer or a handle (win32) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1422 |
mode <Symbol> #readwrite, #readonly or #writeonly |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1423 |
buffered <Boolean> true, if buffered (i.e. collects characters - does |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1424 |
not output immediately) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1425 |
binary <Boolean> true if in binary mode (reads bytes instead of chars) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1426 |
eolMode <Symbol> one of nil, #nl, #cr or #crlf. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1427 |
determines how lines should be terminated. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1428 |
nil -> newLine (as in Unix); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1429 |
#crlf -> with cr-lf (as in MSDOS) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1430 |
#cr -> with cr (as in VMS) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1431 |
hitEOF <Boolean> true, if EOF was reached |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1432 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1433 |
lastErrorNumber <Integer> the value of errno (only valid right after the error - |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1434 |
updated with next i/o operation) |
1295 | 1435 |
|
1436 |
[Class variables:] |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1437 |
Lobby <Registry> keeps track of used ext-streams (to free up FILE*'s) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1438 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1439 |
StreamErrorSignal <Signal> parent of all stream errors (see Stream class) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1440 |
InvalidReadSignal <Signal> raised on read from writeonly stream |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1441 |
InvalidWriteSignal <Signal> raised on write to readonly stream |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1442 |
InvalidModeSignal <Signal> raised on text I/O with binary-stream |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1443 |
or binary I/O with text-stream |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1444 |
OpenErrorSignal <Signal> raised if open fails |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1445 |
StreamNotOpenSignal <Signal> raised on I/O with non-open stream |
159 | 1446 |
|
1447 |
Additional notes: |
|
1448 |
This class is implemented using the underlying stdio-c library package, which |
|
1449 |
has both advantages and disadvantages: since it is portable (posix defined), porting |
|
1450 |
ST/X to non-Unix machines is simplified. The disadvantage is that the stdio library |
|
1451 |
has big problems handling unbounded Streams, since the EOF handling in stdio is |
|
1452 |
not prepared for data to arrive after EOF has been reached - time will show, if we need |
|
1453 |
a complete rewrite for UnboundedStream ... |
|
325 | 1454 |
|
188 | 1455 |
Also, depending on the system, the stdio library behaves infriendly when signals |
1456 |
occur while reading (for example, timer interrupts) - on real unixes (i.e. BSD) the signal |
|
1457 |
is handled transparently - on SYS5.3 (i.e. non unixes :-) the read operation returns |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1458 |
an error and errno is set to EINTR. |
20411 | 1459 |
That's what the ugly code around all getc-calls is for ... |
1295 | 1460 |
Since things get more and more ugly - we will rewrite ExternalStream |
1461 |
completely, to NOT use any stdio stuff (and do its buffering itself). |
|
325 | 1462 |
|
1463 |
Notice that typical stdio's use a single errno global variable to return an error code, |
|
16508 | 1464 |
this was bad design in the stdio lib (right from the very beginning), since it's much |
325 | 1465 |
harder to deal with this in the presence of lightweight processes, where errno gets |
1466 |
overwritten by an I/O operation done in another thread. (stdio should have been written |
|
1467 |
to return errno as a negative number ...). |
|
1468 |
To deal with this, the scheduler treats errno like a per-thread private variable, |
|
1469 |
and saves/restores the errno setting when switching to another thread. |
|
1470 |
(Notice that some thread packages do this also, but ST/X's thread implementation |
|
1471 |
does not depend on those, but instead uses a portable private package). |
|
1472 |
||
216 | 1473 |
Finally, if an stdio-stream is open for both reading and writing, we have to call |
1474 |
fseek whenever we are about to read after write and vice versa. |
|
1475 |
Two macros (__READING__ and __WRITING__) have been defined to be used before every |
|
1476 |
fread/fgetc and fwrite/putc respectively. |
|
1295 | 1477 |
|
1478 |
[author:] |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1479 |
Claus Gittinger |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1480 |
Stefan Vogel (many, many fixes ...) |
1295 | 1481 |
|
1482 |
[see also:] |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1483 |
FileStream Socket PipeStream |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1484 |
Filename OperatingSystem |
22 | 1485 |
" |
3255 | 1486 |
! |
1487 |
||
1488 |
examples |
|
1489 |
" |
|
1490 |
open a file, read the contents and display it in a textView: |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1491 |
[exBegin] |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1492 |
|topView scrollPane textView fileStream text| |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1493 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1494 |
topView := StandardSystemView new. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1495 |
topView label:'contents of Makefile'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1496 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1497 |
scrollPane := HVScrollableView in:topView. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1498 |
scrollPane origin:0.0@0.0 corner:1.0@1.0. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1499 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1500 |
textView := EditTextView new. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1501 |
scrollPane scrolledView:textView. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1502 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1503 |
fileStream := 'Makefile' asFilename readStream. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1504 |
text := fileStream upToEnd. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1505 |
fileStream close. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1506 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1507 |
textView contents:text. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1508 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1509 |
topView open. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1510 |
[exEnd] |
3255 | 1511 |
|
1512 |
||
1513 |
Notice, all of the above can also be done (simply) as: |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1514 |
[exBegin] |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1515 |
EditTextView openOn:'Makefile' |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1516 |
[exEnd] |
3255 | 1517 |
" |
22 | 1518 |
! ! |
1519 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1520 |
!ExternalStream class methodsFor:'initialization'! |
1 | 1521 |
|
18636 | 1522 |
closeFiles |
1523 |
"close all files. |
|
1524 |
To be called on exit of Smalltalk." |
|
1525 |
||
1526 |
Lobby do:[:eachFileStream | |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1527 |
(eachFileStream ~~ Stdin |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1528 |
and:[eachFileStream ~~ Stdout |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1529 |
and:[eachFileStream ~~ Stderr]]) ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1530 |
eachFileStream close |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1531 |
]. |
18636 | 1532 |
]. |
22709 | 1533 |
|
1534 |
"Modified: / 25-04-2018 / 15:23:41 / stefan" |
|
18636 | 1535 |
! |
1536 |
||
2920 | 1537 |
initDefaultEOLMode |
1538 |
OperatingSystem isUNIXlike ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1539 |
"/ unix EOL conventions |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1540 |
DefaultEOLMode := #nl |
2920 | 1541 |
] ifFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1542 |
OperatingSystem isVMSlike ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1543 |
"/ vms EOL conventions |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1544 |
DefaultEOLMode := #cr |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1545 |
] ifFalse:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1546 |
"/ msdos EOL conventions |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1547 |
"/ msdos uses #crlf. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1548 |
"/ the following breaks all programs, which do not explicitly |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1549 |
"/ change th eolMode when writing/reading binary files (zip reader) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1550 |
"/ MUST change all classes before doing the following. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1551 |
"/ Anyway: for backward compatibility (swisscom), it is left in this |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1552 |
"/ mode (for a while, I hope). |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1553 |
DefaultEOLMode := #crlf. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1554 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1555 |
"/ DefaultEOLMode := #nl |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1556 |
] |
2920 | 1557 |
] |
1558 |
! |
|
1559 |
||
1560 |
initModeStrings |
|
1561 |
"initialize modeStrings which are passed down to the underlying |
|
1562 |
fopen/fdopen functions." |
|
1563 |
||
3132
037027ae20fd
msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1564 |
OperatingSystem isMSDOSlike ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1565 |
ReadMode := 'rb'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1566 |
ReadWriteMode := 'rb+'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1567 |
WriteMode := 'wb'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1568 |
AppendMode := 'ab+'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1569 |
CreateReadWriteMode := 'wb+'. |
3132
037027ae20fd
msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1570 |
] ifFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1571 |
ReadMode := 'r'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1572 |
ReadWriteMode := 'r+'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1573 |
WriteMode := 'w'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1574 |
AppendMode := 'a+'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1575 |
CreateReadWriteMode := 'w+'. |
3132
037027ae20fd
msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1576 |
] |
2920 | 1577 |
! |
1578 |
||
1 | 1579 |
initialize |
25180 | 1580 |
"/ self patchByteOrderOptimizedMethods |
159 | 1581 |
|
31 | 1582 |
Lobby isNil ifTrue:[ |
25180 | 1583 |
Lobby := Registry new. |
1584 |
||
1585 |
"want to get informed when returning from snapshot" |
|
1586 |
ObjectMemory addDependent:self |
|
2920 | 1587 |
]. |
5442 | 1588 |
DefaultEOLMode isNil ifTrue:[ |
25180 | 1589 |
self initDefaultEOLMode. |
5442 | 1590 |
]. |
1591 |
ReadMode isNil ifTrue:[ |
|
25180 | 1592 |
self initModeStrings. |
5442 | 1593 |
]. |
18790 | 1594 |
|
1595 |
"limit the amount of newspace to be used for non-tenurable executors to 5%" |
|
18929 | 1596 |
"/ MaxNonTenurableExecutors := ObjectMemory newSpaceSize // (Socket sizeOfInst:0) // 20. |
1597 |
"/ cg: changed because Socket is not in libbasic. Thus, standalone (libbasic only) |
|
1598 |
"/ 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
|
1599 |
MaxNonTenurableExecutors := (ObjectMemory newSpaceSize // 20 min:2000). |
18790 | 1600 |
|
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1601 |
"Modified: / 21.5.1998 / 16:33:53 / cg" |
1 | 1602 |
! |
1603 |
||
19615 | 1604 |
patchByteOrderOptimizedMethods |
1605 |
"EXPERIMENTAL (not yet done by default): |
|
1606 |
change the underlying implementation of |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1607 |
nextPutInt16MSB / nextPutInt16LSB |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1608 |
nextPutInt32MSB / nextPutInt32LSB |
19615 | 1609 |
to the corresponding NATIVE methods." |
1610 |
||
1611 |
|native16 native32| |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
1612 |
|
19615 | 1613 |
native16 := self compiledMethodAt:#nextPutInt16NATIVE:. |
1614 |
native32 := self compiledMethodAt:#nextPutInt32NATIVE:. |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
1615 |
|
19615 | 1616 |
UninterpretedBytes isBigEndian ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1617 |
(self compiledMethodAt:#nextPutInt16MSB:) code:(native16 code). |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1618 |
(self compiledMethodAt:#nextPutInt32MSB:) code:(native32 code). |
19615 | 1619 |
] ifFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1620 |
(self compiledMethodAt:#nextPutInt16LSB:) code:(native16 code). |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1621 |
(self compiledMethodAt:#nextPutInt32LSB:) code:(native32 code). |
19615 | 1622 |
]. |
1623 |
! |
|
1624 |
||
1 | 1625 |
reOpenFiles |
4108
8c4a45bc70eb
perform reOpen of streams earlier (before doing the view-reinit)
Claus Gittinger <cg@exept.de>
parents:
4093
diff
changeset
|
1626 |
"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
|
1627 |
This is invoked via the #earlyRestart change notification." |
1 | 1628 |
|
18636 | 1629 |
Lobby do:[:eachFileStream | |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1630 |
eachFileStream reOpen |
2920 | 1631 |
]. |
1 | 1632 |
! |
1633 |
||
1469 | 1634 |
update:something with:aParameter from:changedObject |
1 | 1635 |
"have to reopen files when returning from snapshot" |
1636 |
||
4108
8c4a45bc70eb
perform reOpen of streams earlier (before doing the view-reinit)
Claus Gittinger <cg@exept.de>
parents:
4093
diff
changeset
|
1637 |
something == #earlyRestart ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1638 |
self reOpenFiles. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1639 |
self initDefaultEOLMode |
1 | 1640 |
] |
1469 | 1641 |
|
1642 |
"Created: 15.6.1996 / 15:19:59 / cg" |
|
1 | 1643 |
! ! |
1644 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1645 |
!ExternalStream class methodsFor:'instance creation'! |
612 | 1646 |
|
12706 | 1647 |
forFileDescriptor:aFileDescriptor mode:modeSymbol |
2920 | 1648 |
"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
|
1649 |
to operate on this fd. |
12706 | 1650 |
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
|
1651 |
This may be used to wrap fd's as returned by user |
2920 | 1652 |
primitive code, or to wrap pipe-fds into externalStreams." |
1653 |
||
12706 | 1654 |
^ self forFileDescriptor:aFileDescriptor mode:modeSymbol buffered:true handleType:nil |
7002 | 1655 |
|
1656 |
" |
|
1657 |
the example below will probably fail (15 is a random FD): |
|
1658 |
||
1659 |
|s| |
|
1660 |
||
1661 |
s := ExternalStream forFileDescriptor:15 mode:'r'. |
|
1662 |
s next. |
|
1663 |
" |
|
1664 |
||
1665 |
"Created: 29.2.1996 / 18:05:00 / cg" |
|
1666 |
"Modified: 29.2.1996 / 18:17:07 / cg" |
|
1667 |
! |
|
1668 |
||
12706 | 1669 |
forFileDescriptor:aFileDescriptor mode:modeSymbol buffered:buffered handleType:handleTypeSymbol |
7002 | 1670 |
"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
|
1671 |
to operate on this fd. |
12706 | 1672 |
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
|
1673 |
This may be used to wrap fd's as returned by user |
7002 | 1674 |
primitive code, or to wrap pipe-fds into externalStreams." |
1675 |
||
21224 | 1676 |
^ self new |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1677 |
buffered:buffered; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1678 |
connectTo:aFileDescriptor withMode:modeSymbol handleType:handleTypeSymbol. |
2920 | 1679 |
|
1680 |
" |
|
1681 |
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
|
1682 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1683 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1684 |
|
21224 | 1685 |
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
|
1686 |
s next. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1687 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1688 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1689 |
"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
|
1690 |
"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
|
1691 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1692 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1693 |
forReadWriteToFileDescriptor:aFileDescriptor |
2920 | 1694 |
"given a fileDescriptor, create an ExternalStream object |
1695 |
to read/write from/to this fd. This may be used to wrap fd's |
|
1696 |
as returned by user primitive code, or to wrap pipe- |
|
1697 |
filedescriptors into externalStreams." |
|
1698 |
||
12706 | 1699 |
^ self forFileDescriptor:aFileDescriptor mode:#readWrite |
2920 | 1700 |
|
1701 |
" |
|
1702 |
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
|
1703 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1704 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1705 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1706 |
s := ExternalStream forReadWriteToFileDescriptor:15. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1707 |
s next. |
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 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1710 |
"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
|
1711 |
"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
|
1712 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1713 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1714 |
forReadingFromFileDescriptor:aFileDescriptor |
2920 | 1715 |
"given a fileDescriptor, create an ExternalStream object |
1716 |
to read from this fd. This may be used to wrap fd's |
|
1717 |
as returned by user primitive code, or to wrap pipe- |
|
1718 |
filedescriptors into externalStreams." |
|
1719 |
||
12706 | 1720 |
^ self forFileDescriptor:aFileDescriptor mode:#readonly |
2920 | 1721 |
|
1722 |
" |
|
1723 |
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
|
1724 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1725 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1726 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1727 |
s := ExternalStream forReadingFromFileDescriptor:15. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1728 |
s next. |
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 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1731 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1732 |
|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
|
1733 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1734 |
'create OS pipe ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1735 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1736 |
pipe := OperatingSystem makePipe. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1737 |
readFd := pipe at:1. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1738 |
writeFd := pipe at:2. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1739 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1740 |
'connect Smalltalk streams ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1741 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1742 |
rs := ExternalStream forReadingFromFileDescriptor:readFd. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1743 |
ws := ExternalStream forWritingToFileDescriptor:writeFd. |
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 |
'read ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1746 |
[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1747 |
1 to:10 do:[:i | |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1748 |
Transcript showCR:rs nextLine |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1749 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1750 |
rs close. |
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1751 |
] forkAt:7. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1752 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1753 |
'write ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1754 |
[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1755 |
1 to:10 do:[:i | |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1756 |
ws nextPutAll:'hello world '; nextPutAll:i printString; cr |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1757 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1758 |
ws close. |
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1759 |
] fork. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1760 |
|
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 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1763 |
"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
|
1764 |
"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
|
1765 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1766 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1767 |
forWritingToFileDescriptor:aFileDescriptor |
2920 | 1768 |
"given a fileDescriptor, create an ExternalStream object |
1769 |
to write to this fd. This may be used to wrap fd's |
|
1770 |
as returned by user primitive code, or to wrap pipe- |
|
1771 |
filedescriptors into externalStreams." |
|
1772 |
||
12706 | 1773 |
^ self forFileDescriptor:aFileDescriptor mode:#writeonly |
2920 | 1774 |
|
1775 |
" |
|
1776 |
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
|
1777 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1778 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1779 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1780 |
s := ExternalStream forWritingToFileDescriptor:15. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1781 |
s binary. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1782 |
s nextPut:1. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1783 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1784 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1785 |
"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
|
1786 |
"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
|
1787 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1788 |
|
612 | 1789 |
new |
15918
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
1790 |
"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
|
1791 |
|
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
1792 |
^ self basicNew initialize. |
612 | 1793 |
! ! |
1794 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1795 |
!ExternalStream class methodsFor:'Signal constants'! |
159 | 1796 |
|
1522
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1797 |
inaccessibleSignal |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1798 |
"ST-80 compatibility: return openErrorSignal" |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1799 |
|
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1800 |
^ self openErrorSignal |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1801 |
|
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1802 |
"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
|
1803 |
! |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1804 |
|
612 | 1805 |
invalidModeSignal |
1806 |
"return the signal raised when doing text-I/O with a binary stream |
|
1807 |
or binary-I/O with a text stream" |
|
1808 |
||
8074 | 1809 |
^ InvalidModeError |
159 | 1810 |
! |
1811 |
||
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1812 |
invalidOperationSignal |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1813 |
"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
|
1814 |
I/O operation is attempted" |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1815 |
|
8074 | 1816 |
^ InvalidOperationError |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1817 |
! |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1818 |
|
159 | 1819 |
invalidReadSignal |
1820 |
"return the signal raised when reading from writeonly streams" |
|
1821 |
||
8074 | 1822 |
^ InvalidReadError |
159 | 1823 |
! |
1824 |
||
1825 |
invalidWriteSignal |
|
1826 |
"return the signal raised when writing to readonly streams" |
|
1827 |
||
8074 | 1828 |
^ InvalidWriteError |
159 | 1829 |
! |
1830 |
||
612 | 1831 |
openErrorSignal |
1832 |
"return the signal raised when a file open failed" |
|
1833 |
||
25180 | 1834 |
^ OpenError |
612 | 1835 |
! |
1836 |
||
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1837 |
streamIOErrorSignal |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1838 |
"return the signal raised when an I/O error occurs. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1839 |
(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
|
1840 |
which is no longer available and has been mounted soft)" |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1841 |
|
8074 | 1842 |
^ StreamIOError |
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1843 |
|
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1844 |
"Created: / 21.5.1998 / 16:32:55 / cg" |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1845 |
! |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1846 |
|
159 | 1847 |
streamNotOpenSignal |
1848 |
"return the signal raised on I/O with closed streams" |
|
1849 |
||
8074 | 1850 |
^ StreamNotOpenError |
2 | 1851 |
! ! |
1852 |
||
22697 | 1853 |
!ExternalStream class methodsFor:'accessing'! |
1854 |
||
1855 |
openStreams |
|
1856 |
"answer a collection of open Streams having this class" |
|
1857 |
||
1858 |
|openStreams| |
|
1859 |
||
1860 |
openStreams := OrderedCollection new. |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1861 |
Lobby keysDo:[:eachStream| |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1862 |
(eachStream isKindOf:self) ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1863 |
openStreams add:eachStream |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1864 |
] |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1865 |
]. |
22697 | 1866 |
|
1867 |
^ openStreams |
|
1868 |
||
1869 |
" |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1870 |
self openStreams |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1871 |
Socket openStreams |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1872 |
NonPositionableExternalStream openStreams |
22697 | 1873 |
" |
1874 |
||
1875 |
"Created: / 24-04-2018 / 09:23:33 / stefan" |
|
1876 |
! ! |
|
1877 |
||
21337 | 1878 |
!ExternalStream class methodsFor:'defaults'! |
1879 |
||
1880 |
defaultCopyBufferSize:anInteger |
|
1881 |
"allows changing the size of buffer used when copying big |
|
1882 |
files/buld data from one stream to another. |
|
1883 |
Due to a bug on older Windows systems, the default used in copyToEndInto: |
|
1884 |
is chosen very conservatively, as the copy used to fail with big buffers. |
|
1885 |
However, modern Windows systems seem to not suffer from that bug, |
|
22578 | 1886 |
and bigger buffer sizes will dramatically increase the performance of |
21337 | 1887 |
copies to/from network drives. |
1888 |
This method allows for fine tuning, in case you run into performance problems, |
|
1889 |
or network buffer failures. |
|
1890 |
When nil, a somewhat conservative compromise is used." |
|
22578 | 1891 |
|
21337 | 1892 |
^ DefaultCopyBufferSize |
1893 |
! ! |
|
1894 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1895 |
!ExternalStream class methodsFor:'error handling'! |
92 | 1896 |
|
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1897 |
errorReporter |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1898 |
"I know about error codes" |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1899 |
|
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1900 |
^ self |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1901 |
! |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1902 |
|
92 | 1903 |
lastErrorNumber |
159 | 1904 |
"return the errno of the last error" |
92 | 1905 |
|
1906 |
^ LastErrorNumber |
|
159 | 1907 |
|
1908 |
" |
|
1909 |
ExternalStream lastErrorNumber |
|
1910 |
" |
|
92 | 1911 |
! |
1912 |
||
1913 |
lastErrorString |
|
1914 |
"return a message string describing the last error" |
|
1915 |
||
1916 |
^ OperatingSystem errorTextForNumber:LastErrorNumber |
|
1917 |
||
1918 |
" |
|
1919 |
ExternalStream lastErrorString |
|
1920 |
" |
|
6269
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 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
1923 |
reportOn:anErrorSymbolOrNumber |
20259 | 1924 |
"an error occurred. |
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1925 |
Report it via an Exception" |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1926 |
|
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1927 |
anErrorSymbolOrNumber isInteger ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1928 |
StreamError |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1929 |
raiseRequestWith:anErrorSymbolOrNumber |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1930 |
errorString:(' - os error:' , (OperatingSystem errorTextForNumber:anErrorSymbolOrNumber)) |
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1931 |
]. |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1932 |
(self respondsTo:anErrorSymbolOrNumber) ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1933 |
self perform:anErrorSymbolOrNumber |
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1934 |
] ifFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1935 |
StreamError |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1936 |
raiseRequestWith:anErrorSymbolOrNumber |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
1937 |
errorString:(' - ' , anErrorSymbolOrNumber printString) |
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1938 |
]. |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1939 |
^ false |
92 | 1940 |
! ! |
1941 |
||
20987 | 1942 |
!ExternalStream class methodsFor:'finalization'! |
1943 |
||
1944 |
finalizationLobby |
|
1945 |
"answer the registry used for finalization. |
|
1946 |
ExternalStreams have their own Registry" |
|
1947 |
||
1948 |
^ Lobby |
|
1949 |
! ! |
|
1950 |
||
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1951 |
!ExternalStream class methodsFor:'obsolete'! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1952 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1953 |
makePTYPair |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1954 |
"obsolete since 12-07-2003" |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1955 |
<resource:#obsolete> |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1956 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1957 |
self obsoleteMethodWarning:'use NonPositionableExternalStream makePTYPair'. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1958 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1959 |
^ NonPositionableExternalStream makePTYPair. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1960 |
! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1961 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1962 |
makePipe |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1963 |
"obsolete since 12-07-2003" |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1964 |
<resource:#obsolete> |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1965 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1966 |
self obsoleteMethodWarning:'use NonPositionableExternalStream makePipe'. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1967 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1968 |
^ NonPositionableExternalStream makePipe. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1969 |
! ! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1970 |
|
21037 | 1971 |
!ExternalStream class methodsFor:'testing'! |
1972 |
||
1973 |
isAbstract |
|
1974 |
^ self == ExternalStream |
|
1975 |
! ! |
|
1976 |
||
7261 | 1977 |
!ExternalStream methodsFor:'Compatibility-Dolphin'! |
6474 | 1978 |
|
1979 |
beText |
|
1980 |
self text |
|
1981 |
! ! |
|
1982 |
||
7261 | 1983 |
!ExternalStream methodsFor:'Compatibility-Squeak'! |
3044 | 1984 |
|
3872
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1985 |
nextInto:aByteArrayOrString |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1986 |
"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
|
1987 |
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
|
1988 |
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
|
1989 |
|
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1990 |
|n nWanted| |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1991 |
|
4368 | 1992 |
nWanted := aByteArrayOrString byteSize. |
3872
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1993 |
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
|
1994 |
n == nWanted ifTrue:[^ aByteArrayOrString]. |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1995 |
^ aByteArrayOrString copyTo:n |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1996 |
|
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1997 |
! |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1998 |
|
4368 | 1999 |
readInto:aContainer startingAt:index count:nElements |
2000 |
"same as #nextBytes:into:startingAt: for ByteArrays; |
|
2001 |
for LongArrays, nelements longs are read. |
|
3872
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2002 |
Squeak compatibility." |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2003 |
|
4368 | 2004 |
|elementSize n| |
2005 |
||
2006 |
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
|
2007 |
n := self nextBytes:nElements*elementSize into:aContainer startingAt:(index-1)*elementSize+1. |
4368 | 2008 |
^ n // elementSize |
3872
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2009 |
|
13940
12eb1c056d5e
fixed: #readInto:startingAt:count:; offset was wrong for non-byte elements
Claus Gittinger <cg@exept.de>
parents:
13927
diff
changeset
|
2010 |
"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
|
2011 |
! |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
2012 |
|
3044 | 2013 |
readOnly |
2014 |
"Squeak compatibility: make the stream readOnly" |
|
2015 |
||
2016 |
mode := #readonly |
|
2017 |
||
2018 |
"Modified: 20.10.1997 / 19:23:04 / cg" |
|
2019 |
"Created: 20.10.1997 / 19:23:19 / cg" |
|
2020 |
! ! |
|
2021 |
||
5187 | 2022 |
!ExternalStream methodsFor:'Signal constants'! |
2023 |
||
2024 |
invalidReadSignal |
|
2025 |
^ self class invalidReadSignal |
|
2026 |
||
2027 |
"Created: / 3.12.1998 / 15:12:06 / cg" |
|
2028 |
! |
|
2029 |
||
2030 |
invalidWriteSignal |
|
2031 |
^ self class invalidWriteSignal |
|
2032 |
||
2033 |
"Created: / 3.12.1998 / 15:12:10 / cg" |
|
2034 |
! ! |
|
2035 |
||
1 | 2036 |
!ExternalStream methodsFor:'accessing'! |
2037 |
||
612 | 2038 |
binary |
2039 |
"switch to binary mode - default is text" |
|
2040 |
||
2041 |
binary := true |
|
1 | 2042 |
! |
2043 |
||
23900 | 2044 |
binary:beBinaryBool |
2045 |
"switch to binary mode - default is text" |
|
2046 |
||
2047 |
|wasBinary| |
|
2048 |
||
2049 |
wasBinary := binary. |
|
2050 |
binary := beBinaryBool. |
|
2051 |
^ wasBinary |
|
2052 |
||
2053 |
"Created: / 13-03-2019 / 19:18:53 / Stefan Vogel" |
|
2054 |
! |
|
2055 |
||
1 | 2056 |
buffered:aBoolean |
23900 | 2057 |
"turn buffering on or off - default is on. |
2058 |
Answer the previous bufferd state." |
|
2059 |
||
2060 |
|wasBuffered| |
|
2061 |
||
2062 |
wasBuffered := buffered. |
|
2063 |
buffered := aBoolean. |
|
2064 |
^ wasBuffered. |
|
2065 |
||
2066 |
"Modified (comment): / 13-03-2019 / 19:33:16 / Stefan Vogel" |
|
1 | 2067 |
! |
2068 |
||
2069 |
contents |
|
2 | 2070 |
"return the contents of the file from the current position up-to |
2071 |
the end. If the stream is in binary mode, a ByteArray containing |
|
2072 |
the byte values is returned. |
|
2073 |
In text-mode, a collection of strings, each representing one line, |
|
2074 |
is returned." |
|
2075 |
||
20092 | 2076 |
|text| |
2 | 2077 |
|
2078 |
binary ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2079 |
^ self upToEnd. |
2 | 2080 |
]. |
1 | 2081 |
|
20092 | 2082 |
"/ text mode |
244 | 2083 |
text := StringCollection new. |
1 | 2084 |
[self atEnd] whileFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2085 |
|line| |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2086 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2087 |
line := self nextLine. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2088 |
line isNil ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2089 |
^ text |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2090 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2091 |
text add:line |
1 | 2092 |
]. |
2093 |
^ text |
|
2094 |
! |
|
2095 |
||
11751
1e75c54748ef
added #contentsAsString for Filename compatibility
Stefan Vogel <sv@exept.de>
parents:
11651
diff
changeset
|
2096 |
contentsAsString |
1e75c54748ef
added #contentsAsString for Filename compatibility
Stefan Vogel <sv@exept.de>
parents:
11651
diff
changeset
|
2097 |
"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
|
2098 |
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
|
2099 |
|
22848 | 2100 |
binary ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2101 |
^ [ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2102 |
binary := false. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2103 |
self contentsOfEntireFile. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2104 |
] ensure:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2105 |
binary := true. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2106 |
]. |
22848 | 2107 |
]. |
2108 |
||
2109 |
^ self contentsOfEntireFile. |
|
2110 |
||
2111 |
"Modified: / 09-05-2018 / 19:37:36 / stefan" |
|
11751
1e75c54748ef
added #contentsAsString for Filename compatibility
Stefan Vogel <sv@exept.de>
parents:
11651
diff
changeset
|
2112 |
! |
1e75c54748ef
added #contentsAsString for Filename compatibility
Stefan Vogel <sv@exept.de>
parents:
11651
diff
changeset
|
2113 |
|
612 | 2114 |
contentsOfEntireFile |
3938
4e7d1880336b
oops - #contentsOfEntireFile must return a byteArray if in binaryMode.
Claus Gittinger <cg@exept.de>
parents:
3906
diff
changeset
|
2115 |
"ST-80 compatibility: return contents as a String (or byteArray, if in binary mode). |
3876 | 2116 |
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
|
2117 |
|
6305 | 2118 |
^ self upToEnd |
1522
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
2119 |
|
3876 | 2120 |
"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
|
2121 |
"Modified: / 27.11.1998 / 16:29:43 / cg" |
2 | 2122 |
! |
2123 |
||
612 | 2124 |
contentsSpecies |
2125 |
"return the kind of object to be returned by sub-collection builders |
|
2126 |
(such as upTo)" |
|
159 | 2127 |
|
21139 | 2128 |
binary ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2129 |
^ ByteArray |
159 | 2130 |
]. |
612 | 2131 |
^ String |
2 | 2132 |
! |
2133 |
||
23745 | 2134 |
dependents |
23751 | 2135 |
^ dependents ? #() |
23745 | 2136 |
|
2137 |
"Created: / 19-02-2019 / 16:08:09 / Claus Gittinger" |
|
23751 | 2138 |
"Modified: / 19-02-2019 / 23:42:56 / Claus Gittinger" |
23745 | 2139 |
! |
2140 |
||
2141 |
dependents:aDependentsCollection |
|
2142 |
dependents := aDependentsCollection |
|
2143 |
||
2144 |
"Created: / 19-02-2019 / 16:08:23 / Claus Gittinger" |
|
2145 |
! |
|
2146 |
||
16776 | 2147 |
eolMode |
2148 |
"return how end-of-line (EOL) is to be marked. |
|
2149 |
Returns one one of: |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2150 |
#crlf -> add a CR-NL, as in MSDOS |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2151 |
#cr -> add a CR, as in VMS |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2152 |
#nl -> add a NL, as in Unix |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2153 |
#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
|
2154 |
#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
|
2155 |
#nl -> add a NL, as in Unix |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2156 |
nil -> transparent |
16776 | 2157 |
" |
2158 |
||
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
|
2159 |
^ eolMode |
21097 | 2160 |
|
2161 |
"Modified (comment): / 06-12-2016 / 14:26:24 / cg" |
|
16776 | 2162 |
! |
2163 |
||
2920 | 2164 |
eolMode:aSymbolOrNil |
2165 |
"specify how end-of-line (EOL) is to be marked. |
|
2166 |
The argument may be one of: |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2167 |
#crlf -> add a CR-NL, as in MSDOS |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2168 |
#cr -> add a CR, as in VMS |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2169 |
#nl -> add a NL, as in Unix |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2170 |
#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
|
2171 |
#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
|
2172 |
anyOther -> like #nl |
2920 | 2173 |
" |
2174 |
||
17462 | 2175 |
aSymbolOrNil == #crnl ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2176 |
eolMode := #crlf |
17462 | 2177 |
] ifFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2178 |
aSymbolOrNil == #lf ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2179 |
eolMode := #nl |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2180 |
] ifFalse:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2181 |
eolMode := aSymbolOrNil |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2182 |
] |
17462 | 2183 |
]. |
21097 | 2184 |
|
2185 |
"Modified (comment): / 06-12-2016 / 14:26:37 / cg" |
|
2920 | 2186 |
! |
2187 |
||
612 | 2188 |
fileDescriptor |
2189 |
"return the fileDescriptor of the receiver - |
|
2190 |
notice: this one returns the underlying OSs fileDescriptor - |
|
25317 | 2191 |
this may not be available on all platforms (i.e. non unix systems). |
2192 |
||
2193 |
NOTE: this may set the handle instance variable to nil |
|
2194 |
if the file descriptor is no longer valid." |
|
1 | 2195 |
|
3971 | 2196 |
%{ |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2197 |
OBJ _handle = __INST(handle); |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2198 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2199 |
if (_handle != nil) { |
25314 | 2200 |
if ((__INST(handleType) == @symbol(fileHandle)) |
2201 |
|| (__INST(handleType) == @symbol(socketHandle))) { |
|
2202 |
RETURN (_handle); |
|
2203 |
} |
|
2204 |
||
2205 |
if ((__INST(handleType) == nil) |
|
2206 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
2207 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
2208 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
2209 |
FILE *file = __FILEVal(_handle); |
|
2210 |
if (file != NULL) { |
|
2211 |
int fileNo = fileno(file); |
|
2212 |
||
2213 |
if (fileNo >= 0) { |
|
2214 |
RETURN ( __MKINT(fileNo)); |
|
2215 |
} |
|
2216 |
} |
|
2217 |
__INST(handle) = nil; |
|
2218 |
} |
|
1 | 2219 |
} |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2220 |
%}. |
25317 | 2221 |
handle isNil ifTrue:[ |
2222 |
^ nil. |
|
2223 |
]. |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2224 |
^ self fileDescriptorOfFile:handle |
21689 | 2225 |
|
21742 | 2226 |
"Modified: / 05-05-2017 / 16:27:34 / cg" |
25317 | 2227 |
"Modified: / 04-03-2020 / 13:02:49 / Stefan Vogel" |
2228 |
"Modified (comment): / 04-03-2020 / 14:14:35 / Stefan Vogel" |
|
21742 | 2229 |
! |
2230 |
||
2231 |
fileDescriptorOfFile:aHandle |
|
5852 | 2232 |
"for migration to rel5 only: |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2233 |
return the fileDescriptor of the argument handle - |
5852 | 2234 |
notice: this one returns the underlying OSs fileDescriptor - |
2235 |
this may not be available on all platforms (i.e. non unix systems)." |
|
2236 |
||
18312 | 2237 |
%{ |
2238 |
#ifdef __SCHTEAM__ |
|
21742 | 2239 |
return context._RETURN(aHandle); |
18312 | 2240 |
#endif |
2241 |
%}. |
|
21742 | 2242 |
^ nil |
2243 |
||
2244 |
"Modified: / 05-05-2017 / 16:20:20 / cg" |
|
612 | 2245 |
! |
2246 |
||
10455 | 2247 |
fileHandle |
2248 |
"return the fileHandle of the receiver. |
|
25317 | 2249 |
Under unix, this is the fileDescriptor; under windows, this is the Handle. |
2250 |
||
2251 |
NOTE: this may set the handle instance variable to nil |
|
2252 |
if the file descriptor is no longer valid." |
|
10455 | 2253 |
|
2254 |
%{ |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2255 |
OBJ _handle = __INST(handle); |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2256 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2257 |
if (_handle != nil) { |
25317 | 2258 |
if ((__INST(handleType) == @symbol(fileHandle)) |
2259 |
|| (__INST(handleType) == @symbol(socketHandle))) { |
|
2260 |
RETURN (_handle); |
|
2261 |
} |
|
2262 |
if ((__INST(handleType) == nil) |
|
2263 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
2264 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
2265 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
2266 |
FILE *file = __FILEVal(_handle); |
|
2267 |
if (file != NULL) { |
|
2268 |
int fileNo = fileno(file); |
|
2269 |
if (fileNo >= 0) { |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
2270 |
#ifdef __win32__ |
25317 | 2271 |
if (__INST(handleType) != @symbol(pipeFilePointer)) { |
2272 |
RETURN(__MKEXTERNALADDRESS(_get_osfhandle(fileNo))); |
|
2273 |
} |
|
10455 | 2274 |
#endif |
25317 | 2275 |
RETURN (__MKINT(fileNo)); |
2276 |
} |
|
2277 |
} |
|
2278 |
__INST(handle) = nil; |
|
2279 |
} |
|
10455 | 2280 |
} |
2281 |
%}. |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2282 |
^ handle |
21688 | 2283 |
|
2284 |
"Modified: / 07-04-2017 / 16:34:40 / cg" |
|
25317 | 2285 |
"Modified (comment): / 04-03-2020 / 14:26:26 / Stefan Vogel" |
10455 | 2286 |
! |
2287 |
||
612 | 2288 |
filePointer |
2289 |
"return the filePointer of the receiver - |
|
2290 |
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
|
2291 |
a FILE * - not a fileDescriptor. |
612 | 2292 |
(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
|
2293 |
You cannot do much with the returned value |
612 | 2294 |
- except passing it to a primitive, for example." |
2295 |
||
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2296 |
(handleType isNil or:[handleType == #filePointer]) ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2297 |
^ handle |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2298 |
]. |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2299 |
^ self error:'not a FILE*' |
612 | 2300 |
! |
2301 |
||
21229 | 2302 |
handle |
2303 |
^ handle |
|
2304 |
! |
|
2305 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2306 |
handleType |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2307 |
^ handleType |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2308 |
! |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2309 |
|
5323 | 2310 |
lineEndCRLF |
2311 |
eolMode := #crlf |
|
2312 |
! |
|
2313 |
||
17672 | 2314 |
lineEndLF |
2315 |
eolMode := #nl |
|
2316 |
! |
|
2317 |
||
3016 | 2318 |
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
|
2319 |
eolMode := #nl |
3016 | 2320 |
! |
2321 |
||
8069
fdf460457c96
acessing: pathName added (returns nil)
Michael Beyl <mb@exept.de>
parents:
8066
diff
changeset
|
2322 |
pathName |
8511
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2323 |
"answer the pathName of the stream. |
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2324 |
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
|
2325 |
|
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2326 |
^ '' |
8069
fdf460457c96
acessing: pathName added (returns nil)
Michael Beyl <mb@exept.de>
parents:
8066
diff
changeset
|
2327 |
! |
fdf460457c96
acessing: pathName added (returns nil)
Michael Beyl <mb@exept.de>
parents:
8066
diff
changeset
|
2328 |
|
612 | 2329 |
readonly |
2330 |
"set access mode to readonly" |
|
2331 |
||
2332 |
mode := #readonly |
|
2333 |
! |
|
2334 |
||
2335 |
readwrite |
|
2336 |
"set access mode to readwrite" |
|
2337 |
||
2338 |
mode := #readwrite |
|
2339 |
! |
|
2340 |
||
2341 |
text |
|
2342 |
"switch to text mode - default is text" |
|
2343 |
||
2344 |
binary := false |
|
2345 |
! |
|
2346 |
||
2347 |
useCRLF:aBoolean |
|
20147 | 2348 |
<resource: #obsolete> |
2920 | 2349 |
"turn on or off CRLF sending (instead of LF only) - default is off. |
2350 |
This method is provided for backward compatibility - see #eolMode: |
|
2351 |
which offers another choice." |
|
2352 |
||
2353 |
aBoolean ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2354 |
eolMode := #crlf |
2920 | 2355 |
] ifFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2356 |
eolMode := #nl |
2920 | 2357 |
]. |
1 | 2358 |
! |
2359 |
||
612 | 2360 |
writeonly |
2361 |
"set access mode to writeonly" |
|
2362 |
||
2363 |
mode := #writeonly |
|
2364 |
! ! |
|
2365 |
||
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2366 |
!ExternalStream methodsFor:'closing'! |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2367 |
|
20679 | 2368 |
abortAndClose |
2369 |
"close the stream - added for protocol compatibility with Socket and PipeStream. |
|
2370 |
see comment there" |
|
2371 |
||
2372 |
self close. |
|
2373 |
||
2374 |
"Modified: 30.8.1996 / 00:39:21 / cg" |
|
2375 |
! |
|
2376 |
||
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2377 |
close |
20106 | 2378 |
"Close the stream. |
2379 |
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
|
2380 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2381 |
self isOpen ifTrue:[ |
23879 | 2382 |
self unregisterForFinalization. |
2383 |
self isOpen ifTrue:[ |
|
2384 |
self closeFile. |
|
2385 |
dependents notNil ifTrue:[ |
|
2386 |
self changed:#close. |
|
2387 |
]. |
|
2388 |
]. |
|
16300 | 2389 |
]. |
23745 | 2390 |
|
2391 |
"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
|
2392 |
! |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2393 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2394 |
shutDown |
20679 | 2395 |
"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
|
2396 |
see comment there" |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2397 |
|
19072 | 2398 |
self close. |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2399 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2400 |
"Modified: 30.8.1996 / 00:39:21 / cg" |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2401 |
! ! |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2402 |
|
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2403 |
!ExternalStream methodsFor:'copying'! |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2404 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2405 |
copy |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2406 |
"answer a copy of myself. |
22713 | 2407 |
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
|
2408 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2409 |
|copy| |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2410 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2411 |
copy := super copy. |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2412 |
copy dupFd. |
22713 | 2413 |
self isPositionable ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2414 |
copy position:position. |
22713 | 2415 |
]. |
18779 | 2416 |
copy registerForFinalization. |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2417 |
^ copy |
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 |
" |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2420 |
|stream1 stream2| |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2421 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2422 |
stream1 := Filename newTemporary writeStream. |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2423 |
stream2 := stream1 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 |
stream1 inspect. |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2426 |
stream2 inspect. |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2427 |
" |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2428 |
! ! |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
2429 |
|
23913 | 2430 |
!ExternalStream methodsFor:'defaults'! |
2431 |
||
2432 |
bufferSizeForBulkCopy |
|
25136 | 2433 |
"return the size of buffer used when copying big files/bulk data |
23913 | 2434 |
from one stream to another. |
2435 |
Due to a bug on older Windows systems, the default used |
|
2436 |
is chosen very conservatively, as the copy used to fail with big buffers. |
|
2437 |
However, modern Windows systems seem to not suffer from that bug, |
|
2438 |
and bigger buffer sizes will dramatically increase the performance of |
|
2439 |
copies to/from network drives. |
|
2440 |
Setting DefaultCopyBufferSize allows for fine tuning, |
|
2441 |
in case you run into performance problems, or network buffer failures. |
|
2442 |
When nil, a somewhat conservative compromise is used." |
|
2443 |
||
2444 |
DefaultCopyBufferSize notNil ifTrue:[^ DefaultCopyBufferSize]. |
|
2445 |
||
2446 |
(OperatingSystem isMSWINDOWSlike and:[OperatingSystem isWin7Like not]) ifTrue:[ |
|
25136 | 2447 |
"/ mhmh - NT hangs, when copying bigger blocks to a network drive - why ? |
2448 |
^ 1 * 1024. |
|
23913 | 2449 |
]. |
2450 |
^ 64 * 1024. |
|
2451 |
||
2452 |
"Created: / 13-03-2019 / 16:49:17 / Stefan Vogel" |
|
2453 |
"Modified: / 13-03-2019 / 23:19:43 / Stefan Vogel" |
|
2454 |
! ! |
|
2455 |
||
612 | 2456 |
!ExternalStream methodsFor:'error handling'! |
2457 |
||
2458 |
argumentMustBeCharacter |
|
14440 | 2459 |
"report an error, that the argument must be a character in 0..FF" |
2460 |
||
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2461 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2462 |
|
14440 | 2463 |
ArgumentError raiseErrorString:' - argument must be a single byte character' |
612 | 2464 |
! |
2465 |
||
2466 |
argumentMustBeInteger |
|
14440 | 2467 |
"report an error, that the argument must be an integer" |
2468 |
||
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2469 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2470 |
|
14440 | 2471 |
ArgumentError raiseErrorString:' - argument must be an integer' |
77 | 2472 |
! |
2473 |
||
612 | 2474 |
argumentMustBeString |
14440 | 2475 |
"report an error, that the argument must be a string" |
2476 |
||
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2477 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2478 |
|
14440 | 2479 |
ArgumentError raiseErrorString:' - argument must be a string' |
612 | 2480 |
! |
2481 |
||
4526
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2482 |
errorAlreadyOpen |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2483 |
"{ Pragma: +optSpace }" |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2484 |
|
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2485 |
"report an error, that the stream is already opened" |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2486 |
|
8074 | 2487 |
^ OpenError |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2488 |
raiseRequestWith:self |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2489 |
errorString:' - stream is already open' |
8511
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2490 |
|
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2491 |
" |
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2492 |
self new errorAlreadyOpen |
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2493 |
" |
4526
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2494 |
|
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2495 |
"Modified: / 8.5.1999 / 20:12:30 / cg" |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2496 |
! |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2497 |
|
612 | 2498 |
errorBinary |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2499 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2500 |
|
612 | 2501 |
"report an error, that the stream is in binary mode" |
2502 |
||
8074 | 2503 |
^ InvalidModeError |
25136 | 2504 |
raiseRequestWith:self |
2505 |
errorString:(self className , ' is in binary mode') |
|
2506 |
"/ in:thisContext sender |
|
24383 | 2507 |
|
2508 |
"Modified: / 08-05-1999 / 20:12:43 / cg" |
|
2509 |
"Modified: / 28-06-2019 / 08:43:06 / Claus Gittinger" |
|
612 | 2510 |
! |
2511 |
||
2512 |
errorNotBinary |
|
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 not in binary mode" |
2516 |
||
8074 | 2517 |
^ InvalidModeError |
25136 | 2518 |
raiseRequestWith:self |
2519 |
errorString:(self className , ' is not in binary mode') |
|
2520 |
"/ in:thisContext sender |
|
24383 | 2521 |
|
2522 |
"Modified: / 08-05-1999 / 20:12:40 / cg" |
|
2523 |
"Modified: / 28-06-2019 / 08:43:11 / Claus Gittinger" |
|
1 | 2524 |
! |
2525 |
||
612 | 2526 |
errorNotBuffered |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2527 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2528 |
|
612 | 2529 |
"report an error, that the stream is not in buffered mode" |
2530 |
||
8074 | 2531 |
^ StreamError |
25136 | 2532 |
raiseRequestWith:self |
2533 |
errorString:(self className , ' is unbuffered - operation not allowed') |
|
2534 |
"/ in:thisContext sender |
|
24383 | 2535 |
|
2536 |
"Modified: / 08-05-1999 / 20:12:36 / cg" |
|
2537 |
"Modified: / 28-06-2019 / 08:43:14 / Claus Gittinger" |
|
612 | 2538 |
! |
2539 |
||
2540 |
errorReadOnly |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2541 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2542 |
|
612 | 2543 |
"report an error, that the stream is a readOnly stream" |
2544 |
||
25180 | 2545 |
^ InvalidWriteError raiseRequestWith:self "/ in:thisContext sender |
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2546 |
|
4468 | 2547 |
"Modified: / 30.7.1999 / 17:08:19 / cg" |
612 | 2548 |
! |
2549 |
||
6255
d68343dc8288
Define #errorReporter and #reportError: (ST-80 protocol)
Stefan Vogel <sv@exept.de>
parents:
6012
diff
changeset
|
2550 |
errorReporter |
d68343dc8288
Define #errorReporter and #reportError: (ST-80 protocol)
Stefan Vogel <sv@exept.de>
parents:
6012
diff
changeset
|
2551 |
"ST-80 mimicry." |
d68343dc8288
Define #errorReporter and #reportError: (ST-80 protocol)
Stefan Vogel <sv@exept.de>
parents:
6012
diff
changeset
|
2552 |
|
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
2553 |
^ self class |
6255
d68343dc8288
Define #errorReporter and #reportError: (ST-80 protocol)
Stefan Vogel <sv@exept.de>
parents:
6012
diff
changeset
|
2554 |
! |
d68343dc8288
Define #errorReporter and #reportError: (ST-80 protocol)
Stefan Vogel <sv@exept.de>
parents:
6012
diff
changeset
|
2555 |
|
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2556 |
errorUnsupportedOperation |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2557 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2558 |
|
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2559 |
"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
|
2560 |
|
8511
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2561 |
^ 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
|
2562 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2563 |
"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
|
2564 |
! |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2565 |
|
612 | 2566 |
errorWriteOnly |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2567 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2568 |
|
612 | 2569 |
"report an error, that the stream is a writeOnly stream" |
2570 |
||
8511
eb02df149f42
Raise proceedable exception proceedable.
Stefan Vogel <sv@exept.de>
parents:
8472
diff
changeset
|
2571 |
^ 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
|
2572 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2573 |
"Modified: / 8.5.1999 / 20:12:20 / cg" |
2 | 2574 |
! |
2575 |
||
612 | 2576 |
ioError |
20259 | 2577 |
"report an error, that some I/O error occurred. |
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
2578 |
(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
|
2579 |
which is no longer available and has been mounted soft)" |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
2580 |
|
16296 | 2581 |
"{ Pragma: +optSpace }" |
2582 |
||
2583 |
self ioError:lastErrorNumber |
|
2584 |
||
2585 |
"Modified: / 8.5.1999 / 20:12:16 / cg" |
|
2586 |
! |
|
2587 |
||
2588 |
ioError:errorNumber |
|
20259 | 2589 |
"report an error, that some I/O error occurred. |
16296 | 2590 |
(for example, a device-IO-error, or reading an NFS-dir, |
2591 |
which is no longer available and has been mounted soft)" |
|
2592 |
||
2593 |
"{ Pragma: +optSpace }" |
|
2594 |
||
2595 |
^ StreamIOError newException |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2596 |
errorCode:errorNumber; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2597 |
osErrorHolder:(OperatingSystem errorHolderForNumber:errorNumber); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2598 |
parameter:self; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2599 |
raiseRequest |
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2600 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2601 |
"Modified: / 8.5.1999 / 20:12:16 / cg" |
612 | 2602 |
! |
2603 |
||
2604 |
lastErrorNumber |
|
2605 |
"return the last error" |
|
2606 |
||
2607 |
^ lastErrorNumber |
|
2608 |
! |
|
2609 |
||
2610 |
lastErrorString |
|
2611 |
"return a message string describing the last error" |
|
2612 |
||
2613 |
(lastErrorNumber isNil or:[lastErrorNumber == 0]) ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2614 |
^ 'I/O error' |
612 | 2615 |
]. |
2616 |
^ OperatingSystem errorTextForNumber:lastErrorNumber |
|
2 | 2617 |
! |
2618 |
||
10932 | 2619 |
lastErrorSymbol |
2620 |
"return an error symbol describing the last error" |
|
2621 |
||
2622 |
^ OperatingSystem errorSymbolForNumber:lastErrorNumber |
|
2623 |
! |
|
2624 |
||
612 | 2625 |
openError |
12688 | 2626 |
"report an error, that the open failed" |
2627 |
||
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2628 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2629 |
|
14438 | 2630 |
^ self openError:lastErrorNumber. |
612 | 2631 |
! |
2632 |
||
12688 | 2633 |
openError:errorNumber |
2634 |
"report an error, that the open failed" |
|
2635 |
||
2636 |
"{ Pragma: +optSpace }" |
|
2637 |
||
15496 | 2638 |
|exClass errorHolder| |
2639 |
||
2640 |
errorHolder := OperatingSystem errorHolderForNumber:errorNumber. |
|
2641 |
||
2642 |
exClass := (errorHolder errorCategory == #nonexistentSignal) |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2643 |
ifTrue:[ FileDoesNotExistException ] |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2644 |
ifFalse:[ OpenError ]. |
13673 | 2645 |
|
2646 |
^ exClass newException |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2647 |
errorCode:errorNumber; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2648 |
osErrorHolder:errorHolder; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2649 |
"/ cg: initialized lazily - see OpenError>>#description |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2650 |
"/ errorString:(' : ' , errorHolder errorString); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2651 |
parameter:self; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2652 |
raiseRequest |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2653 |
"/ in:thisContext sender |
13673 | 2654 |
|
2655 |
"Modified: / 09-09-2011 / 07:22:49 / cg" |
|
12688 | 2656 |
! |
2657 |
||
612 | 2658 |
readError |
20259 | 2659 |
"report an error, that some read error occurred" |
15845 | 2660 |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2661 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2662 |
|
15845 | 2663 |
^ self readError:lastErrorNumber |
2664 |
! |
|
2665 |
||
2666 |
readError:errorNumber |
|
20259 | 2667 |
"report an error, that some read error occurred" |
612 | 2668 |
|
15845 | 2669 |
"{ Pragma: +optSpace }" |
2670 |
||
2671 |
^ ReadError newException |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2672 |
errorCode:errorNumber; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2673 |
osErrorHolder:(OperatingSystem errorHolderForNumber:errorNumber); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2674 |
parameter:self; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2675 |
raiseRequest |
612 | 2676 |
! |
2677 |
||
2678 |
writeError |
|
20259 | 2679 |
"report an error, that some write error occurred" |
15845 | 2680 |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2681 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2682 |
|
15845 | 2683 |
^ self writeError:lastErrorNumber |
2684 |
! |
|
2685 |
||
2686 |
writeError:errorNumber |
|
20259 | 2687 |
"report an error, that some write error occurred" |
612 | 2688 |
|
15845 | 2689 |
"{ Pragma: +optSpace }" |
2690 |
||
2691 |
^ WriteError newException |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2692 |
errorCode:errorNumber; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2693 |
osErrorHolder:(OperatingSystem errorHolderForNumber:errorNumber); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2694 |
parameter:self; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2695 |
raiseRequest |
612 | 2696 |
! ! |
2697 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2698 |
!ExternalStream methodsFor:'finalization'! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2699 |
|
22694 | 2700 |
beExecutor |
2701 |
"mark myself as being an executor for finalization. |
|
2702 |
We mis-use the mode symbol for this." |
|
2703 |
||
2704 |
mode := #executor. |
|
2705 |
||
2706 |
"Created: / 23-04-2018 / 18:17:01 / stefan" |
|
2707 |
! |
|
2708 |
||
15468 | 2709 |
executor |
2710 |
"return a copy for finalization-registration; |
|
2711 |
since all we need at finalization time is the fileDescriptor, |
|
2712 |
a cheaper copy is possible." |
|
2713 |
||
22694 | 2714 |
^ self class basicNew |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2715 |
beExecutor; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2716 |
setAccessor:handleType to:handle; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2717 |
yourself. |
22694 | 2718 |
|
2719 |
"Modified: / 23-04-2018 / 18:34:38 / stefan" |
|
15468 | 2720 |
! |
2721 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2722 |
finalize |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2723 |
"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
|
2724 |
|
20679 | 2725 |
self closeFile |
18779 | 2726 |
! |
2727 |
||
2728 |
reRegisterForFinalization |
|
2729 |
Lobby registerChange:self. |
|
2730 |
! |
|
2731 |
||
2732 |
registerForFinalization |
|
2733 |
||
2734 |
"keep myself in newSpace, so it will be finalized early" |
|
18790 | 2735 |
Lobby size < MaxNonTenurableExecutors ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
2736 |
ObjectMemory preventTenureOf:self. |
18790 | 2737 |
]. |
18779 | 2738 |
Lobby register:self. |
2739 |
! |
|
2740 |
||
2741 |
unregisterForFinalization |
|
2742 |
Lobby unregister:self. |
|
2743 |
"probably the object will be collected soon..." |
|
18793 | 2744 |
ObjectMemory allowTenureOf:self |
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2745 |
! ! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2746 |
|
15918
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
2747 |
!ExternalStream methodsFor:'initialization'! |
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
2748 |
|
d5fe9b9e87d3
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
15896
diff
changeset
|
2749 |
initialize |
15921 | 2750 |
position := 0. |
2751 |
binary := false. |
|
2752 |
buffered := true. |
|
19687 | 2753 |
self initializeEOLMode. |
2754 |
hitEOF := false. |
|
2755 |
! |
|
2756 |
||
2757 |
initializeEOLMode |
|
15921 | 2758 |
eolMode := DefaultEOLMode. |
15918
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 |
|
2 | 2761 |
!ExternalStream methodsFor:'line reading/writing'! |
1 | 2762 |
|
2763 |
nextLine |
|
2764 |
"read the next line (characters up to newline). |
|
2765 |
Return a string containing those characters excluding the newline. |
|
2766 |
If the previous-to-last character is a cr, this is also removed, |
|
16508 | 2767 |
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
|
2768 |
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
|
2769 |
|
16296 | 2770 |
|line error| |
971
eb70f5674303
max lineLength (in nextLine) increased to 16k
Claus Gittinger <cg@exept.de>
parents:
933
diff
changeset
|
2771 |
|
25136 | 2772 |
%{ /* STACK:50000 */ |
1 | 2773 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2774 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2775 |
int len, ret; |
3029
aa14768e0e6a
larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents:
3016
diff
changeset
|
2776 |
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
|
2777 |
char *rslt, *nextPtr, *limit; |
22 | 2778 |
int fd, ch; |
1068
92fdcccf12a3
alles MIST - zurueck zu 1.89 und NOCONTEXT entfernt
Claus Gittinger <cg@exept.de>
parents:
1067
diff
changeset
|
2779 |
int _buffered; |
216 | 2780 |
OBJ fp; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
2781 |
int lineTooLong = 0; |
2920 | 2782 |
int cutOff = 0; |
1 | 2783 |
|
1133 | 2784 |
__INST(lastErrorNumber) = nil; |
12548 | 2785 |
if ((__INST(handleType) == nil) |
2786 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
2787 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2788 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 2789 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 2790 |
if (((fp = __INST(handle)) != nil) |
2791 |
&& (__INST(mode) != @symbol(writeonly)) |
|
2792 |
&& (__INST(binary) != true) |
|
2793 |
) { |
|
2794 |
f = __FILEVal(fp); |
|
2795 |
buffer[0] = '\0'; |
|
2796 |
||
2797 |
_buffered = (__INST(buffered) == true); |
|
2798 |
if (_buffered) { |
|
2799 |
__READING__(f); |
|
2800 |
} |
|
2801 |
||
2802 |
rslt = nextPtr = buffer; |
|
2803 |
limit = buffer + sizeof(buffer) - 2; |
|
2804 |
||
2805 |
for (;;) { |
|
2806 |
__READBYTE__(ret, f, nextPtr, _buffered, __INST(handleType)); |
|
2807 |
if (ret <= 0) { |
|
2808 |
if (nextPtr == buffer) |
|
2809 |
rslt = NULL; |
|
2810 |
if (ret == 0) { |
|
2811 |
__INST(hitEOF) = true; |
|
2812 |
break; |
|
2813 |
} else { |
|
23538 | 2814 |
# ifdef __win32__ |
23743 | 2815 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 2816 |
# endif |
23743 | 2817 |
error = __mkSmallInteger(__threadErrno); |
2818 |
goto err; |
|
2819 |
} |
|
2820 |
} |
|
2821 |
||
2822 |
if (*nextPtr == '\n') { |
|
2823 |
cutOff = 1; |
|
2824 |
*nextPtr = '\0'; |
|
2825 |
break; |
|
2826 |
} |
|
2827 |
if (*nextPtr == '\r') { |
|
2828 |
char peekChar; |
|
2829 |
||
2830 |
/* |
|
2831 |
* peek ahead for a newLine ... |
|
2832 |
*/ |
|
2833 |
__READBYTE__(ret, f, &peekChar, _buffered, __INST(handleType)); |
|
2834 |
if (ret <= 0) { |
|
2835 |
cutOff = 1; |
|
2836 |
*nextPtr = '\0'; |
|
2837 |
if (ret == 0) { |
|
2838 |
__INST(hitEOF) = true; |
|
2839 |
break; |
|
2840 |
} |
|
23538 | 2841 |
# ifdef __win32__ |
23743 | 2842 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 2843 |
# endif |
23743 | 2844 |
error = __mkSmallInteger(__threadErrno); |
2845 |
goto err; |
|
2846 |
} |
|
2847 |
||
2848 |
if (peekChar == '\n') { |
|
2849 |
cutOff = 2; |
|
2850 |
*nextPtr = '\0'; |
|
2851 |
break; |
|
2852 |
} |
|
2853 |
||
2854 |
__UNGETC__(peekChar, f, _buffered); |
|
2855 |
||
2856 |
cutOff = 1; |
|
2857 |
*nextPtr = '\0'; |
|
2858 |
break; |
|
2859 |
} |
|
2860 |
||
2861 |
nextPtr++; |
|
2862 |
if (nextPtr >= limit) { |
|
2863 |
*nextPtr = '\0'; |
|
2864 |
lineTooLong = 1; |
|
2865 |
break; |
|
2866 |
} |
|
2867 |
} |
|
2868 |
||
2869 |
if (rslt != NULL) { |
|
2870 |
len = nextPtr-buffer; |
|
2871 |
||
2872 |
if (__isSmallInteger(__INST(position))) { |
|
2873 |
INT np = __intVal(__INST(position)) + len + cutOff; |
|
2874 |
OBJ t; |
|
2875 |
||
2876 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
2877 |
} else { |
|
2878 |
__INST(position) = nil; /* i.e. do not know */ |
|
2879 |
} |
|
2880 |
/* remove any EOL character */ |
|
2881 |
if (len != 0) { |
|
2882 |
if (buffer[len-1] == '\n') { |
|
2883 |
buffer[--len] = '\0'; |
|
2884 |
} |
|
2885 |
if ((len != 0) && (buffer[len-1] == '\r')) { |
|
2886 |
buffer[--len] = '\0'; |
|
2887 |
} |
|
2888 |
} |
|
2889 |
line = __MKSTRING_L(buffer, len); |
|
2890 |
if (! lineTooLong) { |
|
2891 |
RETURN ( line ); |
|
2892 |
} |
|
2893 |
} |
|
2894 |
} |
|
1 | 2895 |
} |
1478
aae07192b7d1
labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
2896 |
err: ; |
159 | 2897 |
%}. |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
2898 |
line notNil ifTrue:[ |
23743 | 2899 |
"/ the line as read is longer than 32k characters (boy - what a line) |
2900 |
"/ The exception raised below can be handled to ask the user |
|
2901 |
"/ and to read more and return the concatenation from the exception handler |
|
2902 |
"/ (the receiver and the partial line are passed as parameter) |
|
2903 |
"/ If unhandled, we do exactly that: read the rest and return the concatenation |
|
2904 |
"/ i.e. the full line - whatever its size is. |
|
2905 |
||
2906 |
LineTooLongErrorSignal isHandled ifTrue:[ |
|
2907 |
^ LineTooLongErrorSignal |
|
2908 |
raiseRequestWith:(Array with:self with:line) |
|
2909 |
errorString:('line too long read error') |
|
2910 |
]. |
|
2911 |
'ExternalStream [info]: very long line in nextLine' infoPrintCR. |
|
2912 |
^ 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
|
2913 |
]. |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
2914 |
|
21139 | 2915 |
hitEOF ifTrue:[^ self pastEndRead]. |
16296 | 2916 |
error notNil ifTrue:[ |
23743 | 2917 |
lastErrorNumber := error. |
2918 |
^ self readError:error |
|
16296 | 2919 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2920 |
handle isNil ifTrue:[^ self errorNotOpen]. |
1 | 2921 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
21139 | 2922 |
binary ifTrue:[^ self errorBinary]. |
5431 | 2923 |
^ super nextLine |
23538 | 2924 |
|
2925 |
"Modified: / 22-11-2018 / 14:46:40 / Stefan Vogel" |
|
1 | 2926 |
! |
2927 |
||
2928 |
nextPutLine:aString |
|
2920 | 2929 |
"write the characters in aString and append an end-of-Line marker |
2930 |
(LF, CR or CRLF - depending in the setting of eolMode)" |
|
1 | 2931 |
|
16296 | 2932 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2933 |
%{ |
7875
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
2934 |
OBJ fp; |
1 | 2935 |
|
1133 | 2936 |
__INST(lastErrorNumber) = nil; |
12548 | 2937 |
if ((__INST(handleType) == nil) |
2938 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
2939 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
2940 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 2941 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 2942 |
if (((fp = __INST(handle)) != nil) |
2943 |
&& (__INST(mode) != @symbol(readonly)) |
|
2944 |
&& (__INST(binary) != true) |
|
2945 |
&& __isStringLike(aString) |
|
2946 |
) { |
|
2947 |
int _buffered = (__INST(buffered) == true); |
|
2948 |
int len = __stringSize(aString); |
|
2949 |
int cnt, len1; |
|
2950 |
FILEPOINTER f = __FILEVal(fp); |
|
2951 |
char *cp; |
|
2952 |
int o_offs; |
|
2953 |
||
2954 |
if (_buffered) { |
|
2955 |
__WRITING__(f) |
|
2956 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
2957 |
#ifdef __win32__ |
23743 | 2958 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
2959 |
cnt = __win32_fwrite(__stringVal(aString), 1, len, f); |
|
2960 |
} else |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2961 |
#endif |
23743 | 2962 |
{ |
2963 |
o_offs = (char *)__stringVal(aString)-(char *)aString; |
|
2964 |
__WRITEBYTES_OBJ__(cnt, f, aString, o_offs, len, _buffered, __INST(handleType)); |
|
2965 |
} |
|
2966 |
if (cnt == len) { |
|
2967 |
OBJ mode = __INST(eolMode); |
|
2968 |
||
2969 |
len1 = len; |
|
2970 |
||
2971 |
if (mode == @symbol(cr)) { |
|
2972 |
cp = "\r"; len = 1; |
|
2973 |
} else if (mode == @symbol(crlf)) { |
|
2974 |
cp = "\r\n"; len = 2; |
|
2975 |
} else if (mode == @symbol(eot)) { |
|
2976 |
cp = "\004"; len = 1; |
|
2977 |
} else if (mode == @symbol(etx)) { |
|
2978 |
cp = "\003"; len = 1; |
|
2979 |
} else { |
|
2980 |
cp = "\n"; len = 1; |
|
2981 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
2982 |
#ifdef __win32__ |
23743 | 2983 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
2984 |
cnt = __win32_fwrite(cp, 1, len, f); |
|
2985 |
} else |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
2986 |
#endif |
23743 | 2987 |
{ |
2988 |
__WRITEBYTES__(cnt, f, cp, len, _buffered, __INST(handleType)); |
|
2989 |
} |
|
2990 |
if (cnt > 0) { |
|
2991 |
if (__isSmallInteger(__INST(position))) { |
|
2992 |
INT np = __intVal(__INST(position)) + len1 + cnt; |
|
2993 |
OBJ t; |
|
2994 |
||
2995 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
2996 |
} else { |
|
2997 |
__INST(position) = nil; /* i.e. do not know */ |
|
2998 |
} |
|
2999 |
RETURN ( self ); |
|
3000 |
} |
|
3001 |
} |
|
23538 | 3002 |
# ifdef __win32__ |
23743 | 3003 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 3004 |
# endif |
23743 | 3005 |
error = __mkSmallInteger(__threadErrno); |
3006 |
} |
|
1 | 3007 |
} |
159 | 3008 |
%}. |
16296 | 3009 |
error notNil ifTrue:[ |
23743 | 3010 |
lastErrorNumber := error. |
3011 |
self writeError:error. |
|
3012 |
^ self |
|
16296 | 3013 |
]. |
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
3014 |
super nextPutLine:aString. |
23538 | 3015 |
|
3016 |
"Modified: / 22-11-2018 / 14:48:48 / Stefan Vogel" |
|
1 | 3017 |
! |
3018 |
||
3019 |
nextPutLinesFrom:aStream upToLineStartingWith:aStringOrNil |
|
68 | 3020 |
"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
|
3021 |
and append all lines to self. |
159 | 3022 |
Can be used to copy/create large files or copy from a pipe/socket. |
68 | 3023 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3024 |
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
|
3025 |
|
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3026 |
|line| |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3027 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3028 |
[aStream atEnd] whileFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3029 |
line := aStream nextLine. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3030 |
line isNil ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3031 |
^ self. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3032 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3033 |
self nextPutLine:line. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3034 |
(aStringOrNil notNil and:[line startsWith:aStringOrNil]) ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3035 |
^ self |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3036 |
] |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3037 |
]. |
1 | 3038 |
! |
3039 |
||
3040 |
peekForLineStartingWith:aString |
|
3041 |
"read ahead for next line starting with aString; |
|
159 | 3042 |
return the line-string if found, or nil if EOF is encountered. |
7118 | 3043 |
If matched, do not advance position beyond that line |
159 | 3044 |
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
|
3045 |
If not matched, reposition to original position for further reading." |
1 | 3046 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3047 |
|firstPos lastPos line| |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3048 |
|
1 | 3049 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3050 |
handle isNil ifTrue:[^ self errorNotOpen]. |
2 | 3051 |
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
|
3052 |
buffered ifFalse:[^ self errorNotBuffered]. |
12 | 3053 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3054 |
firstPos := self position. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3055 |
[self atEnd] whileFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3056 |
lastPos := self position. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3057 |
line := self nextLine. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3058 |
line isNil ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3059 |
self position:firstPos. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3060 |
^ nil |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3061 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3062 |
(line startsWith:aString) ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3063 |
self position:lastPos. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3064 |
^ line |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3065 |
] |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3066 |
]. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3067 |
self position:firstPos. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3068 |
^ nil |
1 | 3069 |
! |
3070 |
||
3071 |
peekForLineStartingWithAny:aCollectionOfStrings |
|
3072 |
"read ahead for next line starting with any of aCollectionOfStrings; |
|
3073 |
return the index in aCollection if found, nil otherwise.. |
|
3074 |
If no match, do not change position; otherwise advance right before the |
|
3075 |
matched line so that nextLine will return this line." |
|
3076 |
||
3077 |
|line startPos linePos index| |
|
3078 |
||
3079 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3080 |
handle isNil ifTrue:[^ self errorNotOpen]. |
2 | 3081 |
binary ifTrue:[^ self errorBinary]. |
3082 |
||
1 | 3083 |
startPos := self position. |
3084 |
[self atEnd] whileFalse:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3085 |
linePos := self position. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3086 |
line := self nextLine. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3087 |
line notNil ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3088 |
index := 1. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3089 |
aCollectionOfStrings do:[:prefix | |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3090 |
(line startsWith:prefix) ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3091 |
self position:linePos. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3092 |
^ index |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3093 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3094 |
index := index + 1 |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3095 |
] |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3096 |
] |
1 | 3097 |
]. |
3098 |
self position:startPos. |
|
3099 |
^ nil |
|
3100 |
! ! |
|
3101 |
||
612 | 3102 |
!ExternalStream methodsFor:'misc functions'! |
3103 |
||
3104 |
async:aBoolean |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3105 |
"set/clear the async attribute - if set, the availability of data on |
612 | 3106 |
the receiver will trigger an ioInterrupt. |
779 | 3107 |
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
|
3108 |
Notice: |
25317 | 3109 |
not every OS supports this |
3110 |
- check with OS>>supportsIOInterrupts before using" |
|
92 | 3111 |
|
3112 |
|fd| |
|
3113 |
||
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3114 |
OperatingSystem supportsIOInterrupts ifFalse:[ |
25317 | 3115 |
^ self errorUnsupportedOperation |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3116 |
]. |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3117 |
|
92 | 3118 |
fd := self fileDescriptor. |
25317 | 3119 |
"self fileDescriptor sets handle to nil and |
3120 |
answers nil, if the handle is no longer valid!!" |
|
3121 |
fd isNil ifTrue:[ |
|
3122 |
self errorNotOpen. |
|
3123 |
^ false. |
|
3124 |
]. |
|
22195 | 3125 |
|
612 | 3126 |
aBoolean ifTrue:[ |
25317 | 3127 |
^ OperatingSystem enableIOInterruptsOn:fd |
612 | 3128 |
]. |
3129 |
^ OperatingSystem disableIOInterruptsOn:fd |
|
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3130 |
|
25317 | 3131 |
"Modified: / 11-01-1997 / 17:50:21 / cg" |
3132 |
"Modified: / 04-03-2020 / 13:04:08 / Stefan Vogel" |
|
92 | 3133 |
! |
3134 |
||
612 | 3135 |
blocking:aBoolean |
3136 |
"set/clear the blocking attribute - if set (which is the default) |
|
3137 |
a read (using next) on the receiver will block until data is available. |
|
3138 |
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
|
3139 |
nil. |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3140 |
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
|
3141 |
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
|
3142 |
in advance. However, the data must then be read using #nextBytes: |
8616 | 3143 |
methods, in order to avoid other (pastEndRead) exceptions." |
92 | 3144 |
|
22195 | 3145 |
|fd| |
3146 |
||
3147 |
fd := self fileDescriptor. |
|
25317 | 3148 |
"self fileDescriptor sets handle to nil and |
3149 |
answers nil, if the handle is no longer valid!!" |
|
3150 |
fd isNil ifTrue:[ |
|
3151 |
self errorNotOpen. |
|
3152 |
^ true. |
|
25314 | 3153 |
]. |
25317 | 3154 |
^ OperatingSystem setBlocking:aBoolean on:fd. |
25314 | 3155 |
|
3156 |
"Modified: / 11-01-1997 / 17:48:01 / cg" |
|
3157 |
"Modified: / 15-01-1998 / 11:49:48 / stefan" |
|
25317 | 3158 |
"Modified: / 04-03-2020 / 13:05:44 / Stefan Vogel" |
612 | 3159 |
! |
3160 |
||
3161 |
ioctl:ioctlNumber |
|
3162 |
"to provide a simple ioctl facility - an ioctl is performed |
|
3163 |
on the underlying file; no arguments are passed." |
|
3164 |
||
2920 | 3165 |
^ self ioctl:ioctlNumber with:nil |
3166 |
! |
|
3167 |
||
3168 |
ioctl:ioctlNumber with:arg |
|
3169 |
"to provide a simple ioctl facility - an ioctl is performed |
|
3170 |
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
|
3171 |
This is not used by ST/X, but provided for special situations |
2920 | 3172 |
- for example, to control proprietrary I/O devices. |
3173 |
||
3174 |
Since the type of the argument depends on the ioctl being |
|
3175 |
performed, different arg types are allowed here. |
|
3176 |
If the argument is nil, an ioctl without argument is performed. |
|
16508 | 3177 |
If the argument is an integral number, it's directly passed; |
3178 |
if it's a kind of ByteArray (ByteArray, String or Structure), |
|
2920 | 3179 |
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
|
3180 |
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
|
3181 |
This allows performing most ioctls |
2920 | 3182 |
- however, it might be tricky to setup the buffer. |
3183 |
Be careful in what you pass - ST/X cannot validate its correctness." |
|
3184 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3185 |
|error| |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3186 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3187 |
%{ |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3188 |
#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
|
3189 |
int fd; |
10552
d52aa8e066e5
#ioctl:with: accept 32-bit integers as arguments
Stefan Vogel <sv@exept.de>
parents:
10469
diff
changeset
|
3190 |
int ret; |
d52aa8e066e5
#ioctl:with: accept 32-bit integers as arguments
Stefan Vogel <sv@exept.de>
parents:
10469
diff
changeset
|
3191 |
unsigned int ioNum; |
2920 | 3192 |
INT ioArg; |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3193 |
OBJ fp = __INST(handle); |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3194 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3195 |
if (fp == nil) |
23743 | 3196 |
goto out; |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3197 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3198 |
if (!__isInteger(ioctlNumber) |
23743 | 3199 |
|| (!__isInteger(arg) |
3200 |
&& (arg != nil) |
|
3201 |
&& !__isBytes(arg) |
|
3202 |
&& !__isExternalBytesLike(arg) |
|
3203 |
&& !__isExternalAddress(arg))) { |
|
3204 |
error = @symbol(badArgument); |
|
3205 |
goto out; |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3206 |
} |
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 |
if (__INST(handleType) == @symbol(socketHandle)) { |
23743 | 3209 |
fd = (int)((SOCKET)(__FILEVal(fp))); |
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3210 |
} else |
23743 | 3211 |
if ((__INST(handleType) == nil) |
3212 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3213 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
3214 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
3215 |
fd = fileno(__FILEVal(fp)); |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3216 |
} else { |
23743 | 3217 |
error = @symbol(badHandleType); |
3218 |
goto out; |
|
612 | 3219 |
} |
16508 | 3220 |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3221 |
ioNum = __unsignedLongIntVal(ioctlNumber); |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3222 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3223 |
__BEGIN_INTERRUPTABLE__ |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3224 |
do { |
23743 | 3225 |
__threadErrno = 0; |
3226 |
if (arg == nil) { |
|
3227 |
ioArg = 0; |
|
3228 |
} else if (__isSmallInteger(arg)) { |
|
3229 |
ioArg = __intVal(arg); |
|
3230 |
} else if (__isInteger(arg)) { |
|
3231 |
ioArg = __unsignedLongIntVal(arg); |
|
3232 |
} else if (__isExternalBytesLike(arg)) { |
|
3233 |
ioArg = (INT)(__externalBytesAddress(arg)); |
|
3234 |
} else if (__isExternalAddress(arg)) { |
|
3235 |
ioArg = (INT)(__externalAddressVal(arg)); |
|
3236 |
} else { |
|
3237 |
ioArg = (INT)(__ByteArrayInstPtr(arg)->ba_element); |
|
3238 |
} |
|
3239 |
ret = ioctl(fd, ioNum, ioArg); |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3240 |
} while (ret < 0 && __threadErrno == EINTR); |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3241 |
__END_INTERRUPTABLE__ |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3242 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3243 |
if (ret >= 0) { |
23743 | 3244 |
RETURN ( __mkSmallInteger(ret) ); |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3245 |
} |
23538 | 3246 |
# ifdef __win32__ |
23743 | 3247 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 3248 |
# endif |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3249 |
error = __mkSmallInteger(__threadErrno); |
791 | 3250 |
#endif |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3251 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3252 |
out:; |
612 | 3253 |
%}. |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3254 |
error notNil ifTrue:[ |
23743 | 3255 |
lastErrorNumber := error. |
3256 |
^ self ioError:error. |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3257 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3258 |
handle isNil ifTrue:[^ self errorNotOpen]. |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3259 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3260 |
"/ the system does not support ioctl (MSDOS or VMS) |
2920 | 3261 |
^ self errorUnsupportedOperation |
23538 | 3262 |
|
3263 |
"Modified: / 22-11-2018 / 14:42:04 / Stefan Vogel" |
|
612 | 3264 |
! |
3265 |
||
16551 | 3266 |
reset |
3267 |
"set the read position to the beginning of the collection" |
|
3268 |
||
3269 |
self position:0 |
|
3270 |
! |
|
3271 |
||
3272 |
setToEnd |
|
3273 |
"redefined since it must be implemented differently" |
|
3274 |
||
3275 |
^ self subclassResponsibility |
|
3276 |
! |
|
3277 |
||
3278 |
sync |
|
3279 |
"make sure, that the OS writes cached data to the disk" |
|
3280 |
||
3281 |
|error| |
|
3282 |
||
3283 |
self flush. |
|
3284 |
||
3285 |
%{ |
|
3286 |
#if !defined(__openVMS__) |
|
3287 |
int fd; |
|
3288 |
int ret; |
|
3289 |
OBJ fp = __INST(handle); |
|
3290 |
||
3291 |
if (fp == nil) |
|
23743 | 3292 |
goto out; |
16551 | 3293 |
|
3294 |
if (__INST(handleType) == @symbol(socketHandle)) { |
|
23743 | 3295 |
// syncing a socket to disk ? |
3296 |
error = @symbol(badHandleType); |
|
3297 |
goto out; |
|
3298 |
// fd = __FILEVal(fp); |
|
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3299 |
} else |
23743 | 3300 |
if ((__INST(handleType) == nil) |
3301 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3302 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
3303 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
3304 |
fd = fileno(__FILEVal(fp)); |
|
16551 | 3305 |
} else { |
23743 | 3306 |
error = @symbol(badHandleType); |
3307 |
goto out; |
|
16551 | 3308 |
} |
3309 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
3310 |
#ifdef __win32__ |
16551 | 3311 |
__threadErrno = 0; |
3312 |
ret = __STX_API_NOINT_CALL1( "FlushFileBuffers", FlushFileBuffers, _get_osfhandle(fd)); |
|
3313 |
if (ret) { |
|
23743 | 3314 |
RETURN (self); |
16551 | 3315 |
} |
23538 | 3316 |
__threadErrno = __WIN32_ERR(GetLastError()); |
16551 | 3317 |
#else |
3318 |
__BEGIN_INTERRUPTABLE__ |
|
3319 |
do { |
|
23743 | 3320 |
ret = fsync(fd); |
16551 | 3321 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
3322 |
__END_INTERRUPTABLE__ |
|
3323 |
||
3324 |
if (ret >= 0) { |
|
23743 | 3325 |
RETURN (self); |
16551 | 3326 |
} |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
3327 |
#endif /* ! __win32__ */ |
16551 | 3328 |
error = __mkSmallInteger(__threadErrno); |
3329 |
#endif /* ! __openVMS__ */ |
|
3330 |
out:; |
|
3331 |
%}. |
|
3332 |
error notNil ifTrue:[ |
|
23743 | 3333 |
lastErrorNumber := error. |
3334 |
self ioError:error. |
|
3335 |
^ self. |
|
16551 | 3336 |
]. |
3337 |
handle isNil ifTrue:[self errorNotOpen]. |
|
3338 |
||
3339 |
" |
|
23743 | 3340 |
|f| |
3341 |
f := 'x' asFilename writeStream. |
|
3342 |
f nextPutAll:'hallo'; sync; syncData; close |
|
16551 | 3343 |
" |
23538 | 3344 |
|
3345 |
"Modified: / 22-11-2018 / 14:51:43 / Stefan Vogel" |
|
16551 | 3346 |
! |
3347 |
||
3348 |
syncData |
|
3349 |
"make sure, that the OS writes cached data to the disk. |
|
3350 |
In this case, metadata is only written, if it is |
|
3351 |
required to read the file's data (so metadata will not be written, |
|
3352 |
if only access/modification time has changed)." |
|
3353 |
|error| |
|
3354 |
||
3355 |
self flush. |
|
3356 |
||
3357 |
%{ |
|
3358 |
#if !defined(__openVMS__) |
|
3359 |
int fd; |
|
3360 |
int ret; |
|
3361 |
OBJ fp = __INST(handle); |
|
3362 |
||
3363 |
if (fp == nil) |
|
23743 | 3364 |
goto out; |
16551 | 3365 |
|
3366 |
if (__INST(handleType) == @symbol(socketHandle)) { |
|
23743 | 3367 |
// syncing a socket to disk ? |
3368 |
error = @symbol(badHandleType); |
|
3369 |
goto out; |
|
3370 |
// fd = __FILEVal(fp); |
|
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3371 |
} else |
23743 | 3372 |
if ((__INST(handleType) == nil) |
3373 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3374 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
3375 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
3376 |
fd = fileno(__FILEVal(fp)); |
|
16551 | 3377 |
} else { |
23743 | 3378 |
error = @symbol(badHandleType); |
3379 |
goto out; |
|
16551 | 3380 |
} |
3381 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
3382 |
#ifdef __win32__ |
16551 | 3383 |
__threadErrno = 0; |
3384 |
ret = __STX_API_NOINT_CALL1( "FlushFileBuffers", FlushFileBuffers, _get_osfhandle(fd)); |
|
3385 |
if (ret) { |
|
23743 | 3386 |
RETURN (self); |
16551 | 3387 |
} |
23538 | 3388 |
__threadErrno = __WIN32_ERR(GetLastError()); |
16551 | 3389 |
#else |
3390 |
__BEGIN_INTERRUPTABLE__ |
|
3391 |
do { |
|
23743 | 3392 |
ret = fdatasync(fd); |
16551 | 3393 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
3394 |
__END_INTERRUPTABLE__ |
|
3395 |
||
3396 |
if (ret >= 0) { |
|
23743 | 3397 |
RETURN (self); |
16551 | 3398 |
} |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
3399 |
#endif /* ! __win32__ */ |
16551 | 3400 |
error = __mkSmallInteger(__threadErrno); |
3401 |
#endif /* ! __openVMS__ */ |
|
3402 |
out:; |
|
3403 |
%}. |
|
3404 |
||
3405 |
error notNil ifTrue:[ |
|
23743 | 3406 |
lastErrorNumber := error. |
3407 |
self ioError:error. |
|
3408 |
^ self. |
|
16551 | 3409 |
]. |
3410 |
handle isNil ifTrue:[^ self errorNotOpen]. |
|
3411 |
||
3412 |
"if notdef HAS_DATASYNC, fall back" |
|
3413 |
self sync. |
|
3414 |
||
3415 |
" |
|
23743 | 3416 |
|f| |
3417 |
f := 'x' asFilename writeStream. |
|
3418 |
f nextPutAll:'hallo'; sync; syncData; close |
|
16551 | 3419 |
" |
23538 | 3420 |
|
3421 |
"Modified: / 22-11-2018 / 14:51:31 / Stefan Vogel" |
|
16551 | 3422 |
! |
3423 |
||
16508 | 3424 |
tcgetattr |
3425 |
"unix only: |
|
3426 |
provide the information of a tcgetattr call as a dictionary. |
|
3427 |
This provides terminal setting values of a tty or pty. |
|
3428 |
Used by terminal emulators. |
|
3429 |
On non-unix systems, an unsupported operation error is raised" |
|
3430 |
||
3431 |
|error ret |
|
3432 |
iflags "/ input flags |
|
3433 |
ignbrk brkint ignpar parmrk inpck istrip inlcr igncr |
|
16509
2cf139885242
Fixed ExternalStream>>tcgetattr
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16508
diff
changeset
|
3434 |
icrnl iuclc ixon ixoff ixany imaxbel iutf8 |
16508 | 3435 |
oflags "/ output flags |
3436 |
opost onlcr ocrnl olcuc onocr onlret oxtabs onoteot |
|
3437 |
cflags "/ control flags |
|
3438 |
csize cstopb cread parenb parodd hupcl clocal |
|
3439 |
lflags "/ local flags |
|
3440 |
echoke echoe echok echo echonl echoprt echoctl |
|
3441 |
isig icanon altwerase iexten extproc tostop |
|
3442 |
| |
|
3443 |
||
3444 |
%{ |
|
3445 |
#if !defined(MSDOS_LIKE) && !defined(__openVMS__) |
|
3446 |
int fd; |
|
3447 |
int _ret; |
|
3448 |
OBJ fp = __INST(handle); |
|
3449 |
struct termios t; |
|
3450 |
int sz; |
|
3451 |
||
3452 |
if (fp == nil) |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3453 |
goto out; |
16508 | 3454 |
|
3455 |
if (__INST(handleType) == @symbol(socketHandle)) { |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3456 |
// cg: termina attributes of a socket? |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3457 |
error = @symbol(badHandleType); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3458 |
goto out; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3459 |
// fd = __FILEVal(fp); |
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3460 |
} else |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3461 |
if ((__INST(handleType) == nil) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3462 |
|| (__INST(handleType) == @symbol(filePointer)) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3463 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3464 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3465 |
fd = fileno(__FILEVal(fp)); |
16508 | 3466 |
} else { |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3467 |
error = @symbol(badHandleType); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3468 |
goto out; |
16508 | 3469 |
} |
3470 |
||
3471 |
__BEGIN_INTERRUPTABLE__ |
|
3472 |
do { |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3473 |
__threadErrno = 0; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3474 |
_ret = tcgetattr(fd, &t); |
16508 | 3475 |
} while (_ret < 0 && __threadErrno == EINTR); |
3476 |
__END_INTERRUPTABLE__ |
|
3477 |
||
3478 |
if (_ret < 0) { |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3479 |
error = __mkSmallInteger(__threadErrno); |
16508 | 3480 |
} |
3481 |
ignbrk = t.c_iflag & IGNBRK ? true : false; |
|
3482 |
brkint = t.c_iflag & BRKINT ? true : false; |
|
3483 |
ignpar = t.c_iflag & IGNPAR ? true : false; |
|
3484 |
parmrk = t.c_iflag & PARMRK ? true : false; |
|
3485 |
inpck = t.c_iflag & INPCK ? true : false; |
|
3486 |
istrip = t.c_iflag & ISTRIP ? true : false; |
|
3487 |
inlcr = t.c_iflag & INLCR ? true : false; |
|
3488 |
ixon = t.c_iflag & IXON ? true : false; |
|
3489 |
ixoff = t.c_iflag & IXOFF ? true : false; |
|
3490 |
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
|
3491 |
# ifdef IMAXBEL |
16508 | 3492 |
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
|
3493 |
# endif |
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3494 |
# ifdef IUCLC |
16508 | 3495 |
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
|
3496 |
# endif |
16508 | 3497 |
|
3498 |
opost = t.c_oflag & OPOST ? true : false; |
|
3499 |
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
|
3500 |
# ifdef OXTABS |
16508 | 3501 |
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
|
3502 |
# endif |
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3503 |
# ifdef ONOTEOT |
16508 | 3504 |
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
|
3505 |
# endif |
16508 | 3506 |
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
|
3507 |
# ifdef OLCUC |
16508 | 3508 |
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
|
3509 |
# endif |
16508 | 3510 |
onocr = t.c_oflag & ONOCR ? true : false; |
3511 |
onlret = t.c_oflag & ONLRET ? true : false; |
|
3512 |
||
3513 |
sz = t.c_cflag & CSIZE; |
|
3514 |
switch (sz) { |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3515 |
case CS5: |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3516 |
csize = @symbol(cs5); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3517 |
break; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3518 |
case CS6: |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3519 |
csize = @symbol(cs6); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3520 |
break; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3521 |
case CS7: |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3522 |
csize = @symbol(cs7); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3523 |
break; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3524 |
case CS8: |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3525 |
csize = @symbol(cs8); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3526 |
break; |
16508 | 3527 |
} |
3528 |
cstopb = t.c_cflag & CSTOPB ? true : false; |
|
3529 |
cread = t.c_cflag & CREAD ? true : false; |
|
3530 |
parenb = t.c_cflag & PARENB ? true : false; |
|
3531 |
parodd = t.c_cflag & PARODD ? true : false; |
|
3532 |
hupcl = t.c_cflag & HUPCL ? true : false; |
|
3533 |
clocal = t.c_cflag & CLOCAL ? true : false; |
|
3534 |
||
3535 |
echoke = t.c_lflag & ECHOKE ? true : false; |
|
3536 |
echoe = t.c_lflag & ECHOE ? true : false; |
|
3537 |
echo = t.c_lflag & ECHO ? true : false; |
|
3538 |
echonl = t.c_lflag & ECHONL ? true : false; |
|
3539 |
echoctl = t.c_lflag & ECHOCTL ? true : false; |
|
3540 |
isig = t.c_lflag & ISIG ? true : false; |
|
3541 |
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
|
3542 |
# ifdef ALTWERASE |
16508 | 3543 |
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
|
3544 |
# endif |
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3545 |
# ifdef IEXTEN |
16508 | 3546 |
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
|
3547 |
# endif |
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3548 |
# ifdef EXTPROC |
16508 | 3549 |
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
|
3550 |
# endif |
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
3551 |
# ifdef TOSTOP |
16508 | 3552 |
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
|
3553 |
# endif |
16508 | 3554 |
|
3555 |
#else |
|
3556 |
error = @symbol(unsupportedOperation); |
|
3557 |
#endif |
|
3558 |
||
3559 |
out:; |
|
3560 |
%}. |
|
3561 |
error notNil ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3562 |
error == #unsupportedOperation ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3563 |
"/ the system does not support tcgetattr |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3564 |
^ self errorUnsupportedOperation |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3565 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3566 |
lastErrorNumber := error. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3567 |
^ self ioError:error. |
16508 | 3568 |
]. |
3569 |
handle isNil ifTrue:[^ self errorNotOpen]. |
|
3570 |
||
3571 |
"/ construct a dictionary... |
|
3572 |
ret := Dictionary new. |
|
3573 |
ret at:#iflags put:(iflags := Dictionary new). |
|
3574 |
ret at:#oflags put:(oflags := Dictionary new). |
|
3575 |
ret at:#cflags put:(cflags := Dictionary new). |
|
3576 |
ret at:#lflags put:(lflags := Dictionary new). |
|
3577 |
iflags at:#ignbrk put:ignbrk. |
|
3578 |
iflags at:#brkint put:brkint. |
|
3579 |
iflags at:#ignpar put:ignpar. |
|
3580 |
iflags at:#parmrk put:parmrk. |
|
3581 |
iflags at:#inpck put:inpck. |
|
3582 |
iflags at:#istrip put:istrip. |
|
3583 |
iflags at:#inlcr put:inlcr. |
|
3584 |
iflags at:#igncr put:igncr. |
|
3585 |
iflags at:#icrnl put:icrnl. |
|
16509
2cf139885242
Fixed ExternalStream>>tcgetattr
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16508
diff
changeset
|
3586 |
iflags at:#uiclc put:iuclc. |
16508 | 3587 |
iflags at:#ixon put:ixon. |
3588 |
iflags at:#ixoff put:ixoff. |
|
3589 |
iflags at:#ixany put:ixany. |
|
3590 |
iflags at:#imaxbel put:imaxbel. |
|
3591 |
iflags at:#iutf8 put:iutf8. |
|
3592 |
||
3593 |
oflags at:#opost put:opost. |
|
3594 |
oflags at:#onlcr put:onlcr. |
|
3595 |
oflags at:#oxtabs put:oxtabs. |
|
3596 |
oflags at:#onoteot put:onoteot. |
|
3597 |
||
3598 |
cflags at:#csize put:csize. |
|
3599 |
cflags at:#cstopb put:cstopb. |
|
3600 |
cflags at:#cread put:cread. |
|
3601 |
cflags at:#parenb put:parenb. |
|
3602 |
cflags at:#parodd put:parodd. |
|
3603 |
cflags at:#hupcl put:hupcl. |
|
3604 |
cflags at:#clocal put:clocal. |
|
3605 |
||
3606 |
lflags at:#echoke put:echoke. |
|
3607 |
lflags at:#echoe put:echoe. |
|
3608 |
lflags at:#echok put:echok. |
|
3609 |
lflags at:#echo put:echo. |
|
3610 |
lflags at:#echonl put:echonl. |
|
3611 |
lflags at:#echoprt put:echoprt. |
|
3612 |
lflags at:#echoctl put:echoctl. |
|
3613 |
lflags at:#isig put:isig. |
|
3614 |
lflags at:#icanon put:icanon. |
|
3615 |
lflags at:#altwerase put:altwerase. |
|
3616 |
lflags at:#iexten put:iexten. |
|
3617 |
lflags at:#extproc put:extproc. |
|
3618 |
lflags at:#tostop put:tostop. |
|
3619 |
^ ret |
|
612 | 3620 |
! ! |
3621 |
||
3622 |
!ExternalStream methodsFor:'non homogenous reading'! |
|
3623 |
||
17609 | 3624 |
next:count into:aCollection startingAt:start |
20092 | 3625 |
"return the next count bytes or characters from the stream." |
3626 |
||
17609 | 3627 |
|readCount| |
3628 |
||
3629 |
readCount := self nextBytes:count into:aCollection startingAt:start. |
|
3630 |
readCount = count ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3631 |
^ aCollection. |
17609 | 3632 |
]. |
3633 |
^ aCollection copyFrom:1 to:start+readCount-1. |
|
15254 | 3634 |
! |
3635 |
||
3674 | 3636 |
nextAvailable:count |
3637 |
"return the next count elements of the stream as aCollection. |
|
3638 |
If the stream reaches the end before count elements have been read, |
|
3639 |
return what is available. (i.e. a shorter collection). |
|
3640 |
The type of collection is specified in #contentsSpecies." |
|
3641 |
||
3956
51f1a9a4d63f
changes for egcs (stdio uses __new / utsname)
Claus Gittinger <cg@exept.de>
parents:
3949
diff
changeset
|
3642 |
|buffer n| |
3674 | 3643 |
|
20092 | 3644 |
buffer := self contentsSpecies uninitializedNew:count. |
3674 | 3645 |
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
|
3646 |
n == 0 ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3647 |
binary ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3648 |
^ #[] |
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 |
^ '' |
5202
e8130049b18f
#nextAvailableBytes:into:startingAt: may NOT set EOF flag,
Claus Gittinger <cg@exept.de>
parents:
5187
diff
changeset
|
3651 |
]. |
3674 | 3652 |
|
3653 |
n ~~ count ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
3654 |
^ buffer copyTo:n |
3674 | 3655 |
]. |
3656 |
^ buffer. |
|
3657 |
||
3658 |
" |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3659 |
(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
|
3660 |
(ReadStream on:#(1 2 3 4 5)) nextAvailable:10 |
3674 | 3661 |
(ReadStream on:'hello') nextAvailable:3 |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3662 |
(ReadStream on:'hello') nextAvailable:10 |
3674 | 3663 |
" |
3664 |
||
3665 |
"Modified: / 16.6.1998 / 15:52:41 / cg" |
|
3666 |
! |
|
3667 |
||
17608 | 3668 |
nextAvailable:count into:aCollection startingAt:pos |
3669 |
"return the next count elements of the stream into aCollection at position pos." |
|
3670 |
||
3671 |
^ self nextAvailableBytes:count into:aCollection startingAt:pos. |
|
3672 |
! |
|
3673 |
||
24507 | 3674 |
nextAvailableBytes:count |
3675 |
"return the next count bytes of the stream as a byteArray. |
|
3676 |
If the stream reaches the end before count bytes have been read, |
|
3677 |
return what is available. (i.e. a shorter byteArray)." |
|
3678 |
||
3679 |
|buffer n| |
|
3680 |
||
3681 |
buffer := ByteArray uninitializedNew:count. |
|
3682 |
n := self nextAvailableBytes:count into:buffer startingAt:1. |
|
3683 |
n == 0 ifTrue:[ |
|
25136 | 3684 |
^ #[] |
24507 | 3685 |
]. |
3686 |
||
3687 |
n ~~ count ifTrue:[ |
|
25136 | 3688 |
^ buffer copyTo:n |
24507 | 3689 |
]. |
3690 |
^ buffer. |
|
3691 |
||
3692 |
" |
|
3693 |
(ReadStream on:#(1 2 3 4 5)) nextAvailable:3 |
|
3694 |
(ReadStream on:#(1 2 3 4 5)) nextAvailable:10 |
|
3695 |
(ReadStream on:'hello') nextAvailable:3 |
|
3696 |
(ReadStream on:'hello') nextAvailable:10 |
|
3697 |
" |
|
3698 |
||
3699 |
"Modified: / 16.6.1998 / 15:52:41 / cg" |
|
3700 |
! |
|
3701 |
||
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3702 |
nextAvailableBytes:count into:anObject startingAt:start |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3703 |
"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
|
3704 |
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
|
3705 |
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
|
3706 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3707 |
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
|
3708 |
is raised if the connection is broken. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3709 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3710 |
Notice, that in contrast to other methods, |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3711 |
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
|
3712 |
Thus allowing read of partial blocks. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3713 |
|
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3714 |
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
|
3715 |
(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
|
3716 |
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
|
3717 |
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
|
3718 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3719 |
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
|
3720 |
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
|
3721 |
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
|
3722 |
|
16296 | 3723 |
|error| |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3724 |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3725 |
%{ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3726 |
FILEPOINTER f; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3727 |
int cnt, offs, ret, _buffered; |
15987 | 3728 |
int objSize, nInstBytes; |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3729 |
char *cp; |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3730 |
char *extPtr; |
7195
755c46f9b774
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
7118
diff
changeset
|
3731 |
OBJ fp; |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3732 |
int o_offs; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3733 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3734 |
__INST(lastErrorNumber) = nil; |
12548 | 3735 |
if ((__INST(handleType) == nil) |
3736 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3737 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3738 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 3739 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
25136 | 3740 |
if (((fp = __INST(handle)) != nil) |
3741 |
&& (__INST(mode) != @symbol(writeonly)) |
|
3742 |
&& __bothSmallInteger(count, start) |
|
3743 |
) { |
|
3744 |
f = __FILEVal(fp); |
|
3745 |
||
3746 |
cnt = __intVal(count); |
|
3747 |
offs = __intVal(start) - 1; |
|
3748 |
||
3749 |
if (__isExternalBytesLike(anObject)) { |
|
3750 |
OBJ sz; |
|
3751 |
||
3752 |
nInstBytes = 0; |
|
3753 |
extPtr = (char *)(__externalBytesAddress(anObject)); |
|
3754 |
if (extPtr == NULL) goto bad; |
|
3755 |
sz = __externalBytesSize(anObject); |
|
3756 |
if (__isSmallInteger(sz)) { |
|
3757 |
objSize = __intVal(sz); |
|
3758 |
} else { |
|
3759 |
objSize = 0; /* unknown */ |
|
3760 |
} |
|
3761 |
} else { |
|
3762 |
OBJ oClass = __Class(anObject); |
|
3763 |
int nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
3764 |
||
3765 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
3766 |
||
3767 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
|
3768 |
case BYTEARRAY: |
|
3769 |
case WORDARRAY: |
|
3770 |
case LONGARRAY: |
|
3771 |
case SWORDARRAY: |
|
3772 |
case SLONGARRAY: |
|
3773 |
case FLOATARRAY: |
|
3774 |
break; |
|
3775 |
case DOUBLEARRAY: |
|
15987 | 3776 |
#ifdef __NEED_DOUBLE_ALIGN |
25136 | 3777 |
nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1); |
15987 | 3778 |
#endif |
25136 | 3779 |
break; |
3780 |
case LONGLONGARRAY: |
|
3781 |
case SLONGLONGARRAY: |
|
16296 | 3782 |
#ifdef __NEED_LONGLONG_ALIGN |
25136 | 3783 |
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
|
3784 |
#endif |
25136 | 3785 |
break; |
3786 |
default: |
|
3787 |
goto bad; |
|
3788 |
} |
|
3789 |
extPtr = (char *)0; |
|
3790 |
objSize = __Size(anObject) - nInstBytes; |
|
3791 |
} |
|
3792 |
||
3793 |
if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) { |
|
3794 |
_buffered = (__INST(buffered) == true); |
|
3795 |
if (_buffered) { |
|
3796 |
__READING__(f); |
|
3797 |
} |
|
3798 |
||
3799 |
if (extPtr) { |
|
3800 |
__READAVAILBYTES__(ret, f, extPtr+offs, cnt, _buffered, __INST(handleType)); |
|
3801 |
} else { |
|
3802 |
/* |
|
3803 |
* on interrupt, anObject may be moved to another location. |
|
3804 |
* So we pass (char *)__InstPtr(anObject) + nInstBytes + offs to the macro __READ_BYTES__, |
|
3805 |
* to get a new address. |
|
3806 |
*/ |
|
3807 |
offs += nInstBytes; |
|
3808 |
__READAVAILBYTES_OBJ__(ret, f, anObject, offs, cnt, _buffered, __INST(handleType)); |
|
3809 |
} |
|
3810 |
/* 0 is NOT an EOF condition here ... */ |
|
3811 |
if (ret >= 0) { |
|
3812 |
if (__isSmallInteger(__INST(position))) { |
|
3813 |
INT np = __intVal(__INST(position)) + ret; |
|
3814 |
OBJ t; |
|
3815 |
||
3816 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
3817 |
} else { |
|
3818 |
__INST(position) = nil; /* i.e. do not know */ |
|
3819 |
} |
|
3820 |
RETURN (__mkSmallInteger(ret)); |
|
3821 |
} |
|
3822 |
__INST(position) = nil; |
|
23538 | 3823 |
# ifdef __win32__ |
25136 | 3824 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 3825 |
# endif |
25136 | 3826 |
error = __mkSmallInteger(__threadErrno); |
3827 |
} |
|
3828 |
} |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3829 |
} |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3830 |
bad: ; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3831 |
%}. |
20092 | 3832 |
hitEOF ifTrue:[^ 0]. |
16296 | 3833 |
error notNil ifTrue:[ |
25136 | 3834 |
lastErrorNumber := error. |
3835 |
^ self readError:error |
|
16296 | 3836 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3837 |
handle isNil ifTrue:[^ self errorNotOpen]. |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3838 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3839 |
" |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3840 |
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
|
3841 |
" |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3842 |
^ self primitiveFailed |
23538 | 3843 |
|
23897 | 3844 |
"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
|
3845 |
! |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3846 |
|
612 | 3847 |
nextByte |
3848 |
"read the next byte and return it as an Integer; return nil on error. |
|
3849 |
This is allowed in both text and binary modes, always returning the |
|
3850 |
bytes binary value as an integer in 0..255." |
|
3851 |
||
16296 | 3852 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3853 |
%{ |
18364 | 3854 |
#ifdef __SCHTEAM__ |
3855 |
STObject handle = self.instVarAt(I_handle); |
|
3856 |
||
3857 |
if (handle != STObject.Nil) { |
|
23743 | 3858 |
STObject next; |
3859 |
||
3860 |
next = handle.nextByte(); |
|
3861 |
if (next != STObject.EOF) { |
|
3862 |
self.instVarAt_put(I_position, STObject.Nil); |
|
3863 |
return __c__._RETURN( next ); |
|
3864 |
} |
|
3865 |
self.instVarAt_put(I_hitEOF, STObject.True); |
|
18364 | 3866 |
} |
3867 |
#else |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3868 |
FILEPOINTER f; |
612 | 3869 |
unsigned char byte; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3870 |
int ret, _buffered; |
612 | 3871 |
OBJ fp; |
3872 |
||
1133 | 3873 |
__INST(lastErrorNumber) = nil; |
12548 | 3874 |
if ((__INST(handleType) == nil) |
3875 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3876 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3877 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 3878 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 3879 |
if (((fp = __INST(handle)) != nil) |
3880 |
&& (__INST(mode) != @symbol(writeonly))) { |
|
3881 |
f = __FILEVal(fp); |
|
3882 |
||
3883 |
_buffered = (__INST(buffered) == true); |
|
3884 |
if (_buffered) { |
|
3885 |
__READING__(f) |
|
3886 |
} |
|
3887 |
__READBYTE__(ret, f, &byte, _buffered, __INST(handleType)); |
|
3888 |
if (ret > 0) { |
|
3889 |
if (__isSmallInteger(__INST(position))) { |
|
3890 |
INT np = __intVal(__INST(position)) + 1; |
|
3891 |
OBJ t; |
|
3892 |
||
3893 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
3894 |
} else { |
|
3895 |
__INST(position) = nil; /* i.e. do not know */ |
|
3896 |
} |
|
3897 |
RETURN (__mkSmallInteger(byte)); |
|
3898 |
} |
|
3899 |
||
3900 |
if (ret == 0) { |
|
3901 |
__INST(hitEOF) = true; |
|
3902 |
} else /* ret < 0 */ { |
|
3903 |
__INST(position) = nil; |
|
23538 | 3904 |
# ifdef __win32__ |
23743 | 3905 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 3906 |
# endif |
23743 | 3907 |
error = __mkSmallInteger(__threadErrno); |
3908 |
} |
|
3909 |
} |
|
612 | 3910 |
} |
18364 | 3911 |
#endif /* not SCHTEAM */ |
612 | 3912 |
%}. |
8614 | 3913 |
hitEOF ifTrue:[^ self pastEndRead]. |
16296 | 3914 |
error notNil ifTrue:[ |
23743 | 3915 |
lastErrorNumber := error. |
3916 |
^ self readError:error |
|
16296 | 3917 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
3918 |
handle isNil ifTrue:[^ self errorNotOpen]. |
612 | 3919 |
^ self errorWriteOnly |
23538 | 3920 |
|
3921 |
"Modified: / 22-11-2018 / 14:45:15 / Stefan Vogel" |
|
612 | 3922 |
! |
3923 |
||
3924 |
nextBytes:count into:anObject startingAt:start |
|
3925 |
"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
|
3926 |
bytes read or the number of bytes read, if EOF is encountered before. |
612 | 3927 |
If the receiver is some socket/pipe-like stream, an exception |
3928 |
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
|
3929 |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3930 |
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
|
3931 |
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
|
3932 |
to only read whats there. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3933 |
|
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3934 |
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
|
3935 |
this does NOT return nil on EOF, but the actual count. |
612 | 3936 |
Thus allowing read of partial blocks. |
3937 |
||
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
3938 |
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
|
3939 |
(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
|
3940 |
or an externalBytes object (with known size). |
612 | 3941 |
If anObject is a string or byteArray and reused, this provides the |
3942 |
fastest possible physical I/O (since no new objects are allocated). |
|
3943 |
||
3944 |
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
|
3945 |
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
|
3946 |
architectures (unless you prepared the buffer with care), |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3947 |
since it does not care for byte order or float representation." |
612 | 3948 |
|
16296 | 3949 |
|error| |
612 | 3950 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3951 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3952 |
int cnt, offs, ret, _buffered; |
15987 | 3953 |
int objSize, nInstBytes; |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3954 |
char *extPtr; |
7195
755c46f9b774
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
7118
diff
changeset
|
3955 |
OBJ fp; |
612 | 3956 |
|
1133 | 3957 |
__INST(lastErrorNumber) = nil; |
12548 | 3958 |
if ((__INST(handleType) == nil) |
3959 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
3960 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
3961 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 3962 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 3963 |
if (((fp = __INST(handle)) != nil) |
3964 |
&& (__INST(mode) != @symbol(writeonly)) |
|
3965 |
&& __bothSmallInteger(count, start) |
|
3966 |
) { |
|
3967 |
f = __FILEVal(fp); |
|
3968 |
||
3969 |
cnt = __intVal(count); |
|
3970 |
offs = __intVal(start) - 1; |
|
3971 |
||
3972 |
if (__isExternalBytesLike(anObject)) { |
|
3973 |
OBJ sz; |
|
3974 |
||
3975 |
nInstBytes = 0; |
|
3976 |
extPtr = (char *)(__externalBytesAddress(anObject)); |
|
3977 |
if (extPtr == NULL) goto bad; |
|
3978 |
sz = __externalBytesSize(anObject); |
|
3979 |
if (__isSmallInteger(sz)) { |
|
3980 |
objSize = __intVal(sz); |
|
3981 |
} else { |
|
3982 |
objSize = 0; /* unknown */ |
|
3983 |
} |
|
3984 |
} else { |
|
3985 |
OBJ oClass = __Class(anObject); |
|
3986 |
int nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
3987 |
||
3988 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
3989 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
|
3990 |
case BYTEARRAY: |
|
3991 |
case WORDARRAY: |
|
3992 |
case LONGARRAY: |
|
3993 |
case SWORDARRAY: |
|
3994 |
case SLONGARRAY: |
|
3995 |
case FLOATARRAY: |
|
3996 |
break; |
|
3997 |
case DOUBLEARRAY: |
|
15987 | 3998 |
#ifdef __NEED_DOUBLE_ALIGN |
23743 | 3999 |
nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1); |
15987 | 4000 |
#endif |
23743 | 4001 |
break; |
4002 |
case LONGLONGARRAY: |
|
4003 |
case SLONGLONGARRAY: |
|
16296 | 4004 |
#ifdef __NEED_LONGLONG_ALIGN |
23743 | 4005 |
nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1); |
16296 | 4006 |
#endif |
23743 | 4007 |
break; |
4008 |
default: |
|
4009 |
goto bad; |
|
4010 |
} |
|
4011 |
extPtr = (char *)0; |
|
4012 |
objSize = __Size(anObject) - nInstBytes; |
|
4013 |
} |
|
4014 |
if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) { |
|
4015 |
_buffered = (__INST(buffered) == true); |
|
4016 |
if (_buffered) { |
|
4017 |
__READING__(f); |
|
4018 |
} |
|
4019 |
||
4020 |
if (extPtr) { |
|
4021 |
__READBYTES__(ret, f, extPtr+offs, cnt, _buffered, __INST(handleType)); |
|
4022 |
} else { |
|
4023 |
/* |
|
4024 |
* on interrupt, anObject may be moved to another location. |
|
4025 |
* So we pass anObject, and the offset to the __READBYTES_OBJ__ macro. |
|
4026 |
*/ |
|
4027 |
offs += nInstBytes; |
|
4028 |
__READBYTES_OBJ__(ret, f, anObject, offs, cnt, _buffered, __INST(handleType)); |
|
4029 |
} |
|
4030 |
||
4031 |
if (ret > 0) { |
|
4032 |
if (__isSmallInteger(__INST(position))) { |
|
4033 |
INT np = __intVal(__INST(position)) + ret; |
|
4034 |
OBJ t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4035 |
} else { |
|
4036 |
__INST(position) = nil; /* i.e. do not know */ |
|
4037 |
} |
|
4038 |
RETURN (__mkSmallInteger(ret)); |
|
4039 |
} |
|
4040 |
if (ret == 0) { |
|
4041 |
__INST(hitEOF) = true; |
|
4042 |
} else /* ret < 0 */ { |
|
4043 |
__INST(position) = nil; |
|
23538 | 4044 |
# ifdef __win32__ |
23743 | 4045 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4046 |
# endif |
23743 | 4047 |
error = __mkSmallInteger(__threadErrno); |
4048 |
} |
|
4049 |
} |
|
4050 |
} |
|
612 | 4051 |
} |
4052 |
bad: ; |
|
4053 |
%}. |
|
20092 | 4054 |
hitEOF ifTrue:[^ 0]. |
16296 | 4055 |
error notNil ifTrue:[ |
23743 | 4056 |
lastErrorNumber := error. |
4057 |
^ self readError:error |
|
16296 | 4058 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4059 |
handle isNil ifTrue:[^ self errorNotOpen]. |
612 | 4060 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
4061 |
" |
|
4062 |
count not integer or arg not bit-like (String, ByteArray etc) |
|
4063 |
" |
|
4064 |
^ self primitiveFailed |
|
23538 | 4065 |
|
4066 |
"Modified: / 22-11-2018 / 14:45:28 / Stefan Vogel" |
|
92 | 4067 |
! |
4068 |
||
19219 | 4069 |
nextInt16MSB:msbFlag |
4070 |
"Read two bytes and return the value as a 16-bit signed Integer. |
|
4071 |
If msbFlag is true, value is read with most-significant byte first, |
|
4072 |
otherwise least-significant byte comes first. |
|
4073 |
A nil is returned if EOF is reached (also when EOF is hit after the first byte). |
|
4074 |
Works in both binary and text modes." |
|
4075 |
||
4076 |
|error| |
|
4077 |
%{ |
|
4078 |
OBJ fp; |
|
4079 |
||
4080 |
__INST(lastErrorNumber) = nil; |
|
4081 |
if ((__INST(handleType) == nil) |
|
4082 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4083 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
4084 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
4085 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
23743 | 4086 |
if (((fp = __INST(handle)) != nil) |
4087 |
&& (__INST(mode) != @symbol(writeonly)) |
|
4088 |
) { |
|
4089 |
FILEPOINTER f; |
|
4090 |
int ret, _buffered; |
|
4091 |
short value; |
|
4092 |
union { |
|
4093 |
unsigned char buffer[2]; |
|
4094 |
short shortVal; |
|
4095 |
} u; |
|
4096 |
||
4097 |
f = __FILEVal(fp); |
|
4098 |
_buffered = (__INST(buffered) == true); |
|
4099 |
if (_buffered) { |
|
4100 |
__READING__(f) |
|
4101 |
} |
|
4102 |
__READBYTES__(ret, f, u.buffer, 2, _buffered, __INST(handleType)); |
|
4103 |
||
4104 |
if (ret == 2) { |
|
4105 |
if (__isSmallInteger(__INST(position))) { |
|
4106 |
INT np = __intVal(__INST(position)) + 2; |
|
4107 |
OBJ t; |
|
4108 |
||
4109 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4110 |
} else { |
|
4111 |
__INST(position) = nil; /* i.e. do not know */ |
|
4112 |
} |
|
4113 |
if (msbFlag == true) { |
|
19219 | 4114 |
#if defined(__MSBFIRST__) |
23743 | 4115 |
value = u.shortVal; |
19219 | 4116 |
#else |
23743 | 4117 |
value = ((u.buffer[0] & 0xFF) << 8) | (u.buffer[1] & 0xFF); |
19219 | 4118 |
#endif |
23743 | 4119 |
} else { |
19219 | 4120 |
#if defined(__LSBFIRST__) |
23743 | 4121 |
value = u.shortVal; |
19219 | 4122 |
#else |
23743 | 4123 |
value = ((u.buffer[1] & 0xFF) << 8) | (u.buffer[0] & 0xFF); |
19219 | 4124 |
#endif |
23743 | 4125 |
} |
4126 |
RETURN (__mkSmallInteger(value)); |
|
4127 |
} |
|
4128 |
||
4129 |
if (ret < 0) { |
|
4130 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 4131 |
# ifdef __win32__ |
23743 | 4132 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4133 |
# endif |
23743 | 4134 |
error = __mkSmallInteger(__threadErrno); |
4135 |
} else /* ret == 0 */ { |
|
4136 |
__INST(hitEOF) = true; |
|
4137 |
} |
|
4138 |
} |
|
19219 | 4139 |
} |
4140 |
%}. |
|
4141 |
hitEOF ifTrue:[^ self pastEndRead]. |
|
4142 |
handle isNil ifTrue:[^ self errorNotOpen]. |
|
4143 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
4144 |
lastErrorNumber := error. |
|
4145 |
^ self readError:error. |
|
23538 | 4146 |
|
4147 |
"Modified: / 22-11-2018 / 14:45:57 / Stefan Vogel" |
|
612 | 4148 |
! |
4149 |
||
19213
b990f28738b2
refactored to get rid of implizit sizeinnextPutXX:MSM:methods
Claus Gittinger <cg@exept.de>
parents:
19072
diff
changeset
|
4150 |
nextInt32MSB:msbFlag |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
4151 |
"Read four bytes and return the value as a 32-bit signed Integer, |
612 | 4152 |
which may be a LargeInteger. |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
4153 |
If msbFlag is true, value is read with most-significant byte first, |
612 | 4154 |
otherwise least-significant byte comes first. |
4155 |
A nil is returned, if EOF is hit before all 4 bytes have been read. |
|
4156 |
Works in both binary and text modes." |
|
4157 |
||
16296 | 4158 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4159 |
%{ |
612 | 4160 |
OBJ fp; |
4161 |
||
1133 | 4162 |
__INST(lastErrorNumber) = nil; |
12548 | 4163 |
if ((__INST(handleType) == nil) |
4164 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4165 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4166 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 4167 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 4168 |
if (((fp = __INST(handle)) != nil) |
4169 |
&& (__INST(mode) != @symbol(writeonly)) |
|
4170 |
) { |
|
4171 |
FILEPOINTER f; |
|
4172 |
int ret, _buffered; |
|
4173 |
int value; |
|
4174 |
union { |
|
4175 |
unsigned char buffer[4]; |
|
4176 |
int intVal; |
|
4177 |
} u; |
|
4178 |
||
4179 |
f = __FILEVal(fp); |
|
4180 |
_buffered = (__INST(buffered) == true); |
|
4181 |
if (_buffered) { |
|
4182 |
__READING__(f) |
|
4183 |
} |
|
4184 |
__READBYTES__(ret, f, u.buffer, 4, _buffered, __INST(handleType)); |
|
4185 |
||
4186 |
if (ret == 4) { |
|
4187 |
if (__isSmallInteger(__INST(position))) { |
|
4188 |
INT np = __intVal(__INST(position)) + 4; |
|
4189 |
OBJ t; |
|
4190 |
||
4191 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4192 |
} else { |
|
4193 |
__INST(position) = nil; /* i.e. do not know */ |
|
4194 |
} |
|
4195 |
if (msbFlag == true) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4196 |
#if defined(__MSBFIRST__) |
23743 | 4197 |
value = u.intVal; |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4198 |
#else |
23743 | 4199 |
value = (u.buffer[0] & 0xFF); |
4200 |
value = (value << 8) | (u.buffer[1] & 0xFF); |
|
4201 |
value = (value << 8) | (u.buffer[2] & 0xFF); |
|
4202 |
value = (value << 8) | (u.buffer[3] & 0xFF); |
|
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4203 |
#endif |
23743 | 4204 |
} else { |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4205 |
#if defined(__LSBFIRST__) |
23743 | 4206 |
value = u.intVal; |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4207 |
#else |
23743 | 4208 |
value = (u.buffer[3] & 0xFF); |
4209 |
value = (value << 8) | (u.buffer[2] & 0xFF); |
|
4210 |
value = (value << 8) | (u.buffer[1] & 0xFF); |
|
4211 |
value = (value << 8) | (u.buffer[0] & 0xFF); |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4212 |
#endif |
23743 | 4213 |
} |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4214 |
#if __POINTER_SIZE__ == 8 |
23743 | 4215 |
RETURN ( __mkSmallInteger(value)); |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4216 |
#else |
23743 | 4217 |
RETURN ( __MKINT(value) ); |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4218 |
#endif |
23743 | 4219 |
} |
4220 |
||
4221 |
if (ret < 0) { |
|
4222 |
__INST(position) = nil; |
|
23538 | 4223 |
# ifdef __win32__ |
23743 | 4224 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4225 |
# endif |
23743 | 4226 |
error = __mkSmallInteger(__threadErrno); |
4227 |
} else /* ret == 0 */ { |
|
4228 |
__INST(hitEOF) = true; |
|
4229 |
} |
|
4230 |
} |
|
612 | 4231 |
} |
4232 |
%}. |
|
8614 | 4233 |
hitEOF ifTrue:[^ self pastEndRead]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4234 |
handle isNil ifTrue:[^ self errorNotOpen]. |
612 | 4235 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
16296 | 4236 |
lastErrorNumber := error. |
4237 |
^ self readError:error. |
|
23538 | 4238 |
|
4239 |
"Modified: / 22-11-2018 / 14:46:05 / Stefan Vogel" |
|
362 | 4240 |
! |
4241 |
||
19219 | 4242 |
nextUnsignedInt16MSB:msbFlag |
4243 |
"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
|
4244 |
If msbFlag is true, value is read with most-significant byte first, |
612 | 4245 |
otherwise least-significant byte comes first. |
4246 |
A nil is returned if EOF is reached (also when EOF is hit after the first byte). |
|
4247 |
Works in both binary and text modes." |
|
4248 |
||
16296 | 4249 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4250 |
%{ |
612 | 4251 |
OBJ fp; |
4252 |
||
1133 | 4253 |
__INST(lastErrorNumber) = nil; |
12548 | 4254 |
if ((__INST(handleType) == nil) |
4255 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4256 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4257 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 4258 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 4259 |
if (((fp = __INST(handle)) != nil) |
4260 |
&& (__INST(mode) != @symbol(writeonly)) |
|
4261 |
) { |
|
4262 |
FILEPOINTER f; |
|
4263 |
int ret, _buffered; |
|
4264 |
unsigned int value; |
|
4265 |
union { |
|
4266 |
unsigned char buffer[2]; |
|
4267 |
unsigned short shortVal; |
|
4268 |
} u; |
|
4269 |
||
4270 |
f = __FILEVal(fp); |
|
4271 |
_buffered = (__INST(buffered) == true); |
|
4272 |
if (_buffered) { |
|
4273 |
__READING__(f) |
|
4274 |
} |
|
4275 |
__READBYTES__(ret, f, u.buffer, 2, _buffered, __INST(handleType)); |
|
4276 |
||
4277 |
if (ret == 2) { |
|
4278 |
if (__isSmallInteger(__INST(position))) { |
|
4279 |
INT np = __intVal(__INST(position)) + 2; |
|
4280 |
OBJ t; |
|
4281 |
||
4282 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4283 |
} else { |
|
4284 |
__INST(position) = nil; /* i.e. do not know */ |
|
4285 |
} |
|
4286 |
if (msbFlag == true) { |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4287 |
#if defined(__MSBFIRST__) |
23743 | 4288 |
value = u.shortVal; |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4289 |
#else |
23743 | 4290 |
value = (u.buffer[0] << 8) | u.buffer[1]; |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4291 |
#endif |
23743 | 4292 |
} else { |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4293 |
#if defined(__LSBFIRST__) |
23743 | 4294 |
value = u.shortVal; |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4295 |
#else |
23743 | 4296 |
value = (u.buffer[1] << 8) | u.buffer[0]; |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4297 |
#endif |
23743 | 4298 |
} |
4299 |
RETURN (__mkSmallInteger(value)); |
|
4300 |
} |
|
4301 |
||
4302 |
if (ret < 0) { |
|
4303 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 4304 |
# ifdef __win32__ |
23743 | 4305 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4306 |
# endif |
23743 | 4307 |
error = __mkSmallInteger(__threadErrno); |
4308 |
} else /* ret == 0 */ { |
|
4309 |
__INST(hitEOF) = true; |
|
4310 |
} |
|
4311 |
} |
|
612 | 4312 |
} |
4313 |
%}. |
|
8614 | 4314 |
hitEOF ifTrue:[^ self pastEndRead]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4315 |
handle isNil ifTrue:[^ self errorNotOpen]. |
612 | 4316 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
16296 | 4317 |
lastErrorNumber := error. |
4318 |
^ self readError:error. |
|
23538 | 4319 |
|
4320 |
"Modified: / 22-11-2018 / 14:49:05 / Stefan Vogel" |
|
612 | 4321 |
! |
4322 |
||
19213
b990f28738b2
refactored to get rid of implizit sizeinnextPutXX:MSM:methods
Claus Gittinger <cg@exept.de>
parents:
19072
diff
changeset
|
4323 |
nextUnsignedInt32MSB:msbFlag |
612 | 4324 |
"Read four bytes and return the value as a 32-bit unsigned Integer, which may be |
4325 |
a LargeInteger. |
|
4326 |
If msbFlag is true, value is read with most-significant byte first, otherwise |
|
4327 |
least-significant byte comes first. |
|
4328 |
A nil is returned, if endOfFile occurs before all 4 bytes have been read. |
|
4329 |
Works in both binary and text modes." |
|
4330 |
||
16296 | 4331 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4332 |
%{ |
612 | 4333 |
OBJ fp; |
4334 |
||
1133 | 4335 |
__INST(lastErrorNumber) = nil; |
12548 | 4336 |
if ((__INST(handleType) == nil) |
4337 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4338 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4339 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 4340 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 4341 |
if (((fp = __INST(handle)) != nil) |
4342 |
&& (__INST(mode) != @symbol(writeonly)) |
|
4343 |
) { |
|
4344 |
FILEPOINTER f; |
|
4345 |
int ret, _buffered; |
|
4346 |
unsigned INT value; |
|
4347 |
union { |
|
4348 |
unsigned char buffer[4]; |
|
4349 |
unsigned int intVal; |
|
4350 |
} u; |
|
4351 |
||
4352 |
f = __FILEVal(fp); |
|
4353 |
_buffered = (__INST(buffered) == true); |
|
4354 |
if (_buffered) { |
|
4355 |
__READING__(f) |
|
4356 |
} |
|
4357 |
__READBYTES__(ret, f, u.buffer, 4, _buffered, __INST(handleType)); |
|
4358 |
||
4359 |
if (ret == 4) { |
|
4360 |
if (__isSmallInteger(__INST(position))) { |
|
4361 |
INT np = __intVal(__INST(position)) + 4; |
|
4362 |
OBJ t; |
|
4363 |
||
4364 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4365 |
} else { |
|
4366 |
__INST(position) = nil; /* i.e. do not know */ |
|
4367 |
} |
|
4368 |
if (msbFlag == true) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4369 |
#if defined(__MSBFIRST__) |
23743 | 4370 |
value = u.intVal; |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4371 |
#else |
23743 | 4372 |
value = u.buffer[0]; |
4373 |
value = (value << 8) | u.buffer[1]; |
|
4374 |
value = (value << 8) | u.buffer[2]; |
|
4375 |
value = (value << 8) | u.buffer[3]; |
|
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4376 |
#endif |
23743 | 4377 |
} else { |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4378 |
#if defined(__LSBFIRST__) |
23743 | 4379 |
value = u.intVal; |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4380 |
#else |
23743 | 4381 |
value = u.buffer[3]; |
4382 |
value = (value << 8) | u.buffer[2]; |
|
4383 |
value = (value << 8) | u.buffer[1]; |
|
4384 |
value = (value << 8) | u.buffer[0]; |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4385 |
#endif |
23743 | 4386 |
} |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4387 |
#if __POINTER_SIZE__ == 8 |
23743 | 4388 |
value &= 0xFFFFFFFF; |
4389 |
RETURN (__mkSmallInteger(value)); |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4390 |
#else |
23743 | 4391 |
if (value <= _MAX_INT) { |
4392 |
RETURN (__mkSmallInteger(value)); |
|
4393 |
} |
|
4394 |
RETURN (__MKULARGEINT(value) ); |
|
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
4395 |
#endif |
23743 | 4396 |
} |
4397 |
||
4398 |
if (ret < 0) { |
|
4399 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 4400 |
# ifdef __win32__ |
23743 | 4401 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4402 |
# endif |
23743 | 4403 |
error = __mkSmallInteger(__threadErrno); |
4404 |
} else /* ret == 0 */ { |
|
4405 |
__INST(hitEOF) = true; |
|
4406 |
} |
|
4407 |
} |
|
612 | 4408 |
} |
4409 |
%}. |
|
8614 | 4410 |
hitEOF ifTrue:[^ self pastEndRead]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4411 |
handle isNil ifTrue:[^ self errorNotOpen]. |
612 | 4412 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
16296 | 4413 |
lastErrorNumber := error. |
4414 |
^ self readError:error. |
|
23538 | 4415 |
|
4416 |
"Modified: / 22-11-2018 / 14:49:23 / Stefan Vogel" |
|
612 | 4417 |
! |
4418 |
||
4419 |
nextWord |
|
15452 | 4420 |
<resource: #obsolete> |
612 | 4421 |
"in text-mode: |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4422 |
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
|
4423 |
return a string containing those characters. |
612 | 4424 |
in binary-mode: |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4425 |
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
|
4426 |
unsigned Integer (for compatibility with other smalltalks)" |
612 | 4427 |
|
4428 |
binary ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4429 |
self obsoleteMethodWarning:'use #nextUnsignedInt16MSB:true'. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4430 |
^ self nextUnsignedInt16MSB:true |
92 | 4431 |
]. |
14518 | 4432 |
self obsoleteMethodWarning:'use #nextAlphaNumericWord'. |
612 | 4433 |
^ self nextAlphaNumericWord |
4434 |
! ! |
|
4435 |
||
4436 |
!ExternalStream methodsFor:'non homogenous writing'! |
|
4437 |
||
4438 |
nextPutByte:aByteValue |
|
4439 |
"write a byte. |
|
4440 |
Works in both binary and text modes." |
|
4441 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4442 |
|error| |
16296 | 4443 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4444 |
%{ |
7875
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
4445 |
OBJ fp; |
612 | 4446 |
|
1133 | 4447 |
__INST(lastErrorNumber) = nil; |
12548 | 4448 |
if ((__INST(handleType) == nil) |
4449 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4450 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4451 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 4452 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 4453 |
if (((fp = __INST(handle)) != nil) |
4454 |
&& (__INST(mode) != @symbol(readonly)) |
|
4455 |
&& __isSmallInteger(aByteValue) |
|
4456 |
||
4457 |
) { |
|
4458 |
int _buffered = (__INST(buffered) == true); |
|
4459 |
FILEPOINTER f = __FILEVal(fp); |
|
4460 |
char c = __intVal(aByteValue); |
|
4461 |
int cnt; |
|
4462 |
||
4463 |
if (_buffered) { |
|
4464 |
__WRITING__(f) |
|
4465 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4466 |
#ifdef __win32__ |
23743 | 4467 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
4468 |
cnt = __win32_fwrite(&c, 1, 1, f); |
|
4469 |
} else |
|
9053
f3f3d48d6f44
fix writing to stdout/stderr for winstx non-console operation
Claus Gittinger <cg@exept.de>
parents:
9024
diff
changeset
|
4470 |
#endif |
23743 | 4471 |
{ |
4472 |
__WRITEBYTE__(cnt, f, &c, _buffered, __INST(handleType)); |
|
4473 |
} |
|
4474 |
if (cnt == 1) { |
|
4475 |
if (__isSmallInteger(__INST(position))) { |
|
4476 |
INT np = __intVal(__INST(position)) + 1; |
|
4477 |
OBJ t; |
|
4478 |
||
4479 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4480 |
} else { |
|
4481 |
__INST(position) = nil; /* i.e. do not know */ |
|
4482 |
} |
|
4483 |
RETURN (self); |
|
4484 |
} |
|
4485 |
if (cnt < 0) { |
|
4486 |
__INST(position) = nil; /* i.e. do not know */ |
|
4487 |
} |
|
23538 | 4488 |
# ifdef __win32__ |
23743 | 4489 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4490 |
# endif |
23743 | 4491 |
error = __mkSmallInteger(__threadErrno); |
4492 |
} |
|
612 | 4493 |
} |
4494 |
%}. |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4495 |
handle isNil ifTrue:[self errorNotOpen. ^ self]. |
7801
d930c353588d
writeError: care for EWOULDBLOCK in nonBlocking case.
penk
parents:
7737
diff
changeset
|
4496 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
16296 | 4497 |
lastErrorNumber := error. |
4498 |
self writeError:error. |
|
23538 | 4499 |
|
4500 |
"Modified: / 22-11-2018 / 14:47:34 / Stefan Vogel" |
|
612 | 4501 |
! |
4502 |
||
19219 | 4503 |
nextPutInt16:anIntegerOrCharacter MSB:msbFlag |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4504 |
"Write the argument, anIntegerOrCharacter as a short (two bytes). |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4505 |
If msbFlag is true, data is written most-significant byte first; |
19615 | 4506 |
otherwise least first. |
22266 | 4507 |
Notice that integers in the range 16r-8000 to +16rFFFF can be written |
19615 | 4508 |
(i.e. both signed and unsigned int32 values can be written. |
19219 | 4509 |
Works in both binary and text modes." |
4510 |
||
4511 |
|error| |
|
4512 |
%{ |
|
4513 |
int num; |
|
4514 |
union { |
|
23743 | 4515 |
char bytes[2]; |
4516 |
short shortVal; |
|
19219 | 4517 |
} u; |
4518 |
OBJ fp; |
|
4519 |
||
4520 |
__INST(lastErrorNumber) = nil; |
|
4521 |
if ((__INST(handleType) == nil) |
|
4522 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4523 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
4524 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
4525 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
23743 | 4526 |
if (((fp = __INST(handle)) != nil) |
4527 |
&& (__INST(mode) != @symbol(readonly)) |
|
4528 |
) { |
|
4529 |
FILEPOINTER f = __FILEVal(fp); |
|
4530 |
int _buffered = (__INST(buffered) == true); |
|
4531 |
int cnt; |
|
4532 |
||
4533 |
if (__isSmallInteger(anIntegerOrCharacter)) { |
|
4534 |
num = __intVal(anIntegerOrCharacter); |
|
4535 |
} else if (__isCharacter(anIntegerOrCharacter)) { |
|
4536 |
num = __smallIntegerVal(__characterVal(anIntegerOrCharacter)); |
|
4537 |
} else |
|
4538 |
goto out; |
|
4539 |
||
4540 |
if (msbFlag == true) { |
|
19219 | 4541 |
#if defined(__MSBFIRST__) |
23743 | 4542 |
u.shortVal = num; |
19219 | 4543 |
#else |
23743 | 4544 |
u.bytes[0] = (num >> 8) & 0xFF; |
4545 |
u.bytes[1] = num & 0xFF; |
|
19219 | 4546 |
#endif |
23743 | 4547 |
} else { |
19219 | 4548 |
#if defined(__LSBFIRST__) |
23743 | 4549 |
u.shortVal = num; |
19219 | 4550 |
#else |
23743 | 4551 |
u.bytes[1] = (num >> 8) & 0xFF; |
4552 |
u.bytes[0] = num & 0xFF; |
|
19219 | 4553 |
#endif |
23743 | 4554 |
} |
4555 |
||
4556 |
if (_buffered) { |
|
4557 |
__WRITING__(f) |
|
4558 |
} |
|
4559 |
__WRITEBYTES__(cnt, f, u.bytes, 2, _buffered, __INST(handleType)); |
|
4560 |
||
4561 |
if (cnt == 2) { |
|
4562 |
if (__isSmallInteger(__INST(position))) { |
|
4563 |
INT np = __intVal(__INST(position)) + 2; |
|
4564 |
OBJ t; |
|
4565 |
||
4566 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4567 |
} else { |
|
4568 |
__INST(position) = nil; /* i.e. do not know */ |
|
4569 |
} |
|
4570 |
RETURN ( self ); |
|
4571 |
} |
|
4572 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 4573 |
# ifdef __win32__ |
23743 | 4574 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4575 |
# endif |
23743 | 4576 |
error = __mkSmallInteger(__threadErrno); |
4577 |
} |
|
19219 | 4578 |
} |
4579 |
out:; |
|
4580 |
%}. |
|
4581 |
error notNil ifTrue:[ |
|
23743 | 4582 |
lastErrorNumber := error. |
4583 |
self writeError:error. |
|
4584 |
^ self |
|
19219 | 4585 |
]. |
4586 |
handle isNil ifTrue:[self errorNotOpen. ^ self]. |
|
4587 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
|
4588 |
self argumentMustBeInteger |
|
22266 | 4589 |
|
4590 |
"Modified: / 19-09-2017 / 16:32:29 / stefan" |
|
23538 | 4591 |
"Modified: / 22-11-2018 / 14:48:14 / Stefan Vogel" |
19219 | 4592 |
! |
4593 |
||
19615 | 4594 |
nextPutInt16LSB:anIntegerOrCharacter |
4595 |
"do not remove. |
|
4596 |
See #patchByteOrderOptimizedMethods" |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4597 |
|
19615 | 4598 |
self nextPutInt16:anIntegerOrCharacter MSB:false |
4599 |
! |
|
4600 |
||
4601 |
nextPutInt16MSB:anIntegerOrCharacter |
|
4602 |
"do not remove. |
|
4603 |
See #patchByteOrderOptimizedMethods" |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4604 |
|
19615 | 4605 |
self nextPutInt16:anIntegerOrCharacter MSB:true |
4606 |
! |
|
4607 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4608 |
nextPutInt16NATIVE:anIntegerOrCharacter |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4609 |
"Write the argument, anIntegerOrCharacter as a short (two bytes) in native byte order. |
23934 | 4610 |
This is the CPU-specific byte order (LSB on x86 and VAX, MSB on sparc, and possibly on ARM). |
22266 | 4611 |
Notice that integers in the range 16r-8000 to +16rFFFF can be written |
19615 | 4612 |
(i.e. both signed and unsigned int32 values can be written. |
4613 |
Works in both binary and text modes." |
|
4614 |
||
4615 |
|error| |
|
4616 |
%{ |
|
4617 |
int num; |
|
4618 |
union { |
|
25136 | 4619 |
char bytes[2]; |
4620 |
short shortVal; |
|
19615 | 4621 |
} u; |
4622 |
OBJ fp; |
|
4623 |
||
4624 |
__INST(lastErrorNumber) = nil; |
|
4625 |
if ((__INST(handleType) == nil) |
|
4626 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4627 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
4628 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
4629 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
25136 | 4630 |
if (((fp = __INST(handle)) != nil) |
4631 |
&& (__INST(mode) != @symbol(readonly)) |
|
4632 |
) { |
|
4633 |
FILEPOINTER f = __FILEVal(fp); |
|
4634 |
int _buffered = (__INST(buffered) == true); |
|
4635 |
int cnt; |
|
4636 |
||
4637 |
if (__isSmallInteger(anIntegerOrCharacter)) { |
|
4638 |
num = __intVal(anIntegerOrCharacter); |
|
4639 |
} else if (__isCharacter(anIntegerOrCharacter)) { |
|
4640 |
num = __smallIntegerVal(__characterVal(anIntegerOrCharacter)); |
|
4641 |
} else |
|
4642 |
goto out; |
|
4643 |
||
4644 |
u.shortVal = num; |
|
4645 |
||
4646 |
if (_buffered) { |
|
4647 |
__WRITING__(f) |
|
4648 |
} |
|
4649 |
__WRITEBYTES__(cnt, f, u.bytes, 2, _buffered, __INST(handleType)); |
|
4650 |
||
4651 |
if (cnt == 2) { |
|
4652 |
if (__isSmallInteger(__INST(position))) { |
|
4653 |
INT np = __intVal(__INST(position)) + 2; |
|
4654 |
OBJ t; |
|
4655 |
||
4656 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4657 |
} else { |
|
4658 |
__INST(position) = nil; /* i.e. do not know */ |
|
4659 |
} |
|
4660 |
RETURN ( self ); |
|
4661 |
} |
|
4662 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 4663 |
# ifdef __win32__ |
25136 | 4664 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4665 |
# endif |
25136 | 4666 |
error = __mkSmallInteger(__threadErrno); |
4667 |
} |
|
19615 | 4668 |
} |
4669 |
out:; |
|
4670 |
%}. |
|
4671 |
self nextPutInt16:anIntegerOrCharacter MSB:(UninterpretedBytes isBigEndian). |
|
22266 | 4672 |
|
4673 |
"Modified: / 19-09-2017 / 16:32:40 / stefan" |
|
23538 | 4674 |
"Modified: / 22-11-2018 / 14:48:23 / Stefan Vogel" |
23934 | 4675 |
"Modified: / 17-03-2019 / 14:52:06 / Claus Gittinger" |
19615 | 4676 |
! |
4677 |
||
19213
b990f28738b2
refactored to get rid of implizit sizeinnextPutXX:MSM:methods
Claus Gittinger <cg@exept.de>
parents:
19072
diff
changeset
|
4678 |
nextPutInt32:aNumber MSB:msbFlag |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4679 |
"Write the argument, aNumber as a long (four bytes). |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4680 |
If msbFlag is true, data is written most-significant byte first; |
19615 | 4681 |
otherwise least first. |
22266 | 4682 |
Notice that integers in the range 16r-80000000 to +16rFFFFFFFF can be written |
19615 | 4683 |
(i.e. both signed and unsigned int32 values can be written. |
612 | 4684 |
Works in both binary and text modes." |
4685 |
||
16296 | 4686 |
|error| |
4687 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4688 |
%{ |
612 | 4689 |
int num; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4690 |
union { |
23743 | 4691 |
char bytes[4]; |
4692 |
int intVal; |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4693 |
} u; |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4694 |
OBJ fp; |
612 | 4695 |
|
1133 | 4696 |
__INST(lastErrorNumber) = nil; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4697 |
if (__isSmallInteger(aNumber)) { |
23743 | 4698 |
num = __intVal(aNumber); |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4699 |
} else { |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4700 |
#if __POINTER_SIZE__ == 8 |
23743 | 4701 |
// always more than 4-bytes |
4702 |
goto badArg; |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4703 |
#else |
23743 | 4704 |
num = __longIntVal(aNumber); |
4705 |
if (num == 0) { |
|
4706 |
num = __signedLongIntVal(aNumber); |
|
4707 |
if (num == 0) { |
|
4708 |
/* bad arg or out-of-range integer |
|
4709 |
* (handled by the fallBack code) |
|
4710 |
*/ |
|
4711 |
goto badArg; |
|
4712 |
} |
|
4713 |
} |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4714 |
#endif |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4715 |
} |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4716 |
|
12548 | 4717 |
if ((__INST(handleType) == nil) |
4718 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4719 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4720 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 4721 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 4722 |
if (((fp = __INST(handle)) != nil) |
4723 |
&& (__INST(mode) != @symbol(readonly)) |
|
4724 |
) { |
|
4725 |
int _buffered = (__INST(buffered) == true); |
|
4726 |
FILEPOINTER f = __FILEVal(fp); |
|
4727 |
int cnt; |
|
4728 |
||
4729 |
if (msbFlag == true) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4730 |
#if defined(__MSBFIRST__) |
23743 | 4731 |
u.intVal = num; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4732 |
#else |
23743 | 4733 |
u.bytes[0] = (num >> 24) & 0xFF; |
4734 |
u.bytes[1] = (num >> 16) & 0xFF; |
|
4735 |
u.bytes[2] = (num >> 8) & 0xFF; |
|
4736 |
u.bytes[3] = num & 0xFF; |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4737 |
#endif |
23743 | 4738 |
} else { |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
4739 |
#if defined(__LSBFIRST__) |
23743 | 4740 |
u.intVal = num; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4741 |
#else |
23743 | 4742 |
u.bytes[3] = (num >> 24) & 0xFF; |
4743 |
u.bytes[2] = (num >> 16) & 0xFF; |
|
4744 |
u.bytes[1] = (num >> 8) & 0xFF; |
|
4745 |
u.bytes[0] = num & 0xFF; |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4746 |
#endif |
23743 | 4747 |
} |
4748 |
||
4749 |
if (_buffered) { |
|
4750 |
__WRITING__(f) |
|
4751 |
} |
|
4752 |
__WRITEBYTES__(cnt, f, u.bytes, 4, _buffered, __INST(handleType)); |
|
4753 |
||
4754 |
if (cnt == 4) { |
|
4755 |
if (__isSmallInteger(__INST(position))) { |
|
4756 |
INT np = __intVal(__INST(position)) + 4; |
|
4757 |
OBJ t; |
|
4758 |
||
4759 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4760 |
} else { |
|
4761 |
__INST(position) = nil; /* i.e. do not know */ |
|
4762 |
} |
|
4763 |
RETURN ( self ); |
|
4764 |
} |
|
4765 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 4766 |
# ifdef __win32__ |
23743 | 4767 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4768 |
# endif |
23743 | 4769 |
error = __mkSmallInteger(__threadErrno); |
4770 |
} |
|
612 | 4771 |
} |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4772 |
badArg: ; |
612 | 4773 |
%}. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
4774 |
handle isNil ifTrue:[self errorNotOpen. ^ self]. |
7801
d930c353588d
writeError: care for EWOULDBLOCK in nonBlocking case.
penk
parents:
7737
diff
changeset
|
4775 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
16296 | 4776 |
error notNil ifTrue:[ |
23743 | 4777 |
lastErrorNumber := error. |
4778 |
self writeError:error. |
|
4779 |
^ self |
|
16296 | 4780 |
]. |
612 | 4781 |
|
4782 |
aNumber isInteger ifTrue:[ |
|
23743 | 4783 |
^ super nextPutInt32:aNumber MSB:msbFlag |
92 | 4784 |
]. |
612 | 4785 |
self argumentMustBeInteger |
22266 | 4786 |
|
4787 |
"Modified: / 19-09-2017 / 16:32:50 / stefan" |
|
23538 | 4788 |
"Modified: / 22-11-2018 / 14:48:29 / Stefan Vogel" |
19615 | 4789 |
! |
4790 |
||
4791 |
nextPutInt32LSB:anIntegerOrCharacter |
|
4792 |
"do not remove. |
|
4793 |
See #patchByteOrderOptimizedMethods" |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4794 |
|
19615 | 4795 |
self nextPutInt32:anIntegerOrCharacter MSB:false |
4796 |
! |
|
4797 |
||
4798 |
nextPutInt32MSB:anIntegerOrCharacter |
|
4799 |
"do not remove. |
|
4800 |
See #patchByteOrderOptimizedMethods" |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4801 |
|
19615 | 4802 |
self nextPutInt32:anIntegerOrCharacter MSB:true |
4803 |
! |
|
4804 |
||
4805 |
nextPutInt32NATIVE:anInteger |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4806 |
"Write the argument, anInteger as a long (four bytes) in native byte order. |
23934 | 4807 |
This is the CPU-specific byte order (LSB on x86 and VAX, MSB on sparc and possibly on ARM). |
22266 | 4808 |
Notice that integers in the range 16r-80000000 to +16rFFFFFFFF can be written |
19615 | 4809 |
(i.e. both signed and unsigned int32 values can be written. |
4810 |
Works in both binary and text modes. |
|
4811 |
Notice: this message should not be sent explicitly by ANY program. |
|
25136 | 4812 |
the following implementation replaces the code of either nextPutInt32MSB or LSB |
4813 |
dynamically (see #initialize on the class side)" |
|
19615 | 4814 |
|
4815 |
|error| |
|
4816 |
||
4817 |
%{ |
|
4818 |
int num; |
|
4819 |
union { |
|
25136 | 4820 |
char bytes[4]; |
4821 |
int intVal; |
|
19615 | 4822 |
} u; |
4823 |
OBJ fp; |
|
4824 |
||
4825 |
__INST(lastErrorNumber) = nil; |
|
4826 |
if (__isSmallInteger(anInteger)) { |
|
25136 | 4827 |
num = __intVal(anInteger); |
19615 | 4828 |
} else { |
4829 |
#if __POINTER_SIZE__ == 8 |
|
25136 | 4830 |
// always more than 4-bytes |
4831 |
goto badArg; |
|
19615 | 4832 |
#else |
25136 | 4833 |
num = __longIntVal(anInteger); |
4834 |
if (num == 0) { |
|
4835 |
num = __signedLongIntVal(anInteger); |
|
4836 |
if (num == 0) { |
|
4837 |
/* bad arg or out-of-range integer |
|
4838 |
* (handled by the fallBack code) |
|
4839 |
*/ |
|
4840 |
goto badArg; |
|
4841 |
} |
|
4842 |
} |
|
19615 | 4843 |
#endif |
4844 |
} |
|
4845 |
||
4846 |
if ((__INST(handleType) == nil) |
|
4847 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
4848 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
4849 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
4850 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
25136 | 4851 |
if (((fp = __INST(handle)) != nil) |
4852 |
&& (__INST(mode) != @symbol(readonly)) |
|
4853 |
) { |
|
4854 |
int _buffered = (__INST(buffered) == true); |
|
4855 |
FILEPOINTER f = __FILEVal(fp); |
|
4856 |
int cnt; |
|
4857 |
||
4858 |
u.intVal = num; |
|
4859 |
if (_buffered) { |
|
4860 |
__WRITING__(f) |
|
4861 |
} |
|
4862 |
__WRITEBYTES__(cnt, f, u.bytes, 4, _buffered, __INST(handleType)); |
|
4863 |
||
4864 |
if (cnt == 4) { |
|
4865 |
if (__isSmallInteger(__INST(position))) { |
|
4866 |
INT np = __intVal(__INST(position)) + 4; |
|
4867 |
OBJ t; |
|
4868 |
||
4869 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
4870 |
} else { |
|
4871 |
__INST(position) = nil; /* i.e. do not know */ |
|
4872 |
} |
|
4873 |
RETURN ( self ); |
|
4874 |
} |
|
4875 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 4876 |
# ifdef __win32__ |
25136 | 4877 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 4878 |
# endif |
25136 | 4879 |
error = __mkSmallInteger(__threadErrno); |
4880 |
} |
|
19615 | 4881 |
} |
4882 |
badArg: ; |
|
4883 |
%}. |
|
4884 |
self nextPutInt32:anInteger MSB:(UninterpretedBytes isBigEndian) |
|
22266 | 4885 |
|
4886 |
"Modified: / 19-09-2017 / 16:32:59 / stefan" |
|
23538 | 4887 |
"Modified: / 22-11-2018 / 14:48:41 / Stefan Vogel" |
23934 | 4888 |
"Modified: / 17-03-2019 / 14:52:23 / Claus Gittinger" |
20092 | 4889 |
! |
4890 |
||
4891 |
nextPutUtf16:aCharacter |
|
4892 |
"append my UTF-16 MSB representation to the argument, aStream. |
|
4893 |
UTF-16 can encode only characters with code points between 0 to 16r10FFFF." |
|
4894 |
||
4895 |
self nextPutUtf16Bytes:aCharacter MSB:true |
|
4896 |
||
4897 |
" |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4898 |
(FileStream newTemporary |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4899 |
nextPutUtf16:$B; |
25134 | 4900 |
nextPutUtf16:$Ä; |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4901 |
nextPutUtf16:(Character codePoint:16r10CCCC); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4902 |
reset; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4903 |
binary; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4904 |
contents) |
20092 | 4905 |
" |
4906 |
! |
|
4907 |
||
4908 |
nextPutUtf16:aCharacter MSB:msbFlag |
|
4909 |
"append my UTF-16 MSB representation to the argument, aStream. |
|
4910 |
UTF-16 can encode only characters with code points between 0 to 16r10FFFF." |
|
4911 |
||
4912 |
self nextPutUtf16Bytes:aCharacter MSB:msbFlag |
|
10 | 4913 |
! ! |
612 | 4914 |
|
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4915 |
!ExternalStream methodsFor:'positioning'! |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4916 |
|
15619 | 4917 |
position |
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4918 |
self subclassResponsibility |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4919 |
! |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4920 |
|
15619 | 4921 |
position:index0Based |
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4922 |
self subclassResponsibility |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4923 |
! ! |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4924 |
|
12631 | 4925 |
!ExternalStream methodsFor:'printing & storing'! |
4926 |
||
4927 |
printOn:aStream |
|
14068 | 4928 |
aStream |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4929 |
nextPutAll:self className; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
4930 |
nextPut:$(. |
22245 | 4931 |
handleType printOn:aStream. |
4932 |
aStream nextPutAll:':('. |
|
12631 | 4933 |
handle printOn:aStream. |
4934 |
aStream nextPutAll:'))' |
|
4935 |
! ! |
|
4936 |
||
612 | 4937 |
!ExternalStream methodsFor:'private'! |
4938 |
||
4939 |
clearEOF |
|
4940 |
hitEOF := false |
|
20987 | 4941 |
! |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4942 |
|
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4943 |
closeFile |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4944 |
"low level close - may be redefined in subclasses |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4945 |
Don't send this message, send #close instead" |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4946 |
|
12674 | 4947 |
|fp error| |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4948 |
|
20679 | 4949 |
handle isNil ifTrue:[ |
23743 | 4950 |
^ self. |
20679 | 4951 |
]. |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4952 |
fp := handle. |
19767 | 4953 |
"/ (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
|
4954 |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
4955 |
%{ |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4956 |
int rslt; |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4957 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4958 |
if (__INST(handleType) == @symbol(socketHandle)) { |
23743 | 4959 |
SOCKET sock = (SOCKET)(__FILEVal(fp)); |
4960 |
||
23879 | 4961 |
// whether the close() will be successful or not - the handle is invalid now! |
4962 |
__INST(handle) = nil; |
|
4963 |
||
23743 | 4964 |
if (@global(FileOpenTrace) == true) { |
4965 |
fprintf(stderr, "close socket [ExternalStream] %"_lx_"\n", (INT)sock); |
|
4966 |
} |
|
4967 |
||
4968 |
do { |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4969 |
#ifdef __win32__ |
23743 | 4970 |
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
|
4971 |
#else |
23743 | 4972 |
__threadErrno = 0; |
4973 |
__BEGIN_INTERRUPTABLE__ |
|
4974 |
rslt = close(sock); |
|
4975 |
__END_INTERRUPTABLE__ |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4976 |
#endif |
23743 | 4977 |
} while((rslt < 0) && (__threadErrno == EINTR)); |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4978 |
} else if ((__INST(handleType) == nil) |
23743 | 4979 |
|| (__INST(handleType) == @symbol(filePointer)) |
4980 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
4981 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
4982 |
{ |
23743 | 4983 |
FILEPOINTER f = __FILEVal(fp); |
4984 |
||
23879 | 4985 |
// whether the close() will be successful or not - the handle is invalid now! |
4986 |
__INST(handle) = nil; |
|
4987 |
||
23743 | 4988 |
if (@global(FileOpenTrace) == true) { |
4989 |
fprintf(stderr, "fclose [ExternalStream] %"_lx_"\n", (INT)f); |
|
4990 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4991 |
|
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
4992 |
#ifdef __win32__ |
23743 | 4993 |
if (__INST(mode) != @symbol(readonly) && __INST(buffered) != false) { |
4994 |
// do a fflush() first, so that fclose() doesn't block |
|
4995 |
// we suspect, that EINTR causes problems in fclose() |
|
4996 |
do { |
|
4997 |
__threadErrno = 0; |
|
4998 |
rslt = __STX_C_CALL1("fflush", fflush, f); |
|
4999 |
} while((rslt < 0) && (__threadErrno == EINTR)); |
|
5000 |
if (rslt < 0) |
|
5001 |
goto err; |
|
5002 |
} |
|
5003 |
do { |
|
5004 |
__threadErrno = 0; |
|
5005 |
rslt = __STX_C_NOINT_CALL1("fclose", fclose, f); |
|
5006 |
} while((rslt < 0) && (__threadErrno == EINTR)); |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5007 |
#else |
23743 | 5008 |
// cg: not sure why, but on osx, I get blocked occasionally in fclose |
5009 |
// lets try this: |
|
5010 |
if ((__INST(mode) != @symbol(readonly)) && (__INST(buffered) != false)) { |
|
5011 |
// do a fflush() first, so that fclose() doesn't block |
|
5012 |
// we suspect, that EINTR causes problems in fclose() |
|
5013 |
do { |
|
5014 |
clearerr(f); |
|
5015 |
__threadErrno = 0; |
|
5016 |
__BEGIN_INTERRUPTABLE__ |
|
5017 |
rslt = fflush(f); |
|
5018 |
__END_INTERRUPTABLE__ |
|
5019 |
} while((rslt < 0) && (__threadErrno == EINTR)); |
|
5020 |
if (rslt < 0) |
|
5021 |
goto err; |
|
5022 |
} |
|
5023 |
do { |
|
5024 |
clearerr(f); |
|
5025 |
__threadErrno = 0; |
|
5026 |
__BEGIN_INTERRUPTABLE__ |
|
5027 |
rslt = fclose(f); |
|
5028 |
__END_INTERRUPTABLE__ |
|
5029 |
} while((rslt < 0) && (__threadErrno == EINTR)); |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5030 |
#endif |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5031 |
} else { |
23743 | 5032 |
error = @symbol(badHandleType); |
5033 |
goto out; |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5034 |
} |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5035 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5036 |
if (rslt < 0) { |
23538 | 5037 |
err: |
5038 |
# ifdef __win32__ |
|
23743 | 5039 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5040 |
# endif |
23743 | 5041 |
error = __mkSmallInteger(__threadErrno); |
5042 |
goto out; |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5043 |
} |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5044 |
RETURN (self); |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5045 |
|
12674 | 5046 |
out:; |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5047 |
%}. |
12674 | 5048 |
|
5049 |
error notNil ifTrue:[ |
|
23743 | 5050 |
error isInteger ifTrue:[ |
5051 |
lastErrorNumber := error. |
|
5052 |
mode == #readonly ifTrue:[ |
|
5053 |
self ioError:error. |
|
5054 |
] ifFalse:[ |
|
5055 |
self writeError:error. |
|
5056 |
]. |
|
5057 |
^ self. |
|
5058 |
]. |
|
5059 |
self primitiveFailed:error. |
|
5060 |
^ self. |
|
12674 | 5061 |
]. |
5062 |
||
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5063 |
"/ fallback for rel5 |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5064 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5065 |
fp := handle. |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5066 |
fp notNil ifTrue:[ |
23743 | 5067 |
handle := nil. |
5068 |
self closeFile:fp |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5069 |
] |
22681 | 5070 |
|
5071 |
"Modified: / 19-04-2018 / 10:57:54 / stefan" |
|
23538 | 5072 |
"Modified: / 22-11-2018 / 12:18:22 / Stefan Vogel" |
23737 | 5073 |
"Modified: / 14-02-2019 / 15:42:44 / Claus Gittinger" |
20987 | 5074 |
! |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5075 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5076 |
closeFile:handle |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5077 |
"for rel5 only" |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5078 |
|
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5079 |
self primitiveFailed |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5080 |
! |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5081 |
|
12706 | 5082 |
connectTo:aFileDescriptor withMode:modeSymbol handleType:handleTypeSymbol |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5083 |
"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
|
5084 |
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
|
5085 |
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
|
5086 |
a Stream object. |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5087 |
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
|
5088 |
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
|
5089 |
|
21224 | 5090 |
|error openmode| |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5091 |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5092 |
handle notNil ifTrue:[^ self errorAlreadyOpen]. |
12706 | 5093 |
mode := modeSymbol. |
5094 |
openmode := self fopenMode. |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5095 |
%{ |
12683 | 5096 |
FILEPOINTER f = 0; |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5097 |
OBJ fp; |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5098 |
FILE *fdopen(); |
12683 | 5099 |
int fd = -2; |
5100 |
||
5101 |
if (__isStringLike(openmode)) { |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5102 |
#ifdef __win32__ |
23743 | 5103 |
__stxWrapApiEnterCritical(); |
12688 | 5104 |
#endif |
23743 | 5105 |
if (__isSmallInteger(aFileDescriptor)) { |
5106 |
fd = __intVal(aFileDescriptor); |
|
5107 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5108 |
#ifdef __win32__ |
23743 | 5109 |
else if (__isExternalAddressLike(aFileDescriptor)) { |
5110 |
fd = _open_osfhandle((long)__externalAddressVal(aFileDescriptor), O_BINARY); |
|
5111 |
if (fd < 0) { |
|
5112 |
if (__threadErrno == 0) { |
|
5113 |
// no more file descriptors |
|
5114 |
__threadErrno = EMFILE; |
|
5115 |
} |
|
5116 |
error = __mkSmallInteger(__WIN32_ERR(GetLastError())); |
|
5117 |
__stxWrapApiLeaveCritical(); |
|
5118 |
goto out; |
|
5119 |
} |
|
5120 |
} |
|
12683 | 5121 |
#endif |
23743 | 5122 |
f = (FILEPOINTER) fdopen(fd, (char *)__stringVal(openmode)); |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5123 |
#ifdef __win32__ |
23743 | 5124 |
__stxWrapApiLeaveCritical(); |
12688 | 5125 |
#endif |
23743 | 5126 |
if (f == NULL) { |
23538 | 5127 |
# ifdef __win32__ |
23743 | 5128 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5129 |
# endif |
23743 | 5130 |
error =__mkSmallInteger(__threadErrno); |
5131 |
} else { |
|
5132 |
if (@global(FileOpenTrace) == true) { |
|
5133 |
fprintf(stderr, "fdopen [ExternalStream] %"_ld_" (%"_lx_") -> %"_lx_"\n", (INT)fd, (INT)fd, (INT)f); |
|
5134 |
} |
|
5135 |
||
5136 |
fp = __MKFILEPOINTER(f); __INST(handle) = fp; __STORE(self, fp); |
|
5137 |
} |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5138 |
} |
12688 | 5139 |
out:; |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5140 |
%}. |
21224 | 5141 |
error notNil ifTrue:[ |
23743 | 5142 |
" |
5143 |
the open failed for some reason ... |
|
5144 |
" |
|
5145 |
OperatingSystem closeFd:aFileDescriptor. |
|
5146 |
lastErrorNumber := error. |
|
5147 |
position := nil. |
|
5148 |
^ self openError:error |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5149 |
]. |
21224 | 5150 |
|
5151 |
position := 0. |
|
5152 |
buffered isNil ifTrue:[ |
|
23743 | 5153 |
buffered := true. "default is buffered" |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5154 |
]. |
21224 | 5155 |
handleType := handleTypeSymbol. |
5156 |
self registerForFinalization. |
|
23538 | 5157 |
|
5158 |
"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
|
5159 |
! |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5160 |
|
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5161 |
dupFd |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5162 |
"duplicate my file descriptor" |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5163 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5164 |
|fd dupFd| |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5165 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5166 |
fd := self fileHandle. |
22578 | 5167 |
fd isNil ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5168 |
^ self errorNotOpen. |
20690 | 5169 |
]. |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5170 |
dupFd := OperatingSystem dup:fd. |
10989 | 5171 |
self setFileHandle:dupFd mode:self fopenMode. |
10995 | 5172 |
! |
10989 | 5173 |
|
5174 |
fopenMode |
|
5175 |
"answer the mode for fopen. |
|
5176 |
Only used internally" |
|
5177 |
||
5178 |
mode == #readonly ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5179 |
^ ReadMode |
10989 | 5180 |
]. |
5181 |
mode == #writeonly ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5182 |
^ WriteMode |
10989 | 5183 |
]. |
5184 |
mode == #readWrite ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5185 |
^ ReadWriteMode |
10989 | 5186 |
]. |
5187 |
mode == #append ifTrue:[ |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5188 |
^ AppendMode |
10989 | 5189 |
]. |
5190 |
^ ReadWriteMode |
|
10995 | 5191 |
! |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5192 |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5193 |
open:aPath withMode:openModeString |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5194 |
"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
|
5195 |
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
|
5196 |
|
16296 | 5197 |
|ok error| |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5198 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5199 |
ok := false. |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5200 |
%{ |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5201 |
FILE *f; |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5202 |
OBJ fp; |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5203 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5204 |
if (__isStringLike(aPath) && __isStringLike(openModeString)) { |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5205 |
#ifdef __win32__ |
10339 | 5206 |
# if 1 |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5207 |
f = fopen((char *) __stringVal(aPath), (char *) __stringVal(openModeString)); |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5208 |
# else |
23743 | 5209 |
__BEGIN_INTERRUPTABLE__ |
5210 |
do { |
|
5211 |
f = fopen((char *) __stringVal(aPath), (char *) __stringVal(openModeString)); |
|
5212 |
} while ((f == NULL) && (__threadErrno == EINTR)); |
|
5213 |
__END_INTERRUPTABLE__ |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5214 |
# endif |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5215 |
#else /* UNIX */ |
23743 | 5216 |
__BEGIN_INTERRUPTABLE__ |
5217 |
do { |
|
5218 |
f = fopen((char *) __stringVal(aPath), (char *) __stringVal(openModeString)); |
|
5219 |
} while ((f == NULL) && (__threadErrno == EINTR)); |
|
5220 |
__END_INTERRUPTABLE__ |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5221 |
#endif /* UNIX */ |
23743 | 5222 |
if (f == NULL) { |
23538 | 5223 |
# ifdef __win32__ |
23743 | 5224 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5225 |
# endif |
23743 | 5226 |
error = __mkSmallInteger(__threadErrno); |
5227 |
} else { |
|
5228 |
if (@global(FileOpenTrace) == true) { |
|
5229 |
fprintf(stderr, "fopen %s [ExternalStream] -> %"_lx_"\n", __stringVal(aPath), (INT)f); |
|
5230 |
} |
|
5231 |
fp = __MKFILEPOINTER(f); __INST(handle) = fp; __STORE(self, fp); |
|
5232 |
__INST(handleType) = @symbol(filePointer); |
|
5233 |
ok = true; |
|
5234 |
} |
|
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 |
%}. |
16296 | 5237 |
ok ifTrue:[ |
23743 | 5238 |
position := 0. |
5239 |
self registerForFinalization. |
|
5240 |
^ self. |
|
16296 | 5241 |
]. |
5242 |
error notNil ifTrue:[ |
|
23743 | 5243 |
" |
5244 |
the open failed for some reason ... |
|
5245 |
" |
|
5246 |
lastErrorNumber := error. |
|
5247 |
self openError:error. |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5248 |
]. |
16296 | 5249 |
self primitiveFailed. |
23538 | 5250 |
|
5251 |
"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
|
5252 |
! |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5253 |
|
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5254 |
reOpen |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5255 |
"USERS WILL NEVER INVOKE THIS METHOD |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5256 |
sent after snapin to reopen streams. |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5257 |
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
|
5258 |
|
24383 | 5259 |
self className errorPrint. ' [warning]: automatic reOpen not supported - stream closed' errorPrintCR. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5260 |
handle := nil. |
18779 | 5261 |
self unregisterForFinalization. |
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5262 |
|
24383 | 5263 |
"Modified: / 10-01-1997 / 17:50:44 / cg" |
5264 |
"Modified: / 28-06-2019 / 08:43:21 / Claus Gittinger" |
|
8966
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5265 |
! |
0b299dd8759c
Allow Symbols as pathname and openMode
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
5266 |
|
12398 | 5267 |
setAccessor:what to:something |
5268 |
"set the filePointer/fileHandle to the given one; |
|
5269 |
low level private & friend interface; may also be used to connect to some |
|
5270 |
externally provided handle." |
|
5271 |
||
5272 |
handle := something. |
|
5273 |
handleType := what. |
|
5274 |
! |
|
5275 |
||
5276 |
setFileHandle:something |
|
5277 |
"set the fileHandle to the given one; |
|
5278 |
low level private & friend interface; may also be used to connect to some |
|
5279 |
externally provided file handle." |
|
5280 |
||
5281 |
self setAccessor:#fileHandle to:something |
|
5282 |
! |
|
5283 |
||
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5284 |
setFileHandle:anIntegerOrExternalAddress mode:openMode |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5285 |
"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
|
5286 |
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
|
5287 |
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
|
5288 |
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
|
5289 |
|
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5290 |
%{ |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5291 |
FILEPOINTER f; |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5292 |
OBJ fp; |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5293 |
FILE *fdopen(); |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5294 |
int fd; |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5295 |
|
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5296 |
if (!__isStringLike(openMode)) |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5297 |
goto err; |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5298 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5299 |
#ifdef __win32__ |
12688 | 5300 |
__stxWrapApiEnterCritical(); |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5301 |
if (__isExternalAddressLike(anIntegerOrExternalAddress) ) { |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5302 |
HANDLE __fileHandle = (HANDLE)__externalAddressVal(anIntegerOrExternalAddress); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5303 |
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
|
5304 |
if (fd < 0) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5305 |
__stxWrapApiLeaveCritical(); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5306 |
CloseHandle(__fileHandle); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5307 |
goto err; |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5308 |
} |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5309 |
} else |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5310 |
#endif |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5311 |
if (__isSmallInteger(anIntegerOrExternalAddress)) { |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5312 |
fd = __smallIntegerVal(anIntegerOrExternalAddress); |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5313 |
} else { |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5314 |
#ifdef __win32__ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5315 |
__stxWrapApiLeaveCritical(); |
12688 | 5316 |
#endif |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5317 |
goto err; |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5318 |
} |
10997 | 5319 |
f = fdopen(fd, __stringVal(openMode)); |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5320 |
#ifdef __win32__ |
12688 | 5321 |
__stxWrapApiLeaveCritical(); |
5322 |
#endif |
|
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5323 |
if (f != NULL) { |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5324 |
if (@global(FileOpenTrace) == true) { |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5325 |
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
|
5326 |
} |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5327 |
fp = __MKFILEPOINTER(f); __INST(handle) = fp; __STORE(self, fp); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5328 |
__INST(handleType) = @symbol(filePointer); |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5329 |
RETURN (self); |
10982
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5330 |
} |
11fd48c1276d
New: #copy duplicates the underlying file descriptor resp. file handle
Stefan Vogel <sv@exept.de>
parents:
10932
diff
changeset
|
5331 |
err:; |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5332 |
%}. |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5333 |
^ self primitiveFailed |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5334 |
! |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5335 |
|
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5336 |
setFilePointer:something |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5337 |
"set the filePointer to the given one; |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5338 |
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
|
5339 |
externally provided file." |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5340 |
|
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5341 |
self setAccessor:#filePointer to:something |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5342 |
! |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5343 |
|
12398 | 5344 |
setLastError:aNumber |
5345 |
lastErrorNumber := aNumber |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5346 |
! |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5347 |
|
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5348 |
setSocketHandle:something |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5349 |
"set the socketHandle to the given one; |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5350 |
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
|
5351 |
externally provided socket handle." |
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5352 |
|
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5353 |
self setAccessor:#socketHandle to:something |
8471
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5354 |
! ! |
e061e503bf03
Documentation: users shold never send #closeFile
Stefan Vogel <sv@exept.de>
parents:
8362
diff
changeset
|
5355 |
|
612 | 5356 |
!ExternalStream methodsFor:'queries'! |
5357 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5358 |
nextError |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5359 |
"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
|
5360 |
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
|
5361 |
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
|
5362 |
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
|
5363 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5364 |
%{ /*NOCONTEXT*/ |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5365 |
FILEPOINTER f; |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5366 |
int ret, _buffered; |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5367 |
OBJ fp; |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5368 |
unsigned char ch; |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5369 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5370 |
if ((__INST(handleType) == nil) |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5371 |
|| (__INST(handleType) == @symbol(filePointer)) |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5372 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5373 |
|| (__INST(handleType) == @symbol(socketHandle)) |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5374 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 5375 |
if (((fp = __INST(handle)) != nil) |
5376 |
&& (__INST(mode) != @symbol(writeonly)) |
|
5377 |
) { |
|
5378 |
f = __FILEVal(fp); |
|
5379 |
||
5380 |
_buffered = (__INST(buffered) == true); |
|
5381 |
if (_buffered) { |
|
5382 |
__READING__(f) |
|
5383 |
} |
|
5384 |
__READBYTE__(ret, f, &ch, _buffered, __INST(handleType)); |
|
5385 |
||
5386 |
if (ret > 0) { |
|
5387 |
RETURN(nil) |
|
5388 |
} |
|
5389 |
if (ret < 0) { |
|
23538 | 5390 |
# ifdef __win32__ |
23743 | 5391 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5392 |
# endif |
23743 | 5393 |
RETURN(__mkSmallInteger(__threadErrno)); |
5394 |
} else /* ret == 0 */ { |
|
5395 |
RETURN(__mkSmallInteger(0)); /* EOF */ |
|
5396 |
} |
|
5397 |
} |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5398 |
} |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5399 |
%}. |
23538 | 5400 |
|
5401 |
"Modified: / 22-11-2018 / 15:07:16 / Stefan Vogel" |
|
612 | 5402 |
! |
5403 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5404 |
numAvailable |
21130 | 5405 |
<resource: #obsolete> |
5406 |
^ self numAvailableForRead |
|
612 | 5407 |
! ! |
5408 |
||
5409 |
!ExternalStream methodsFor:'reading'! |
|
5410 |
||
5411 |
next |
|
5412 |
"return the next element; advance read position. |
|
5413 |
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
|
5414 |
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
|
5415 |
- see #pastEndRead." |
1 | 5416 |
|
16296 | 5417 |
|c error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
5418 |
%{ |
18364 | 5419 |
#ifdef __SCHTEAM__ |
5420 |
STObject handle = self.instVarAt(I_handle); |
|
5421 |
||
5422 |
if (handle != STObject.Nil) { |
|
23743 | 5423 |
STObject next; |
5424 |
||
5425 |
if (self.instVarAt(I_binary) == STObject.True) { |
|
5426 |
next = handle.nextByte(); |
|
5427 |
} else { |
|
5428 |
next = handle.nextChar(); |
|
5429 |
} |
|
5430 |
if (next != STObject.EOF) { |
|
5431 |
self.instVarAt_put(I_position, STObject.Nil); |
|
5432 |
return __c__._RETURN( next ); |
|
5433 |
} |
|
5434 |
self.instVarAt_put(I_hitEOF, STObject.True); |
|
18364 | 5435 |
} |
5436 |
#else |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
5437 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5438 |
int ret, _buffered; |
612 | 5439 |
OBJ pos, fp; |
5440 |
unsigned char ch; |
|
5441 |
||
1133 | 5442 |
__INST(lastErrorNumber) = nil; |
12548 | 5443 |
if ((__INST(handleType) == nil) |
5444 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
5445 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5446 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 5447 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 5448 |
if (((fp = __INST(handle)) != nil) |
5449 |
&& (__INST(mode) != @symbol(writeonly)) |
|
5450 |
) { |
|
5451 |
f = __FILEVal(fp); |
|
5452 |
||
5453 |
_buffered = (__INST(buffered) == true); |
|
5454 |
if (_buffered) { |
|
5455 |
__READING__(f) |
|
5456 |
} |
|
5457 |
__READBYTE__(ret, f, &ch, _buffered, __INST(handleType)); |
|
5458 |
||
5459 |
if (ret > 0) { |
|
5460 |
pos = __INST(position); |
|
5461 |
if (__isSmallInteger(pos)) { |
|
5462 |
OBJ t; |
|
5463 |
||
5464 |
t = __MKINT(__intVal(pos) + 1); __INST(position) = t; __STORE(self, t); |
|
5465 |
} else { |
|
5466 |
__INST(position) = nil; /* i.e. do not know */ |
|
5467 |
} |
|
5468 |
if (__INST(binary) == true) { |
|
5469 |
RETURN ( __mkSmallInteger(ch) ); |
|
5470 |
} |
|
5471 |
RETURN ( __MKCHARACTER(ch) ); |
|
5472 |
} |
|
5473 |
||
5474 |
__INST(position) = nil; |
|
5475 |
if (ret < 0) { |
|
23538 | 5476 |
# ifdef __win32__ |
23743 | 5477 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5478 |
# endif |
23743 | 5479 |
error = __mkSmallInteger(__threadErrno); |
5480 |
} else /* ret == 0 */ { |
|
5481 |
__INST(hitEOF) = true; |
|
5482 |
} |
|
5483 |
} |
|
612 | 5484 |
} |
18364 | 5485 |
#endif /* not SCHTEAM */ |
612 | 5486 |
%}. |
21139 | 5487 |
hitEOF ifTrue:[^ self pastEndRead]. |
16296 | 5488 |
error notNil ifTrue:[ |
23743 | 5489 |
lastErrorNumber := error. |
5490 |
^ self readError:error |
|
16296 | 5491 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5492 |
handle isNil ifTrue:[^ self errorNotOpen]. |
5420 | 5493 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
5494 |
||
5495 |
readAhead notNil ifTrue:[ |
|
23743 | 5496 |
c := readAhead. |
5497 |
readAhead := nil. |
|
5498 |
^ c. |
|
5420 | 5499 |
]. |
20679 | 5500 |
|
5501 |
"unknown handleType - future" |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5502 |
c := self nextByteFromFile:handle. |
5430 | 5503 |
c isNil ifTrue:[ |
23743 | 5504 |
^ self pastEndRead. |
5430 | 5505 |
]. |
21139 | 5506 |
binary ifTrue:[ |
23743 | 5507 |
^ c |
5420 | 5508 |
]. |
5509 |
^ Character value:c |
|
23538 | 5510 |
|
5511 |
"Modified: / 22-11-2018 / 14:44:30 / Stefan Vogel" |
|
612 | 5512 |
! |
5513 |
||
5514 |
next:count |
|
5515 |
"return the next count elements of the stream as a collection. |
|
5516 |
Redefined to return a String or ByteArray instead of the default: Array." |
|
5517 |
||
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
5518 |
|coll nRead| |
612 | 5519 |
|
20092 | 5520 |
coll := self contentsSpecies uninitializedNew:count. |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
5521 |
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
|
5522 |
|
20092 | 5523 |
nRead ~~ count ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5524 |
"/ for readStream protocol compatibility, |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5525 |
"/ we must raise an exception here. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5526 |
^ self pastEndRead |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
5527 |
]. |
612 | 5528 |
^ coll |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
5529 |
|
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
5530 |
"Modified: 11.1.1997 / 17:44:17 / cg" |
612 | 5531 |
! |
5532 |
||
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5533 |
nextOrNil |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5534 |
"return the next element; advance read position. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5535 |
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
|
5536 |
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
|
5537 |
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
|
5538 |
|
16296 | 5539 |
|c error| |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5540 |
%{ |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5541 |
FILEPOINTER f; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5542 |
int ret, _buffered; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5543 |
OBJ pos, fp; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5544 |
unsigned char ch; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5545 |
|
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5546 |
__INST(lastErrorNumber) = nil; |
12548 | 5547 |
if ((__INST(handleType) == nil) |
5548 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
5549 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5550 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 5551 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 5552 |
if (((fp = __INST(handle)) != nil) |
5553 |
&& (__INST(mode) != @symbol(writeonly)) |
|
5554 |
) { |
|
5555 |
f = __FILEVal(fp); |
|
5556 |
||
5557 |
_buffered = (__INST(buffered) == true); |
|
5558 |
if (_buffered) { |
|
5559 |
__READING__(f) |
|
5560 |
} |
|
5561 |
__READBYTE__(ret, f, &ch, _buffered, __INST(handleType)); |
|
5562 |
||
5563 |
if (ret > 0) { |
|
5564 |
pos = __INST(position); |
|
5565 |
if (__isSmallInteger(pos)) { |
|
5566 |
OBJ t; |
|
5567 |
||
5568 |
t = __MKINT(__intVal(pos) + 1); __INST(position) = t; __STORE(self, t); |
|
5569 |
} else { |
|
5570 |
__INST(position) = nil; /* i.e. do not know */ |
|
5571 |
} |
|
5572 |
if (__INST(binary) == true) { |
|
5573 |
RETURN ( __mkSmallInteger(ch) ); |
|
5574 |
} |
|
5575 |
RETURN ( __MKCHARACTER(ch) ); |
|
5576 |
} |
|
5577 |
||
5578 |
__INST(position) = nil; |
|
5579 |
if (ret < 0) { |
|
23538 | 5580 |
# ifdef __win32__ |
23743 | 5581 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5582 |
# endif |
23743 | 5583 |
error = __mkSmallInteger(__threadErrno); |
5584 |
} else /* ret == 0 */ { |
|
5585 |
__INST(hitEOF) = true; |
|
5586 |
} |
|
5587 |
} |
|
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5588 |
} |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5589 |
%}. |
21139 | 5590 |
hitEOF ifTrue:[^ nil]. |
16296 | 5591 |
error notNil ifTrue:[ |
23743 | 5592 |
lastErrorNumber := error. |
5593 |
^ self readError:error. |
|
16296 | 5594 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5595 |
handle isNil ifTrue:[^ self errorNotOpen]. |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5596 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5597 |
|
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5598 |
readAhead notNil ifTrue:[ |
23743 | 5599 |
c := readAhead. |
5600 |
readAhead := nil. |
|
5601 |
^ c. |
|
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5602 |
]. |
20679 | 5603 |
|
5604 |
"unknown handleType - future" |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5605 |
c := self nextByteFromFile:handle. |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5606 |
c isNil ifTrue:[ |
23743 | 5607 |
^ nil. |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5608 |
]. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5609 |
binary == true ifTrue:[ |
23743 | 5610 |
^ c |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5611 |
]. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5612 |
^ Character value:c |
23538 | 5613 |
|
5614 |
"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
|
5615 |
! |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5616 |
|
612 | 5617 |
peek |
5618 |
"return the element to be read next without advancing read position. |
|
5619 |
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
|
5620 |
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
|
5621 |
- see #pastEndRead." |
612 | 5622 |
|
16296 | 5623 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
5624 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
5625 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5626 |
unsigned char c; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
5627 |
int ret, _buffered; |
216 | 5628 |
OBJ fp; |
3672
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
5629 |
OBJ ra; |
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
5630 |
|
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
5631 |
if ((ra = __INST(readAhead)) != nil) { |
23743 | 5632 |
if (__INST(binary) == true) { |
5633 |
RETURN ( ra ); |
|
5634 |
} |
|
5635 |
c = __intVal(ra); |
|
5636 |
RETURN ( __MKCHARACTER(c) ); |
|
3029
aa14768e0e6a
larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents:
3016
diff
changeset
|
5637 |
} |
aa14768e0e6a
larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents:
3016
diff
changeset
|
5638 |
|
1133 | 5639 |
__INST(lastErrorNumber) = nil; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
5640 |
|
12548 | 5641 |
if ((__INST(handleType) == nil) |
5642 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
5643 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5644 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 5645 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 5646 |
if (((fp = __INST(handle)) != nil) |
5647 |
&& (__INST(mode) != @symbol(writeonly)) |
|
5648 |
) { |
|
5649 |
f = __FILEVal(fp); |
|
5650 |
_buffered = (__INST(buffered) == true); |
|
5651 |
if (_buffered) { |
|
5652 |
__READING__(f) |
|
5653 |
} |
|
5654 |
__READBYTE__(ret, f, &c, _buffered, __INST(handleType)); |
|
5655 |
||
5656 |
if (ret > 0) { |
|
5657 |
__UNGETC__(c, f, _buffered); |
|
5658 |
||
5659 |
if (__INST(binary) == true) { |
|
5660 |
RETURN ( __mkSmallInteger(c) ); |
|
5661 |
} |
|
5662 |
RETURN ( __MKCHARACTER(c) ); |
|
5663 |
} |
|
5664 |
if (ret < 0) { |
|
23538 | 5665 |
# ifdef __win32__ |
23743 | 5666 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5667 |
# endif |
23743 | 5668 |
error = __mkSmallInteger(__threadErrno); |
5669 |
} else /* ret == 0 */ { |
|
5670 |
__INST(hitEOF) = true; |
|
5671 |
} |
|
5672 |
} |
|
1 | 5673 |
} |
159 | 5674 |
%}. |
21139 | 5675 |
hitEOF ifTrue:[^ self pastEndRead]. |
16296 | 5676 |
error notNil ifTrue:[ |
23743 | 5677 |
lastErrorNumber := error. |
5678 |
^ self readError:error. |
|
16296 | 5679 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5680 |
handle isNil ifTrue:[^ self errorNotOpen]. |
5420 | 5681 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
5682 |
||
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5683 |
readAhead isNil ifTrue:[ |
23743 | 5684 |
readAhead := self nextOrNil. |
5685 |
readAhead isNil ifTrue:[ |
|
5686 |
^ self pastEndRead. |
|
5687 |
]. |
|
5420 | 5688 |
]. |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5689 |
^ readAhead |
23538 | 5690 |
|
5691 |
"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
|
5692 |
! |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5693 |
|
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5694 |
peekOrNil |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5695 |
"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
|
5696 |
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
|
5697 |
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
|
5698 |
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
|
5699 |
|
16296 | 5700 |
|error| |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5701 |
%{ |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5702 |
FILEPOINTER f; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5703 |
unsigned char c; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5704 |
int ret, _buffered; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5705 |
OBJ fp; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5706 |
OBJ ra; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5707 |
|
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5708 |
if ((ra = __INST(readAhead)) != nil) { |
23743 | 5709 |
if (__INST(binary) == true) { |
5710 |
RETURN ( ra ); |
|
5711 |
} |
|
5712 |
c = __intVal(ra); |
|
5713 |
RETURN ( __MKCHARACTER(c) ); |
|
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5714 |
} |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5715 |
|
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5716 |
__INST(lastErrorNumber) = nil; |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5717 |
|
12548 | 5718 |
if ((__INST(handleType) == nil) |
5719 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
5720 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5721 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 5722 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 5723 |
if (((fp = __INST(handle)) != nil) |
5724 |
&& (__INST(mode) != @symbol(writeonly)) |
|
5725 |
) { |
|
5726 |
f = __FILEVal(fp); |
|
5727 |
_buffered = (__INST(buffered) == true); |
|
5728 |
if (_buffered) { |
|
5729 |
__READING__(f) |
|
5730 |
} |
|
5731 |
__READBYTE__(ret, f, &c, _buffered, __INST(handleType)); |
|
5732 |
||
5733 |
if (ret > 0) { |
|
5734 |
__UNGETC__(c, f, _buffered); |
|
5735 |
||
5736 |
if (__INST(binary) == true) { |
|
5737 |
RETURN ( __mkSmallInteger(c) ); |
|
5738 |
} |
|
5739 |
RETURN ( __MKCHARACTER(c) ); |
|
5740 |
} |
|
5741 |
if (ret < 0) { |
|
23538 | 5742 |
# ifdef __win32__ |
23743 | 5743 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5744 |
# endif |
23743 | 5745 |
error = __mkSmallInteger(__threadErrno); |
5746 |
} else /* ret == 0 */ { |
|
5747 |
__INST(hitEOF) = true; |
|
5748 |
} |
|
5749 |
} |
|
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5750 |
} |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5751 |
%}. |
21139 | 5752 |
hitEOF ifTrue:[^ nil]. |
16296 | 5753 |
error notNil ifTrue:[ |
23743 | 5754 |
lastErrorNumber := error. |
5755 |
^ self readError:error. |
|
16296 | 5756 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5757 |
handle isNil ifTrue:[^ self errorNotOpen]. |
10348
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5758 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5759 |
|
7ed317f7f2be
Speedup ExternalStream>>#nextOrNil and ExternalStream>>#peekOrNil.
Stefan Vogel <sv@exept.de>
parents:
10339
diff
changeset
|
5760 |
readAhead isNil ifTrue:[ |
23743 | 5761 |
readAhead := self nextOrNil. |
5420 | 5762 |
]. |
5763 |
^ readAhead |
|
23538 | 5764 |
|
5765 |
"Modified: / 22-11-2018 / 14:50:22 / Stefan Vogel" |
|
1295 | 5766 |
! |
5767 |
||
5768 |
upToEnd |
|
5769 |
"return a collection of the elements up-to the end. |
|
20092 | 5770 |
Return an empty collection, if the stream-end is already at the end." |
5771 |
||
22849 | 5772 |
|chunkSize chunksAndCounts byteCount data offset contentsSpecies| |
20092 | 5773 |
|
5774 |
"adding to a ByteArray produces quadratic time-space |
|
5775 |
behavior - therefore we allocate chunks, and concatenate them |
|
5776 |
at the end." |
|
5777 |
||
5778 |
chunkSize := 4096. |
|
5779 |
byteCount := 0. |
|
22849 | 5780 |
contentsSpecies := self contentsSpecies. |
5781 |
||
1295 | 5782 |
[self atEnd] whileFalse:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5783 |
|chunk cnt| |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5784 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5785 |
chunk := contentsSpecies uninitializedNew:chunkSize. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5786 |
cnt := self nextBytes:chunkSize into:chunk startingAt:1. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5787 |
cnt ~~ 0 ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5788 |
chunksAndCounts isNil ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5789 |
(cnt < chunkSize and:[self atEnd]) ifTrue:[ |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5790 |
"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
|
5791 |
^ chunk copyFrom:1 to:cnt. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5792 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5793 |
chunksAndCounts := OrderedCollection new. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5794 |
]. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5795 |
chunksAndCounts add:chunk; add:cnt. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5796 |
byteCount := byteCount + cnt. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5797 |
] |
1295 | 5798 |
]. |
20092 | 5799 |
|
5800 |
"now, create one big array" |
|
22849 | 5801 |
data := contentsSpecies uninitializedNew:byteCount. |
20092 | 5802 |
offset := 1. |
22849 | 5803 |
1 to:chunksAndCounts size by:2 do:[:index | |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5804 |
|chunk cnt| |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5805 |
|
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5806 |
chunk := chunksAndCounts at:index. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5807 |
cnt := chunksAndCounts at:index+1. |
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5808 |
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
|
5809 |
offset := offset + cnt |
20092 | 5810 |
]. |
5811 |
^ data |
|
5812 |
||
1295 | 5813 |
|
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
5814 |
" |
20092 | 5815 |
'/dev/null' asFilename readStream upToEnd |
5816 |
'/proc/self/stat' asFilename readStream upToEnd |
|
22849 | 5817 |
'librun.so' asFilename readStream binary upToEnd |
20092 | 5818 |
|
20241 | 5819 |
self assert:('smalltalk.rc' asFilename readStream upToEnd size) |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
5820 |
= ('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
|
5821 |
" |
22849 | 5822 |
|
5823 |
"Modified (format): / 09-05-2018 / 20:09:31 / stefan" |
|
612 | 5824 |
! ! |
5825 |
||
5420 | 5826 |
!ExternalStream methodsFor:'rel5 protocol'! |
5827 |
||
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5828 |
atEndFile:handle |
5420 | 5829 |
"for migration to rel5 only" |
5830 |
||
5831 |
self primitiveFailed |
|
5832 |
! |
|
5833 |
||
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5834 |
nextByteFromFile:handle |
5420 | 5835 |
"for migration to rel5 only" |
5836 |
||
5837 |
self primitiveFailed |
|
5838 |
! |
|
5839 |
||
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
5840 |
nextPutByte:aByte toFile:handle |
5420 | 5841 |
"for migration to rel5 only" |
5842 |
||
5843 |
self primitiveFailed |
|
5844 |
! ! |
|
5845 |
||
612 | 5846 |
!ExternalStream methodsFor:'testing'! |
5847 |
||
5848 |
atEnd |
|
20675 | 5849 |
"return true, if position is at end. |
21032 | 5850 |
If a stream is at the end, the next read operation |
5851 |
would return or raise an exception immediately without waiting. |
|
5852 |
If a stream is not at the end, this may be a blocking operation |
|
5853 |
(see NonPositionableExternalStream)" |
|
612 | 5854 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
5855 |
%{ |
21221 | 5856 |
OBJ fp, lim; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5857 |
char c; |
612 | 5858 |
|
1133 | 5859 |
if (__INST(hitEOF) == true) { |
23743 | 5860 |
RETURN (true); |
3906
7f2d4a3b63e2
oops - readLimit was not handled in #atEnd
Claus Gittinger <cg@exept.de>
parents:
3878
diff
changeset
|
5861 |
} |
7875
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
5862 |
lim = __INST(readLimit); |
21221 | 5863 |
if (lim != nil && __signedLongIntVal(__INST(position)) >= __signedLongIntVal(lim)) { |
23743 | 5864 |
RETURN (true); |
612 | 5865 |
} |
5866 |
||
1133 | 5867 |
__INST(lastErrorNumber) = nil; |
5868 |
||
12548 | 5869 |
if ((__INST(handleType) == nil) |
5870 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
5871 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5872 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 5873 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
23743 | 5874 |
if ((fp = __INST(handle)) != nil) { |
5875 |
int _buffered = (__INST(buffered) == true); |
|
5876 |
int ret; |
|
5877 |
FILEPOINTER f = __FILEVal(fp); |
|
5878 |
||
5879 |
if (_buffered) { |
|
5880 |
__READING__(f); |
|
5881 |
} else if (__INST(readAhead) != nil) { |
|
5882 |
RETURN (false); |
|
5883 |
} |
|
5884 |
||
5885 |
/* |
|
5886 |
* read ahead ... |
|
5887 |
*/ |
|
5888 |
do { |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5889 |
#ifdef __win32__ |
23743 | 5890 |
__READBYTE__(ret, f, &c, _buffered, __INST(handleType)); |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
5891 |
#else /* not __win32__ */ |
23743 | 5892 |
__BEGIN_INTERRUPTABLE__ |
5893 |
__READBYTE__(ret, f, &c, _buffered, __INST(handleType)); |
|
5894 |
__END_INTERRUPTABLE__ |
|
21221 | 5895 |
#endif /* not __win32__ */ |
23743 | 5896 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
5897 |
if (ret > 0) { |
|
5898 |
__UNGETC__(c&0xff, f, _buffered); |
|
5899 |
RETURN (false); |
|
5900 |
} |
|
5901 |
if (ret == 0) { |
|
5902 |
__INST(hitEOF) = true; |
|
5903 |
RETURN (true); |
|
5904 |
} |
|
5905 |
/* ret < 0 -> error */ |
|
23538 | 5906 |
# ifdef __win32__ |
23743 | 5907 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 5908 |
# endif |
23743 | 5909 |
__INST(lastErrorNumber) = __mkSmallInteger(__threadErrno); |
5910 |
} |
|
5911 |
// we do not raise an error here - the next read operation will raise the error. |
|
5912 |
RETURN(false); |
|
612 | 5913 |
} |
5914 |
%}. |
|
20675 | 5915 |
|
22578 | 5916 |
"/ we come here if the handle type is unknown |
5420 | 5917 |
"/ migration support |
20675 | 5918 |
^ self atEndFile:handle |
3906
7f2d4a3b63e2
oops - readLimit was not handled in #atEnd
Claus Gittinger <cg@exept.de>
parents:
3878
diff
changeset
|
5919 |
|
23538 | 5920 |
"Modified: / 30-10-1998 / 20:16:06 / cg" |
5921 |
"Modified: / 22-11-2018 / 14:39:54 / Stefan Vogel" |
|
612 | 5922 |
! |
5923 |
||
10995 | 5924 |
gotErrorOrEOF |
20675 | 5925 |
"answer true, if amn error or eof has been occurred on the stream" |
10995 | 5926 |
|
21139 | 5927 |
^ hitEOF or:[lastErrorNumber notNil] |
10995 | 5928 |
! |
5929 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5930 |
isBinary |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5931 |
"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
|
5932 |
The default when created is false." |
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 |
^ binary |
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
5935 |
! |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
5936 |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5937 |
isBlocking |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5938 |
"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
|
5939 |
|
22195 | 5940 |
|fd| |
5941 |
||
5942 |
fd := self fileDescriptor. |
|
25317 | 5943 |
"self fileDescriptor sets handle to nil and |
5944 |
answers nil, if the handle is no longer valid!!" |
|
5945 |
fd isNil ifTrue:[ |
|
5946 |
^ true. |
|
5947 |
]. |
|
5948 |
^ OperatingSystem isBlockingOn:fd. |
|
5949 |
||
5950 |
"Modified: / 04-03-2020 / 13:06:29 / Stefan Vogel" |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5951 |
! |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5952 |
|
22694 | 5953 |
isExecutor |
5954 |
"am I an executor and no real stream object?" |
|
5955 |
||
5956 |
^ mode == #executor. |
|
5957 |
||
5958 |
"Created: / 23-04-2018 / 18:17:40 / stefan" |
|
5959 |
! |
|
5960 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5961 |
isExternalStream |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5962 |
"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
|
5963 |
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
|
5964 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5965 |
^ true |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5966 |
! |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5967 |
|
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5968 |
isOpen |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5969 |
"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
|
5970 |
|
22694 | 5971 |
"executors are only used to finalize - they are not really open and are closed with #closeFile, |
5972 |
which does not check for #isOpen" |
|
5973 |
^ handle notNil and:[self isExecutor not] |
|
5974 |
||
5975 |
"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
|
5976 |
! |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5977 |
|
22978 | 5978 |
isPipeStream |
5979 |
"return true, if this stream is a pipe" |
|
5980 |
||
5981 |
^ false |
|
5982 |
! |
|
5983 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5984 |
isReadable |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5985 |
"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
|
5986 |
|
21139 | 5987 |
^ mode ~~ #writeonly |
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5988 |
! |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5989 |
|
22978 | 5990 |
isSocket |
5991 |
"return true, if this stream is a socket" |
|
5992 |
||
5993 |
^ false |
|
5994 |
! |
|
5995 |
||
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5996 |
isWritable |
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
5997 |
"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
|
5998 |
|
21139 | 5999 |
^ mode ~~ #readonly |
612 | 6000 |
! ! |
6001 |
||
6002 |
!ExternalStream methodsFor:'waiting for I/O'! |
|
6003 |
||
5101 | 6004 |
canBeSelected |
6005 |
"return true, if this stream can be selected upon" |
|
6006 |
||
6007 |
^ OperatingSystem supportsSelect |
|
6008 |
! |
|
6009 |
||
20104 | 6010 |
numAvailableForRead |
20241 | 6011 |
"answer the number of bytes available for reading" |
6012 |
||
25317 | 6013 |
|available fd| |
6014 |
||
6015 |
fd := self fileHandle. |
|
6016 |
fd isNil ifTrue:[ |
|
6017 |
^ self errorNotOpen |
|
20104 | 6018 |
]. |
6019 |
mode == #writeonly ifTrue:[ |
|
25317 | 6020 |
^ self errorWriteOnly |
20104 | 6021 |
]. |
25317 | 6022 |
available := OperatingSystem numAvailableForReadOn:fd. |
20104 | 6023 |
readAhead notNil ifTrue:[ |
25317 | 6024 |
available := available + 1 |
20104 | 6025 |
]. |
6026 |
^ available. |
|
6027 |
||
6028 |
" |
|
25317 | 6029 |
'/etc/hosts' asFilename readStream numAvailableForRead |
21130 | 6030 |
" |
25317 | 6031 |
|
6032 |
"Modified: / 04-03-2020 / 14:40:38 / Stefan Vogel" |
|
20104 | 6033 |
! |
6034 |
||
18327 | 6035 |
readWaitWithTimeoutMs:timeoutOrNil |
612 | 6036 |
"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
|
6037 |
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
|
6038 |
If data is already available, return immediate. |
20259 | 6039 |
Return true if a timeout occurred (i.e. false, if data is available). |
612 | 6040 |
The other threads are not affected by the wait." |
6041 |
||
16480 | 6042 |
|fd inputSema hasTimedout wasBlocked| |
612 | 6043 |
|
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
6044 |
readAhead notNil ifTrue:[^ false]. |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
6045 |
|
25317 | 6046 |
fd := self fileHandle. |
6047 |
fd isNil ifTrue:[ |
|
6048 |
"read will immediately return (with error)" |
|
6049 |
^ false. |
|
6050 |
]. |
|
612 | 6051 |
mode == #writeonly ifTrue:[^ self errorWriteOnly]. |
6052 |
||
6053 |
(OperatingSystem readCheck:fd) ifTrue:[^ false]. |
|
6054 |
||
20104 | 6055 |
"cannot do a readWait (which means possible suspend), |
6056 |
if the processor is not yet initialized; i.e. if a read is attempted |
|
6057 |
during early startup. |
|
6058 |
This may happen, for example, if a MiniDebugger is entered, before |
|
6059 |
process scheduling has been setup. |
|
6060 |
In this case, all I/O operations here will be blocking." |
|
6061 |
||
23726 | 6062 |
Smalltalk isInitialized ifFalse:[ |
25317 | 6063 |
^ false |
23726 | 6064 |
]. |
20104 | 6065 |
|
612 | 6066 |
wasBlocked := OperatingSystem blockInterrupts. |
25134 | 6067 |
(OperatingSystem readCheck:fd) ifTrue:[ |
25317 | 6068 |
hasTimedout := false |
25134 | 6069 |
] ifFalse:[ |
25317 | 6070 |
inputSema := Semaphore name:'readWait'. |
6071 |
hasTimedout := [ |
|
6072 |
Processor signal:inputSema onInput:fd. |
|
6073 |
(inputSema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil. |
|
6074 |
] ifCurtailed:[ |
|
6075 |
Processor disableSemaphore:inputSema. |
|
6076 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
6077 |
]. |
|
6078 |
hasTimedout ifTrue:[ |
|
6079 |
Processor disableSemaphore:inputSema. |
|
6080 |
]. |
|
16480 | 6081 |
]. |
612 | 6082 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
16480 | 6083 |
^ hasTimedout |
22177 | 6084 |
|
6085 |
"Modified: / 09-08-2017 / 11:53:58 / cg" |
|
25317 | 6086 |
"Modified: / 04-03-2020 / 15:05:24 / Stefan Vogel" |
612 | 6087 |
! |
6088 |
||
22683 | 6089 |
readWriteWaitWithTimeoutMs:timeoutOrNil |
6090 |
"suspend the current process, until the receiver |
|
6091 |
becomes ready for reading or writing or a timeout (in milliseconds) expired. |
|
6092 |
Return true if a timeout occurred (i.e. false, if data is available). |
|
6093 |
Return immediate if the receiver is already ready. |
|
6094 |
The other threads are not affected by the wait." |
|
6095 |
||
6096 |
|fd sema hasTimedout wasBlocked| |
|
6097 |
||
6098 |
readAhead notNil ifTrue:[^ false]. |
|
25317 | 6099 |
fd := self fileHandle. |
6100 |
fd isNil ifTrue:[ |
|
6101 |
"read or write will immediately return (with error)" |
|
6102 |
^ false. |
|
22683 | 6103 |
]. |
6104 |
(OperatingSystem readWriteCheck:fd) ifTrue:[^ false]. |
|
6105 |
||
6106 |
wasBlocked := OperatingSystem blockInterrupts. |
|
6107 |
sema := Semaphore name:'readWriteWait'. |
|
23726 | 6108 |
hasTimedout := [ |
25317 | 6109 |
Processor |
6110 |
signal:sema onOutput:fd; |
|
6111 |
signal:sema onInput:fd. |
|
6112 |
(sema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil. |
|
22683 | 6113 |
] ifCurtailed:[ |
25317 | 6114 |
Processor disableSemaphore:sema. |
6115 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
22683 | 6116 |
]. |
6117 |
hasTimedout ifTrue:[ |
|
25317 | 6118 |
Processor disableSemaphore:sema. |
22683 | 6119 |
]. |
6120 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
6121 |
^ hasTimedout |
|
6122 |
||
6123 |
"Modified: / 09-08-2017 / 11:54:03 / cg" |
|
25317 | 6124 |
"Modified: / 04-03-2020 / 15:04:52 / Stefan Vogel" |
22683 | 6125 |
! |
6126 |
||
6127 |
writeExceptionWaitWithTimeoutMs:timeoutOrNil |
|
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
6128 |
"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
|
6129 |
becomes ready for reading or writing or a timeout (in milliseconds) expired. |
20259 | 6130 |
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
|
6131 |
Return immediate if the receiver is already ready. |
5506 | 6132 |
The other threads are not affected by the wait." |
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
6133 |
|
16480 | 6134 |
|fd sema hasTimedout wasBlocked| |
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
6135 |
|
25317 | 6136 |
fd := self fileHandle. |
6137 |
fd isNil ifTrue:[ |
|
6138 |
"write will immediately return (with error)" |
|
6139 |
^ false. |
|
18956 | 6140 |
]. |
6141 |
(OperatingSystem writeExceptionCheck:fd) ifTrue:[^ false]. |
|
6142 |
||
6143 |
wasBlocked := OperatingSystem blockInterrupts. |
|
22177 | 6144 |
sema := Semaphore name:'writeExceptionWait'. |
23726 | 6145 |
hasTimedout := [ |
25317 | 6146 |
Processor |
6147 |
signal:sema onOutput:fd; |
|
6148 |
signal:sema onException:fd. |
|
6149 |
(sema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil. |
|
18956 | 6150 |
] ifCurtailed:[ |
25317 | 6151 |
Processor disableSemaphore:sema. |
6152 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
18956 | 6153 |
]. |
22683 | 6154 |
hasTimedout ifTrue:[ |
25317 | 6155 |
Processor disableSemaphore:sema. |
18956 | 6156 |
]. |
6157 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
6158 |
^ hasTimedout |
|
22177 | 6159 |
|
6160 |
"Modified: / 09-08-2017 / 11:54:10 / cg" |
|
25317 | 6161 |
"Modified: / 04-03-2020 / 15:04:29 / Stefan Vogel" |
18956 | 6162 |
! |
6163 |
||
22683 | 6164 |
writeWaitWithTimeoutMs:timeoutOrNil |
612 | 6165 |
"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
|
6166 |
becomes ready for writing or a timeout (in milliseconds) expired. |
20259 | 6167 |
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
|
6168 |
Return immediate if the receiver is already ready. |
612 | 6169 |
The other threads are not affected by the wait." |
6170 |
||
16480 | 6171 |
|fd outputSema hasTimedout wasBlocked| |
612 | 6172 |
|
25317 | 6173 |
fd := self fileHandle. |
6174 |
fd isNil ifTrue:[ |
|
6175 |
"write will immediately return (with error)" |
|
6176 |
^ false. |
|
612 | 6177 |
]. |
6178 |
mode == #readonly ifTrue:[ |
|
25317 | 6179 |
^ self errorReadOnly |
612 | 6180 |
]. |
25136 | 6181 |
%{ |
6182 |
#ifdef __win32__ |
|
6183 |
{ |
|
25317 | 6184 |
FILEPOINTER f = __FILEVal(__INST(handle)); |
6185 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
|
6186 |
RETURN(false); |
|
6187 |
} |
|
25136 | 6188 |
} |
6189 |
#endif |
|
6190 |
%}. |
|
612 | 6191 |
|
25317 | 6192 |
(OperatingSystem writeCheck:fd) ifTrue:[ |
6193 |
^ false |
|
6194 |
]. |
|
612 | 6195 |
|
6196 |
wasBlocked := OperatingSystem blockInterrupts. |
|
24778 | 6197 |
"/ check again - now inside lock |
25134 | 6198 |
(OperatingSystem writeCheck:fd) ifTrue:[ |
25317 | 6199 |
hasTimedout := false. |
25134 | 6200 |
] ifFalse:[ |
25317 | 6201 |
outputSema := Semaphore name:'writeWait'. |
6202 |
hasTimedout := [ |
|
6203 |
Processor signal:outputSema onOutput:fd. |
|
6204 |
(outputSema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil. |
|
6205 |
] ifCurtailed:[ |
|
6206 |
Processor disableSemaphore:outputSema. |
|
6207 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
6208 |
]. |
|
6209 |
hasTimedout ifTrue:[ |
|
6210 |
Processor disableSemaphore:outputSema. |
|
6211 |
]. |
|
16480 | 6212 |
]. |
612 | 6213 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
16480 | 6214 |
^ hasTimedout |
22177 | 6215 |
|
6216 |
"Modified: / 09-08-2017 / 11:54:14 / cg" |
|
25317 | 6217 |
"Modified: / 04-03-2020 / 15:03:57 / Stefan Vogel" |
612 | 6218 |
! ! |
6219 |
||
6220 |
!ExternalStream methodsFor:'writing'! |
|
6221 |
||
6222 |
cr |
|
6223 |
"append an end-of-line character (or CRLF if in crlf mode). |
|
6224 |
reimplemented for speed" |
|
6225 |
||
23538 | 6226 |
|error| |
6227 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
6228 |
%{ |
12548 | 6229 |
if ((__INST(handleType) == nil) |
6230 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
16368
1efe4d36fd3f
Win32 sockets use handles instead of file pointers
Stefan Vogel <sv@exept.de>
parents:
16308
diff
changeset
|
6231 |
|| (__INST(handleType) == @symbol(socketHandle)) |
12548 | 6232 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
6233 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
23743 | 6234 |
OBJ fp; |
6235 |
||
6236 |
__INST(lastErrorNumber) = nil; |
|
6237 |
if (((fp = __INST(handle)) != nil) |
|
6238 |
&& (__INST(mode) != @symbol(readonly)) |
|
6239 |
&& (__INST(binary) != true) |
|
6240 |
) { |
|
6241 |
FILEPOINTER f = __FILEVal(fp); |
|
6242 |
int _buffered = (__INST(buffered) == true); |
|
6243 |
int len, cnt; |
|
6244 |
char *cp; |
|
6245 |
||
6246 |
if (_buffered) { |
|
6247 |
__WRITING__(f) |
|
6248 |
} |
|
6249 |
{ |
|
6250 |
OBJ mode = __INST(eolMode); |
|
6251 |
||
6252 |
if (mode == @symbol(cr)) { |
|
6253 |
cp = "\r"; len = 1; |
|
6254 |
} else if (mode == @symbol(crlf)) { |
|
6255 |
cp = "\r\n"; len = 2; |
|
6256 |
} else if (mode == @symbol(eot)) { |
|
6257 |
cp = "\004"; len = 1; |
|
6258 |
} else if (mode == @symbol(etx)) { |
|
6259 |
cp = "\003"; len = 1; |
|
6260 |
} else { |
|
6261 |
cp = "\n"; len = 1; |
|
6262 |
} |
|
6263 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6264 |
#ifdef __win32__ |
23743 | 6265 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6266 |
cnt = __win32_fwrite(cp, 1, len, f); |
|
6267 |
} else |
|
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
6268 |
#endif |
23743 | 6269 |
{ |
6270 |
__WRITEBYTES__(cnt, f, cp, len, _buffered, __INST(handleType)); |
|
6271 |
} |
|
6272 |
if (cnt == len) { |
|
6273 |
if (__isSmallInteger(__INST(position))) { |
|
6274 |
INT np = __intVal(__INST(position)) + len; |
|
6275 |
OBJ t; |
|
6276 |
||
6277 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
6278 |
} else { |
|
6279 |
__INST(position) = nil; /* i.e: don't know */ |
|
6280 |
} |
|
6281 |
RETURN ( self ); |
|
6282 |
} |
|
23538 | 6283 |
# ifdef __win32__ |
23743 | 6284 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 6285 |
# endif |
23743 | 6286 |
error = __mkSmallInteger(__threadErrno); |
6287 |
} |
|
612 | 6288 |
} |
6289 |
%}. |
|
23538 | 6290 |
error notNil ifTrue:[ |
23743 | 6291 |
lastErrorNumber := error. |
6292 |
self writeError:error. |
|
6293 |
^ self |
|
23538 | 6294 |
]. |
12395
1db7ea277c93
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
11751
diff
changeset
|
6295 |
handle isNil ifTrue:[self errorNotOpen. ^ self]. |
2326 | 6296 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
21139 | 6297 |
binary ifTrue:[self errorBinary. ^ self]. |
5414 | 6298 |
|
17426
6e49243ce4e0
fix: code treated everything but nl,cr,crnl symbols als cr (by accident).
Claus Gittinger <cg@exept.de>
parents:
17420
diff
changeset
|
6299 |
(eolMode == #cr) ifTrue:[ |
23743 | 6300 |
self nextPut:(Character return). |
6301 |
^ 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
|
6302 |
]. |
6e49243ce4e0
fix: code treated everything but nl,cr,crnl symbols als cr (by accident).
Claus Gittinger <cg@exept.de>
parents:
17420
diff
changeset
|
6303 |
(eolMode == #crlf) ifTrue:[ |
23743 | 6304 |
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
|
6305 |
]. |
8818
4b1ffc19e3ce
remerged WIN32 and Unix versions into common source
Claus Gittinger <cg@exept.de>
parents:
8616
diff
changeset
|
6306 |
self nextPut:(Character nl). |
5414 | 6307 |
^ self |
23538 | 6308 |
|
6309 |
"Modified: / 22-11-2018 / 14:41:46 / Stefan Vogel" |
|
612 | 6310 |
! |
6311 |
||
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6312 |
flush |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6313 |
"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
|
6314 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6315 |
%{ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6316 |
__INST(lastErrorNumber) = nil; |
12548 | 6317 |
if ((__INST(handleType) == nil) |
6318 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
6319 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
6320 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
25136 | 6321 |
OBJ fp; |
6322 |
int _buffered = (__INST(buffered) == true); |
|
6323 |
||
6324 |
if ((fp = __INST(handle)) != nil) { |
|
6325 |
if (__INST(mode) != @symbol(readonly)) { |
|
6326 |
if (1 /* _buffered */) { |
|
6327 |
FILEPOINTER f = __FILEVal(fp); |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6328 |
#ifdef __win32__ |
25136 | 6329 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6330 |
__win32_fflush(f); |
|
6331 |
} else { |
|
6332 |
int rslt; |
|
6333 |
||
6334 |
do { |
|
6335 |
__threadErrno = 0; |
|
6336 |
rslt = __STX_C_CALL1("fflush", fflush, f); |
|
6337 |
} while((rslt < 0) && (__threadErrno == EINTR)); |
|
6338 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6339 |
#else /* ! __win32__ */ |
25136 | 6340 |
__BEGIN_INTERRUPTABLE__ |
6341 |
FFLUSH(f); |
|
6342 |
__END_INTERRUPTABLE__ |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6343 |
#endif /* ! __win32__ */ |
25136 | 6344 |
} |
6345 |
} |
|
6346 |
} |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6347 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6348 |
%} |
24045 | 6349 |
|
6350 |
"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
|
6351 |
! |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
6352 |
|
612 | 6353 |
nextPut:aCharacter |
24628 | 6354 |
"write the argument, aCharacter - raise an error if failed. |
24654 | 6355 |
Answer aCharacter. |
6356 |
Only single-byte characters are supported here" |
|
612 | 6357 |
|
16296 | 6358 |
|error| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
6359 |
%{ |
18364 | 6360 |
#ifdef __SCHTEAM__ |
6361 |
STObject handle = self.instVarAt(I_handle); |
|
6362 |
||
6363 |
if ((handle != STObject.Nil) |
|
6364 |
&& (aCharacter.isSTCharacter())) { |
|
25136 | 6365 |
handle.writeChar( aCharacter ); |
6366 |
self.instVarAt_put(I_position, STObject.Nil); |
|
6367 |
return __c__._RETURN(aCharacter); |
|
18364 | 6368 |
} |
6369 |
#else |
|
17332 | 6370 |
__INST(lastErrorNumber) = nil; |
6371 |
if ((__INST(handleType) == nil) |
|
6372 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
6373 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
6374 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
6375 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
25136 | 6376 |
OBJ fp; |
6377 |
||
6378 |
if (((fp = __INST(handle)) != nil) |
|
6379 |
&& (__INST(mode) != @symbol(readonly)) |
|
6380 |
) { |
|
6381 |
FILEPOINTER f = __FILEVal(fp); |
|
6382 |
int _buffered = (__INST(buffered) == true); |
|
6383 |
int cnt; |
|
6384 |
char buff[2]; |
|
6385 |
int nBytes = 1; |
|
6386 |
||
6387 |
if (__INST(binary) != true) { |
|
6388 |
if (__isCharacter(aCharacter)) { |
|
6389 |
unsigned int codePoint = __intVal(__characterVal(aCharacter)); |
|
6390 |
if (codePoint <= 0xFF) { |
|
6391 |
unsigned char c = codePoint; |
|
6392 |
buff[0] = c; nBytes = 1; |
|
6393 |
||
6394 |
if (c == '\n') { |
|
6395 |
OBJ mode = __INST(eolMode); |
|
6396 |
if (mode == @symbol(nl)) { |
|
6397 |
// no EOL translation |
|
6398 |
} else if (mode == nil) { |
|
6399 |
// no EOL translation |
|
6400 |
} else if (mode == @symbol(cr)) { |
|
6401 |
buff[0] = '\r'; |
|
6402 |
} else if (mode == @symbol(eot)) { |
|
6403 |
buff[0] = '\004'; |
|
6404 |
} else if (mode == @symbol(etx)) { |
|
6405 |
buff[0] = '\003'; |
|
6406 |
} else if (mode == @symbol(crlf)) { |
|
6407 |
buff[0] = '\r'; |
|
6408 |
buff[1] = '\n'; |
|
6409 |
nBytes = 2; |
|
6410 |
} |
|
6411 |
} |
|
17332 | 6412 |
doWrite: |
25136 | 6413 |
if (! f) { |
6414 |
fprintf(stderr, "oops - fileHandle is NULL in nextPut:\n"); |
|
6415 |
__INST(handle) = nil; |
|
6416 |
goto out; |
|
6417 |
} |
|
6418 |
||
6419 |
if (_buffered) { |
|
6420 |
__WRITING__(f) |
|
6421 |
} |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6422 |
# ifdef __win32__ |
25136 | 6423 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6424 |
cnt = __win32_fwrite(buff, 1, nBytes, f); |
|
6425 |
} else |
|
18364 | 6426 |
# endif |
25136 | 6427 |
{ |
6428 |
__WRITEBYTES__(cnt, f, buff, nBytes, _buffered, __INST(handleType)); |
|
6429 |
} |
|
6430 |
if (cnt == nBytes) { |
|
6431 |
if (__isSmallInteger(__INST(position))) { |
|
6432 |
INT np = __intVal(__INST(position)) + nBytes; |
|
6433 |
OBJ t; |
|
6434 |
||
6435 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
6436 |
} else { |
|
6437 |
__INST(position) = nil; /* i.e. do not know */ |
|
6438 |
} |
|
6439 |
RETURN ( aCharacter ); |
|
6440 |
} |
|
23538 | 6441 |
# ifdef __win32__ |
25136 | 6442 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 6443 |
# endif |
25136 | 6444 |
error = __mkSmallInteger(__threadErrno); |
6445 |
} |
|
6446 |
} |
|
6447 |
} else { |
|
6448 |
if (__isSmallInteger(aCharacter)) { |
|
6449 |
unsigned char c = __intVal(aCharacter); |
|
6450 |
buff[0] = c; nBytes = 1; |
|
6451 |
goto doWrite; |
|
6452 |
} |
|
6453 |
} |
|
6454 |
} |
|
17332 | 6455 |
} |
6456 |
out: ; |
|
18364 | 6457 |
#endif /* not SCHTEAM */ |
17332 | 6458 |
%}. |
6459 |
error notNil ifTrue:[ |
|
25136 | 6460 |
lastErrorNumber := error. |
6461 |
self writeError:error. |
|
6462 |
^ aCharacter |
|
17332 | 6463 |
]. |
6464 |
handle isNil ifTrue:[self errorNotOpen. ^ self]. |
|
6465 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
|
21139 | 6466 |
binary == true ifTrue:[ |
25136 | 6467 |
aCharacter isInteger ifFalse:[ |
6468 |
self argumentMustBeInteger. |
|
6469 |
^ aCharacter. |
|
6470 |
]. |
|
21139 | 6471 |
] ifFalse:[ |
25136 | 6472 |
(aCharacter isCharacter not |
6473 |
or:[aCharacter codePoint > 16rFF]) ifTrue:[ |
|
6474 |
self argumentMustBeCharacter. |
|
6475 |
^ aCharacter. |
|
6476 |
]. |
|
17332 | 6477 |
]. |
6478 |
"/ migration support |
|
6479 |
self |
|
25136 | 6480 |
nextPutByte:aCharacter asInteger |
6481 |
toFile:handle. |
|
24646 | 6482 |
^ aCharacter |
23538 | 6483 |
|
6484 |
"Modified: / 22-11-2018 / 14:47:13 / Stefan Vogel" |
|
17332 | 6485 |
! |
6486 |
||
17418 | 6487 |
nextPutAll:aCollection |
6488 |
"write all elements of the argument, aCollection. |
|
24640 | 6489 |
Answer the receiver. |
17418 | 6490 |
Reimplemented for speed when writing strings or byteArrays. |
6491 |
For others, falls back to general method in superclass." |
|
6492 |
||
6493 |
|error| |
|
6494 |
%{ |
|
18364 | 6495 |
#ifdef __SCHTEAM__ |
6496 |
STObject handle = self.instVarAt(I_handle); |
|
6497 |
||
6498 |
if ((handle != STObject.Nil) |
|
6499 |
&& (aCollection.isSTString())) { |
|
25136 | 6500 |
handle.writeCharacters( aCollection.asSTString().characters ); |
6501 |
self.instVarAt_put(I_position, STObject.Nil); |
|
6502 |
return __c__._RETURN_self(); |
|
18364 | 6503 |
} |
6504 |
#else |
|
17418 | 6505 |
|
6506 |
__INST(lastErrorNumber) = nil; |
|
6507 |
||
6508 |
if ((__INST(handleType) == nil) |
|
6509 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
6510 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
6511 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
6512 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
25136 | 6513 |
OBJ fp; |
6514 |
||
6515 |
if (((fp = __INST(handle)) != nil) |
|
6516 |
&& (__INST(mode) != @symbol(readonly)) |
|
6517 |
) { |
|
6518 |
INT len, cnt; |
|
6519 |
INT o_offs; |
|
6520 |
FILEPOINTER f = __FILEVal(fp); |
|
6521 |
int _buffered = (__INST(buffered) == true); |
|
6522 |
||
6523 |
if (! f) { |
|
6524 |
fprintf(stderr, "oops - fileHandle is NULL in nextPutAll:\n"); |
|
6525 |
__INST(handle) = nil; |
|
6526 |
goto out; |
|
6527 |
} |
|
6528 |
if (_buffered) { |
|
6529 |
__WRITING__(f) |
|
6530 |
} |
|
6531 |
||
6532 |
if (__isStringLike(aCollection)) { |
|
6533 |
OBJ mode = __INST(eolMode); |
|
6534 |
char *stringP = __stringVal(aCollection); |
|
6535 |
len = __stringSize(aCollection); |
|
6536 |
||
6537 |
if (__INST(binary) != true |
|
6538 |
&& ((mode == @symbol(cr)) |
|
6539 |
|| (mode == @symbol(etx)) |
|
6540 |
|| (mode == @symbol(eot)) |
|
6541 |
|| (mode == @symbol(crlf))) |
|
6542 |
&& memchr(stringP, '\n', len) != NULL) |
|
6543 |
{ |
|
6544 |
// there is a '\n' to be translated, replace it into a buffer |
|
6545 |
||
6546 |
char *end; |
|
6547 |
char sep[2]; |
|
6548 |
int sepLen = 1; |
|
6549 |
int bufLen; |
|
6550 |
char *buf, *endBuf, *sp, *dp; |
|
6551 |
||
6552 |
sep[0] = '\n'; |
|
6553 |
if (mode == @symbol(crlf)) { |
|
6554 |
sep[0] = '\r'; sep[1] = '\n'; sepLen = 2; |
|
6555 |
} else if (mode == @symbol(cr)) { |
|
6556 |
sep[0] = '\r'; |
|
6557 |
} else if (mode == @symbol(eot)) { |
|
6558 |
sep[0] = '\004'; |
|
6559 |
} else if (mode == @symbol(etx)) { |
|
6560 |
sep[0] = '\003'; |
|
6561 |
} |
|
6562 |
||
6563 |
// estimate size of buffer - assume every 4th char is a separator |
|
6564 |
bufLen = (sepLen == 1) ? len : (len + ((len/4) + 1) * sepLen); |
|
6565 |
buf = (char *)malloc(bufLen); |
|
6566 |
if (buf == NULL) { |
|
6567 |
error = __mkSmallInteger(ENOMEM); |
|
6568 |
goto out; |
|
6569 |
} |
|
6570 |
||
6571 |
endBuf = buf + bufLen; |
|
6572 |
end = stringP + len; |
|
6573 |
for (sp = stringP, dp = buf; sp < end; sp++) { |
|
6574 |
char c; |
|
6575 |
||
6576 |
if ((dp+sepLen) >= endBuf) { |
|
6577 |
char *newBuf; |
|
6578 |
||
6579 |
bufLen = bufLen * 2; |
|
6580 |
newBuf = (char *)realloc(buf, bufLen); |
|
6581 |
if (newBuf == NULL) { |
|
6582 |
free(buf); |
|
6583 |
error = __mkSmallInteger(ENOMEM); |
|
6584 |
goto out; |
|
6585 |
} |
|
6586 |
endBuf = newBuf + bufLen; |
|
6587 |
dp = newBuf + (dp-buf); |
|
6588 |
buf = newBuf; |
|
6589 |
} |
|
6590 |
||
6591 |
if ((c = *sp) != '\n') { |
|
6592 |
*dp++ = c; |
|
6593 |
} else { |
|
6594 |
*dp++ = sep[0]; |
|
6595 |
if (sepLen == 2) { |
|
6596 |
*dp++ = sep[1]; |
|
6597 |
}; |
|
6598 |
} |
|
6599 |
} |
|
6600 |
||
6601 |
len = dp - buf; |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6602 |
# ifdef __win32__ |
25136 | 6603 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6604 |
cnt = __win32_fwrite(buf, 1, len, f); |
|
6605 |
} else |
|
18364 | 6606 |
# endif |
25136 | 6607 |
{ |
6608 |
__WRITEBYTES__(cnt, f, buf, len, _buffered, __INST(handleType)); |
|
6609 |
} |
|
6610 |
free(buf); |
|
6611 |
} else { // No EOL conversion needed |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6612 |
# ifdef __win32__ |
25136 | 6613 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6614 |
cnt = __win32_fwrite(stringP, 1, len, f); |
|
6615 |
} else |
|
18364 | 6616 |
# endif |
25136 | 6617 |
{ |
6618 |
o_offs = stringP - (char *)__InstPtr(aCollection); |
|
6619 |
__WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs, len, _buffered, __INST(handleType)); |
|
6620 |
} |
|
6621 |
} |
|
6622 |
} else { // Not a String |
|
6623 |
if (__INST(binary) == true) { |
|
6624 |
INT offs; |
|
6625 |
||
6626 |
if (__isByteArrayLike(aCollection)) { |
|
6627 |
offs = 0; |
|
6628 |
len = __byteArraySize(aCollection); |
|
6629 |
} else if (__isBytes(aCollection)) { |
|
6630 |
offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars)); |
|
6631 |
len = __byteArraySize(aCollection) - offs; |
|
6632 |
} else |
|
6633 |
goto out; |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6634 |
# ifdef __win32__ |
25136 | 6635 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6636 |
cnt = __win32_fwrite(__stringVal(aCollection), 1, len, f); |
|
6637 |
} else |
|
18364 | 6638 |
# endif |
25136 | 6639 |
{ |
6640 |
o_offs = (char *)(__ByteArrayInstPtr(aCollection)->ba_element) - (char *)__InstPtr(aCollection); |
|
6641 |
o_offs += offs; |
|
6642 |
__WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs, len, _buffered, __INST(handleType)); |
|
6643 |
} |
|
6644 |
} else // Not binary mode |
|
6645 |
goto out; |
|
6646 |
} |
|
6647 |
||
6648 |
// Now check for errors |
|
6649 |
if (cnt == len) { |
|
6650 |
if (__isSmallInteger(__INST(position))) { |
|
6651 |
INT np = __intVal(__INST(position)) + len; |
|
6652 |
OBJ t; |
|
6653 |
||
6654 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
6655 |
} else { |
|
6656 |
__INST(position) = nil; /* i.e. do not know */ |
|
6657 |
} |
|
6658 |
RETURN (self); |
|
6659 |
} |
|
23538 | 6660 |
# ifdef __win32__ |
25136 | 6661 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 6662 |
# endif |
25136 | 6663 |
error = __mkSmallInteger(__threadErrno); |
6664 |
fprintf(stderr, "cnt=%"_ld_" len=%"_ld_"\n", (INT)cnt, (INT)len); |
|
6665 |
} |
|
17418 | 6666 |
} |
6667 |
out: ; |
|
18364 | 6668 |
#endif /* not SCHTEAM */ |
17418 | 6669 |
%}. |
6670 |
error notNil ifTrue:[ |
|
25136 | 6671 |
lastErrorNumber := error. |
6672 |
self writeError:error. |
|
6673 |
^ self |
|
17418 | 6674 |
]. |
6675 |
handle isNil ifTrue:[self errorNotOpen. ^ self]. |
|
6676 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
|
6677 |
||
24628 | 6678 |
super nextPutAll:aCollection |
23538 | 6679 |
|
6680 |
"Modified: / 22-11-2018 / 11:16:12 / Stefan Vogel" |
|
17418 | 6681 |
! |
6682 |
||
17608 | 6683 |
nextPutAll:initialWriteCount from:buffer startingAt:initialOffset |
22232 | 6684 |
"append count elements with index starting at initialOffset |
6685 |
of the argument, buffer onto the receiver. |
|
6686 |
This is only allowed, if the receiver supports writing. |
|
6687 |
Answer the number of elements that were appended. |
|
6688 |
Buffer should be a byte collection. |
|
20270 | 6689 |
I don't know how to write non-bytes to an external stream, but let superclass handle this." |
17608 | 6690 |
|
22234 | 6691 |
buffer isSingleByteCollection ifTrue:[ |
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
6692 |
^ self nextPutBytes:initialWriteCount from:buffer startingAt:initialOffset. |
17608 | 6693 |
]. |
6694 |
||
6695 |
^ super nextPutAll:initialWriteCount from:buffer startingAt:initialOffset |
|
6696 |
! |
|
6697 |
||
17418 | 6698 |
nextPutAll:aCollection startingAt:start to:stop |
6699 |
"write a range of elements of the argument, aCollection. |
|
6700 |
Reimplemented for speed when writing strings or byteArrays. |
|
6701 |
For others, falls back to general method in superclass." |
|
6702 |
||
6703 |
|error| |
|
6704 |
||
6705 |
%{ |
|
6706 |
__INST(lastErrorNumber) = nil; |
|
6707 |
if ((__INST(handleType) == nil) |
|
6708 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
6709 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
6710 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
6711 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
23743 | 6712 |
OBJ fp = __INST(handle); |
6713 |
||
6714 |
if ((fp != nil) |
|
6715 |
&& (__INST(mode) != @symbol(readonly)) |
|
6716 |
&& __bothSmallInteger(start, stop) |
|
6717 |
) { |
|
6718 |
int _buffered = (__INST(buffered) == true); |
|
6719 |
FILEPOINTER f = __FILEVal(fp); |
|
6720 |
int offs, len, cnt; |
|
6721 |
int iStart = __intVal(start); |
|
6722 |
int iStop = __intVal(stop); |
|
6723 |
int o_offs; |
|
6724 |
||
6725 |
if (_buffered ) { |
|
6726 |
__WRITING__(f) |
|
6727 |
} |
|
6728 |
||
6729 |
if ((iStart < 1) || (iStop < iStart)) { |
|
6730 |
RETURN(self); |
|
6731 |
} |
|
6732 |
if (__isStringLike(aCollection)) { |
|
6733 |
char *stringP; |
|
6734 |
OBJ mode = __INST(eolMode); |
|
6735 |
||
6736 |
len = __stringSize(aCollection); |
|
6737 |
if (iStop > len) { |
|
6738 |
RETURN(self); |
|
6739 |
} |
|
6740 |
if (iStop > len) |
|
6741 |
iStop = len; |
|
6742 |
len = iStop - iStart + 1; |
|
6743 |
stringP = __stringVal(aCollection) + iStart - 1; |
|
6744 |
||
6745 |
if (__INST(binary) != true |
|
6746 |
&& ((mode == @symbol(cr)) |
|
6747 |
|| (mode == @symbol(etx)) |
|
6748 |
|| (mode == @symbol(eot)) |
|
6749 |
|| (mode == @symbol(crlf))) |
|
6750 |
&& memchr(stringP, '\n', len) != NULL) |
|
6751 |
{ |
|
6752 |
// see if there is a \n which needs to be translated, replace it |
|
6753 |
||
6754 |
char *end = stringP + len; |
|
6755 |
char sep[2]; |
|
6756 |
int sepLen = 1; |
|
6757 |
int bufLen; |
|
6758 |
char *buf, *endBuf, *sp, *dp; |
|
6759 |
||
6760 |
sep[0] = '\n'; |
|
6761 |
if (mode == @symbol(crlf)) { |
|
6762 |
sep[0] = '\r'; sep[1] = '\n'; sepLen = 2; |
|
6763 |
} else if (mode == @symbol(cr)) { |
|
6764 |
sep[0] = '\r'; |
|
6765 |
} else if (mode == @symbol(eot)) { |
|
6766 |
sep[0] = '\004'; |
|
6767 |
} else if (mode == @symbol(etx)) { |
|
6768 |
sep[0] = '\003'; |
|
6769 |
} |
|
6770 |
||
6771 |
// estimate size of buffer - assume every 4th char is a separator |
|
6772 |
bufLen = (sepLen == 1) ? len : (len + ((len/4) + 1) * sepLen); |
|
6773 |
buf = (char *)malloc(bufLen); |
|
6774 |
if (buf == NULL) { |
|
6775 |
error = __mkSmallInteger(ENOMEM); |
|
6776 |
goto out; |
|
6777 |
} |
|
6778 |
||
6779 |
endBuf = buf + bufLen; |
|
6780 |
||
6781 |
for (sp = stringP, dp = buf; sp < end; sp++) { |
|
6782 |
char c; |
|
6783 |
||
6784 |
if ((dp+sepLen) >= endBuf) { |
|
6785 |
char *newBuf; |
|
6786 |
||
6787 |
bufLen = bufLen * 2; |
|
6788 |
newBuf = (char *)realloc(buf, bufLen); |
|
6789 |
if (newBuf == NULL) { |
|
6790 |
free(buf); |
|
6791 |
error = __mkSmallInteger(ENOMEM); |
|
6792 |
goto out; |
|
6793 |
} |
|
6794 |
endBuf = newBuf + bufLen; |
|
6795 |
dp = newBuf + (dp-buf); |
|
6796 |
buf = newBuf; |
|
6797 |
} |
|
6798 |
||
6799 |
if ((c = *sp) == '\n') { |
|
6800 |
*dp++ = sep[0]; |
|
6801 |
if (sepLen == 2) { |
|
6802 |
*dp++ = sep[1]; |
|
6803 |
}; |
|
6804 |
} else { |
|
6805 |
*dp++ = c; |
|
6806 |
} |
|
6807 |
} |
|
6808 |
||
6809 |
len = dp - buf; |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6810 |
#ifdef __win32__ |
23743 | 6811 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6812 |
cnt = __win32_fwrite(buf, 1, len, f); |
|
6813 |
} else |
|
17420 | 6814 |
#endif |
23743 | 6815 |
{ |
6816 |
__WRITEBYTES__(cnt, f, buf, len, _buffered, __INST(handleType)); |
|
6817 |
} |
|
6818 |
free(buf); |
|
6819 |
} else { // No EOL conversion needed |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6820 |
#ifdef __win32__ |
23743 | 6821 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6822 |
cnt = __win32_fwrite(stringP, 1, len, f); |
|
6823 |
} else |
|
17420 | 6824 |
#endif |
23743 | 6825 |
{ |
6826 |
o_offs = (char *)__stringVal(aCollection)-(char *)__InstPtr(aCollection); |
|
6827 |
__WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs+iStart-1, len, _buffered, __INST(handleType)); |
|
6828 |
} |
|
6829 |
} |
|
6830 |
} else { // Not a string |
|
6831 |
if (__INST(binary) == true) { |
|
6832 |
int offs; |
|
6833 |
||
6834 |
if (__isByteArrayLike(aCollection)) { |
|
6835 |
offs = 0; |
|
6836 |
len = __byteArraySize(aCollection); |
|
6837 |
} else if (__isBytes(aCollection)) { |
|
6838 |
offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars)); |
|
6839 |
len = __byteArraySize(aCollection) - offs; |
|
6840 |
} else |
|
6841 |
goto out; |
|
6842 |
||
6843 |
if (iStop > len) { |
|
6844 |
RETURN(self); |
|
6845 |
} |
|
6846 |
if (iStop > len) |
|
6847 |
iStop = len; |
|
6848 |
len = iStop - iStart + 1; |
|
6849 |
offs += iStart - 1; |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
6850 |
#ifdef __win32__ |
23743 | 6851 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
6852 |
cnt = __win32_fwrite(__stringVal(aCollection)+iStart-1, 1, len, f); |
|
6853 |
} else |
|
17418 | 6854 |
#endif |
23743 | 6855 |
{ |
6856 |
o_offs = (char *)(__ByteArrayInstPtr(aCollection)->ba_element)-(char *)__InstPtr(aCollection); |
|
6857 |
__WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs+offs, len, _buffered, __INST(handleType)); |
|
6858 |
} |
|
6859 |
} else |
|
6860 |
goto out; |
|
6861 |
} |
|
6862 |
if (cnt == len) { |
|
6863 |
if (__isSmallInteger(__INST(position))) { |
|
6864 |
INT np = __intVal(__INST(position)) + len; |
|
6865 |
OBJ t; |
|
6866 |
||
6867 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
6868 |
} else { |
|
6869 |
__INST(position) = nil; /* i.e. do not know */ |
|
6870 |
} |
|
6871 |
RETURN (self); |
|
6872 |
} |
|
23538 | 6873 |
# ifdef __win32__ |
23743 | 6874 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 6875 |
# endif |
23743 | 6876 |
error = __mkSmallInteger(__threadErrno); |
6877 |
} |
|
17418 | 6878 |
} |
6879 |
out: ; |
|
6880 |
%}. |
|
6881 |
error notNil ifTrue:[ |
|
23743 | 6882 |
lastErrorNumber := error. |
6883 |
self writeError:error. |
|
6884 |
^ self |
|
17418 | 6885 |
]. |
23538 | 6886 |
super nextPutAll:aCollection startingAt:start to:stop |
6887 |
||
6888 |
"Modified: / 22-11-2018 / 12:52:13 / Stefan Vogel" |
|
17418 | 6889 |
! |
6890 |
||
6891 |
nextPutAllUnicode:aString |
|
6892 |
"normal streams can not handle multi-byte characters, so convert them to utf8. |
|
6893 |
This is needed, so that you can do ('something' asUnicode16String errorPrintCR)" |
|
6894 |
||
6895 |
aString do:[:eachCharacter| |
|
23032
3555c5883830
linetoolong warning message and comment
Claus Gittinger <cg@exept.de>
parents:
22978
diff
changeset
|
6896 |
self nextPutUtf8:eachCharacter. |
17418 | 6897 |
]. |
6898 |
||
6899 |
" |
|
25134 | 6900 |
'Bönnigheim' asUnicode16String errorPrintCR |
17418 | 6901 |
" |
6902 |
! |
|
6903 |
||
17608 | 6904 |
nextPutBytes:count from:anObject startingAt:start |
6905 |
"write count bytes from an object starting at index start. |
|
6906 |
return the number of bytes written - which could be 0. |
|
6907 |
The object must have non-pointer indexed instvars |
|
6908 |
(i.e. be a ByteArray, String, Float- or DoubleArray), |
|
6909 |
or an externalBytes object (with known size). |
|
6910 |
||
6911 |
Use with care - non object oriented i/o. |
|
6912 |
Warning: |
|
23743 | 6913 |
in general, you cannot use this method to pass non-byte data to other |
6914 |
architectures (unless you prepared the buffer with care), |
|
6915 |
since it does not care for byte order or float representation." |
|
17608 | 6916 |
|
6917 |
|error| |
|
6918 |
||
6919 |
%{ |
|
18312 | 6920 |
#ifdef __SCHTEAM__ |
6921 |
byte[] bytes; |
|
6922 |
STObject handle = self.instVarAt(I_handle); |
|
6923 |
||
6924 |
if (anObject.isSTString()) { |
|
23743 | 6925 |
char[] chars = anObject.asSTString().characters; |
6926 |
handle.writeCharacters(chars, start.intValue()-1, count.intValue()); |
|
6927 |
self.instVarAt_put(I_position, STObject.Nil); |
|
6928 |
return context._RETURN(count); |
|
18364 | 6929 |
} |
6930 |
if (anObject.isSymbol()) { |
|
23743 | 6931 |
java.lang.String chars = anObject.asSTSymbol().characters; |
6932 |
handle.writeString(chars, start.intValue()-1, count.intValue()); |
|
6933 |
self.instVarAt_put(I_position, STObject.Nil); |
|
6934 |
return context._RETURN(count); |
|
18312 | 6935 |
} |
6936 |
#else |
|
18652
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
6937 |
int ret; |
ee5e81c67497
moved local C variables down into their blcoks
Claus Gittinger <cg@exept.de>
parents:
18636
diff
changeset
|
6938 |
int objSize, nInstBytes; |
17608 | 6939 |
char *extPtr; |
6940 |
OBJ fp; |
|
6941 |
||
6942 |
__INST(lastErrorNumber) = nil; |
|
6943 |
if ((__INST(handleType) == nil) |
|
6944 |
|| (__INST(handleType) == @symbol(filePointer)) |
|
6945 |
|| (__INST(handleType) == @symbol(socketFilePointer)) |
|
6946 |
|| (__INST(handleType) == @symbol(socketHandle)) |
|
6947 |
|| (__INST(handleType) == @symbol(pipeFilePointer))) { |
|
23743 | 6948 |
if (((fp = __INST(handle)) != nil) |
6949 |
&& (__INST(mode) != @symbol(readonly)) |
|
6950 |
&& __bothSmallInteger(count, start) |
|
6951 |
) { |
|
6952 |
int _buffered = (__INST(buffered) == true); |
|
6953 |
FILEPOINTER f = __FILEVal(fp); |
|
6954 |
int len = __intVal(count); |
|
6955 |
int offs = __intVal(start) - 1; |
|
6956 |
||
6957 |
if (__isExternalBytesLike(anObject)) { |
|
6958 |
OBJ sz; |
|
6959 |
||
6960 |
nInstBytes = 0; |
|
6961 |
extPtr = (char *)__externalBytesAddress(anObject); |
|
6962 |
if (extPtr == NULL) goto bad; |
|
6963 |
sz = __externalBytesSize(anObject); |
|
6964 |
if (__isSmallInteger(sz)) { |
|
6965 |
objSize = __intVal(sz); |
|
6966 |
} else { |
|
6967 |
objSize = 0; /* unknown */ |
|
6968 |
} |
|
6969 |
} else { |
|
6970 |
OBJ oClass = __Class(anObject); |
|
6971 |
int nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
6972 |
||
6973 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
6974 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
|
6975 |
case BYTEARRAY: |
|
6976 |
case WORDARRAY: |
|
6977 |
case LONGARRAY: |
|
6978 |
case SWORDARRAY: |
|
6979 |
case SLONGARRAY: |
|
6980 |
case FLOATARRAY: |
|
6981 |
break; |
|
6982 |
case DOUBLEARRAY: |
|
18312 | 6983 |
# ifdef __NEED_DOUBLE_ALIGN |
23743 | 6984 |
nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1); |
18312 | 6985 |
# endif |
23743 | 6986 |
break; |
6987 |
case LONGLONGARRAY: |
|
6988 |
case SLONGLONGARRAY: |
|
18312 | 6989 |
# ifdef __NEED_LONGLONG_ALIGN |
23743 | 6990 |
nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1); |
18312 | 6991 |
# endif |
23743 | 6992 |
break; |
6993 |
default: |
|
6994 |
goto bad; |
|
6995 |
} |
|
6996 |
extPtr = (char *)0; |
|
6997 |
objSize = __Size(anObject) - nInstBytes; |
|
6998 |
} |
|
6999 |
if ( (offs >= 0) && (len >= 0) && (objSize >= (len + offs)) ) { |
|
7000 |
int cnt; |
|
7001 |
||
7002 |
if (_buffered) { |
|
7003 |
__WRITING__(f) |
|
7004 |
} |
|
7005 |
||
7006 |
if (extPtr) { |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
7007 |
# ifdef __win32__ |
23743 | 7008 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
7009 |
cnt = __win32_fwrite(extPtr+offs, 1, len, f); |
|
7010 |
} else |
|
18312 | 7011 |
# endif |
23743 | 7012 |
{ |
7013 |
__WRITEBYTES__(cnt, f, extPtr+offs, len, _buffered, __INST(handleType)); |
|
7014 |
} |
|
7015 |
} else { |
|
7016 |
/* |
|
7017 |
* on interrupt, anObject may be moved to another location. |
|
7018 |
* So we pass anObject, and the offset to the __WRITEBYTES_OBJ__ macro. |
|
7019 |
*/ |
|
7020 |
offs += nInstBytes; |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19767
diff
changeset
|
7021 |
# ifdef __win32__ |
23743 | 7022 |
if ((f == __win32_stdout()) || (f == __win32_stderr())) { |
7023 |
cnt = __win32_fwrite((char *)anObject+offs, 1, len, f); |
|
7024 |
} else |
|
18312 | 7025 |
# endif |
23743 | 7026 |
{ |
7027 |
__WRITEBYTES_OBJ__(cnt, f, anObject, offs, len, _buffered, __INST(handleType)); |
|
7028 |
} |
|
7029 |
} |
|
7030 |
||
7031 |
if (cnt >= 0) { |
|
7032 |
if (__isSmallInteger(__INST(position))) { |
|
7033 |
INT np = __intVal(__INST(position)) + cnt; |
|
7034 |
OBJ t; |
|
7035 |
||
7036 |
t = __MKINT(np); __INST(position) = t; __STORE(self, t); |
|
7037 |
} else { |
|
7038 |
__INST(position) = nil; /* i.e. do not know */ |
|
7039 |
} |
|
7040 |
RETURN ( __mkSmallInteger(cnt) ); |
|
7041 |
} else /* cnt < 0 */ { |
|
7042 |
if ( |
|
18312 | 7043 |
# ifdef EWOULDBLOCK |
23743 | 7044 |
(__threadErrno == EWOULDBLOCK) || |
18312 | 7045 |
# endif |
23743 | 7046 |
(__threadErrno == EAGAIN) |
7047 |
) { |
|
7048 |
RETURN ( __mkSmallInteger(0) ); |
|
7049 |
} |
|
7050 |
__INST(position) = nil; /* i.e. do not know */ |
|
23538 | 7051 |
# ifdef __win32__ |
23743 | 7052 |
__threadErrno = __WIN32_ERR(GetLastError()); |
23538 | 7053 |
# endif |
23743 | 7054 |
error = __mkSmallInteger(__threadErrno); |
7055 |
} |
|
7056 |
} |
|
7057 |
} |
|
17608 | 7058 |
} |
7059 |
bad: ; |
|
18312 | 7060 |
#endif /* not SCHTEAM */ |
17608 | 7061 |
%}. |
7062 |
error notNil ifTrue:[ |
|
23743 | 7063 |
lastErrorNumber := error. |
7064 |
self writeError:error. |
|
7065 |
^ 0 |
|
17608 | 7066 |
]. |
17634 | 7067 |
handle isNil ifTrue:[self errorNotOpen. ^ 0]. |
7068 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ 0]. |
|
7069 |
self primitiveFailed. |
|
7070 |
^ 0. |
|
23538 | 7071 |
|
7072 |
"Modified: / 22-11-2018 / 14:47:58 / Stefan Vogel" |
|
17608 | 7073 |
! |
7074 |
||
17418 | 7075 |
nextPutUnicode:aCharacter |
7076 |
"normal streams can not handle multi-byte characters, so convert them to utf8" |
|
7077 |
||
7078 |
self nextPutUtf8:aCharacter. |
|
612 | 7079 |
! ! |
7080 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
7081 |
!ExternalStream class methodsFor:'documentation'! |
730 | 7082 |
|
7083 |
version |
|
18636 | 7084 |
^ '$Header$' |
12398 | 7085 |
! |
7086 |
||
7087 |
version_CVS |
|
18636 | 7088 |
^ '$Header$' |
730 | 7089 |
! ! |
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6758
diff
changeset
|
7090 |
|
14603 | 7091 |
|
612 | 7092 |
ExternalStream initialize! |