Changeset 388 for trunk/Include/Classes/System/IO/FileStream.ab
- Timestamp:
- Nov 25, 2007, 4:31:35 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Include/Classes/System/IO/FileStream.ab
r349 r388 1 1 Namespace System 2 2 Namespace IO 3 4 3 5 4 /* ほんとはmiscに入れるかかファイルを分けたほうがいいかもしれないが一先ず実装 */ … … 28 27 fileShare As DWord 29 28 fileOptions As DWord 30 fileReadOverlapped As OVERLAPPED31 fileWriteOverlapped As OVERLAPPED29 30 offset As QWord 'オーバーラップドIO用 32 31 33 32 Public … … 108 107 This.fileShare = sh 109 108 This.fileOptions = op 109 This.offset = 0 110 110 End Sub 111 111 Sub FileStream(path As String, mode As FileMode, access As FileAccess, share As FileShare) … … 133 133 This.FileStream(path,mode,access,FileShare.None,FileOptions.None) 134 134 End Sub 135 136 Sub ~FileStream()137 This.Flush()138 This.Close()139 End Sub140 141 135 Public 142 136 Override Function CanRead() As Boolean … … 176 170 Function IsAsync() As Boolean 177 171 /* ファイルが非同期操作に対応しているかを返す */ 178 If This.fileOptions =FILE_FLAG_OVERLAPPED/*FileOptions.Asynchronous*/ Then172 If This.fileOptions And FILE_FLAG_OVERLAPPED /*FileOptions.Asynchronous*/ Then 179 173 Return True 180 174 Else … … 187 181 Dim length As LARGE_INTEGER 188 182 length.LowPart=GetFileSize(This.handle,VarPtr(length.HighPart) As *DWord) 189 Return MAKEQWORD(length.LowPart,length.HighPart) 183 Return MAKEQWORD(length.LowPart,length.HighPart) As Int64 190 184 End If 191 185 End Function 192 186 193 187 Function Name() As String 194 Return New String(This.filePath)188 Return This.filePath 195 189 End Function 196 190 … … 198 192 If This.CanSeek() Then 199 193 If This.IsAsync() Then 200 fileReadOverlapped.Offset=LODWORD(value) 201 fileReadOverlapped.OffsetHigh=HIDWORD(value) 202 fileWriteOverlapped.OffsetHigh=LODWORD(value) 203 fileWriteOverlapped.OffsetHigh=HIDWORD(value) 194 offset = value As QWord 204 195 Else 205 196 Dim position As LARGE_INTEGER … … 213 204 If This.CanSeek() Then 214 205 If This.IsAsync() Then 215 Return MAKEQWORD(fileReadOverlapped.Offset,fileReadOverlapped.OffsetHigh)206 Return offset As Int64 216 207 Else 217 208 Dim position As LARGE_INTEGER 218 209 ZeroMemory(VarPtr(position),SizeOf(LARGE_INTEGER)) 219 210 position.LowPart=SetFilePointer(This.handle,position.LowPart,VarPtr(position.HighPart) As *DWord,FILE_CURRENT) 220 Return MAKEQWORD(position.LowPart,position.HighPart) 211 Return MAKEQWORD(position.LowPart,position.HighPart) As Int64 221 212 End If 222 213 End If … … 257 248 End Function 258 249 259 Override Sub Close()260 This.Dispose()261 End Sub262 263 250 /* CreateObjRef*/ 264 251 265 Override Sub Dispose() 252 Override Sub Dispose(disposing As Boolean) 253 Flush() 266 254 CloseHandle(InterlockedExchangePointer(VarPtr(This.handle),NULL)) 267 255 End Sub 268 256 269 Override Function EndRead( ByRefasyncResult As System.IAsyncResult) As Long270 'TODO 271 End Function 272 273 Override Sub EndWrite( ByRefasyncResult As System.IAsyncResult)257 Override Function EndRead(asyncResult As System.IAsyncResult) As Long 258 'TODO 259 End Function 260 261 Override Sub EndWrite(asyncResult As System.IAsyncResult) 274 262 'TODO 275 263 End Sub … … 298 286 299 287 Sub Lock(position As Int64, length As Int64) 288 If position < 0 Then 289 Throw New ArgumentOutOfRangeException("FileStream.Lock: An argument is negative value.", New System.Int64(position), "position") 290 ElseIf length < 0 Then 291 Throw New ArgumentOutOfRangeException("FileStream.Lock: An argument is negative value.", New System.Int64(length), "length") 292 End If 293 LockFile(handle, LODWORD(position As QWord), HIDWORD(position As QWord), 294 LODWORD(length As QWord), HIDWORD(length As QWord)) 300 295 End Sub 301 296 302 297 Override Function Read( buffer As *Byte, offset As Long, count As Long) As Long 303 298 If This.CanRead() Then 304 Dim ret As DWord 305 If This.IsAsync() Then 306 ReadFile(This.handle,VarPtr(buffer[offset]),count,VarPtr(ret),This.fileReadOverlapped) 307 While This.fileReadOverlapped.Internal=STATUS_PENDING 308 Wend 309 fileReadOverlapped.Offset+=LODWORD(ret) 310 fileReadOverlapped.OffsetHigh+=HIDWORD(ret) 311 fileWriteOverlapped.Offset+=LODWORD(ret) 312 fileWriteOverlapped.OffsetHigh+=HIDWORD(ret) 313 Return ret 314 Else 315 ReadFile(This.handle,VarPtr(buffer[offset]),count,VarPtr(ret),ByVal NULL) 316 Return ret 317 End If 299 Dim readBytes As DWord 300 If This.IsAsync() Then 301 Dim overlapped As OVERLAPPED 302 SetQWord(VarPtr(overlapped.Offset), offset) 303 Dim ret = ReadFile(This.handle, VarPtr(buffer[offset]), count, 0, overlapped) 304 If ret = FALSE Then 305 If GetLastError() = ERROR_IO_PENDING Then 306 GetOverlappedResult(This.handle, overlapped, readBytes, TRUE) 307 End If 308 End If 309 offset += Read 310 Else 311 ReadFile(This.handle,VarPtr(buffer[offset]),count,VarPtr(readBytes),ByVal NULL) 312 End If 313 Read = readBytes As Long 318 314 End If 319 315 End Function … … 326 322 Select Case origin 327 323 Case SeekOrigin.Begin 328 fileReadOverlapped.Offset=LODWORD(offset) 329 fileReadOverlapped.OffsetHigh=HIDWORD(offset) 330 fileWriteOverlapped.OffsetHigh=LODWORD(offset) 331 fileWriteOverlapped.OffsetHigh=HIDWORD(offset) 324 This.offset = offset 332 325 Case SeekOrigin.Current 333 fileReadOverlapped.Offset+=LODWORD(offset) 334 fileReadOverlapped.OffsetHigh+=HIDWORD(offset) 335 fileWriteOverlapped.Offset+=LODWORD(offset) 336 fileWriteOverlapped.OffsetHigh+=HIDWORD(offset) 326 This.offset += offset 337 327 Case SeekOrigin.End 338 fileReadOverlapped.Offset=LODWORD(This.Length()+offset) 339 fileReadOverlapped.OffsetHigh=HIDWORD(This.Length()+offset) 340 fileWriteOverlapped.Offset=LODWORD(This.Length()+offset) 341 fileWriteOverlapped.OffsetHigh=HIDWORD(This.Length()+offset) 328 This.offset = This.Length + offset 342 329 End Select 343 330 Else … … 379 366 380 367 Sub Unlock(position As Int64, length As Int64) 381 End Sub 368 If position < 0 Then 369 Throw New ArgumentOutOfRangeException("FileStream.Lock: An argument is negative value.", New System.Int64(position), "position") 370 ElseIf length < 0 Then 371 Throw New ArgumentOutOfRangeException("FileStream.Lock: An argument is negative value.", New System.Int64(length), "length") 372 End If 373 UnlockFile(handle, LODWORD(position As QWord), HIDWORD(position As QWord), 374 LODWORD(length As QWord), HIDWORD(length As QWord)) 375 End Sub 376 382 377 383 378 Override Sub Write(buffer As *Byte, offset As Long, count As Long) 384 379 If This.CanWrite() Then 385 Dim ret As DWord 386 If This.IsAsync() Then 387 WriteFile(This.handle,VarPtr(buffer[offset]),count,VarPtr(ret),This.fileWriteOverlapped) 388 While This.fileReadOverlapped.Internal=STATUS_PENDING 389 Wend 390 This.fileReadOverlapped.Offset+=LODWORD(ret) 391 This.fileReadOverlapped.OffsetHigh+=HIDWORD(ret) 392 This.fileWriteOverlapped.Offset+=LODWORD(ret) 393 This.fileWriteOverlapped.OffsetHigh+=HIDWORD(ret) 394 Else 395 WriteFile(This.handle,VarPtr(buffer[offset]),count,VarPtr(ret),ByVal NULL) 380 Dim writeBytes As DWord 381 If This.IsAsync() Then 382 Dim overlapped As OVERLAPPED 383 SetQWord(VarPtr(overlapped.Offset), offset) 384 Dim ret = WriteFile(This.handle, VarPtr(buffer[offset]), count, 0, overlapped) 385 If ret = FALSE Then 386 If GetLastError() = ERROR_IO_PENDING Then 387 GetOverlappedResult(This.handle, overlapped, writeBytes, TRUE) 388 End If 389 End If 390 offset += writeBytes 391 Else 392 WriteFile(This.handle, VarPtr(buffer[offset]), count, VarPtr(writeBytes), ByVal NULL) 396 393 End If 397 394 End If
Note:
See TracChangeset
for help on using the changeset viewer.