This is a stripped down version of the 002-fd_type patch I submitted yesterday. Alexandre, let me know if you like this one better. New versions of the subsequent patches are required in any case after today's CVS update. I have them if you want. -- Martin Wilck Phone: +49 5251 8 15113 Fujitsu Siemens Computers Fax: +49 5251 8 20409 Heinz-Nixdorf-Ring 1 mailto:Martin.Wilck@Fujitsu-Siemens.com D-33106 Paderborn http://www.fujitsu-siemens.com/primergy Patch file: 002-fd_type.diff Purpose: More general approach to file descriptor types and flags. Created: 2002-01-08 Applies: CVS 2002-01-08 server/protocol.def: The lowest byte of the type value is reserved for the type itself (macro FD_TYPE (type)the rest is available for miscellaneous flags. New FD flags (were formerly FD types): FD_TYPE_FLAG_OVERLAPPED: The fd uses overlapped I/O. FD_TYPE_FLAG_TIMEOUT: The fd applies a timeout on its I/O operations New test macros: FD_TYPE_IS_OVERLAPPED (type), FD_TYPE_HAS_TIMEOUT (type) server/file.c: file_get_info(): set FD_TYPE_FLAG_OVERLAPPED on overlapped files. server/serial.c: serial_get_info(): account for OVERLAPPED and TIMEOUT flags. files/file.c: ReadFile(): Replace FD_TYPE_XYZ dependent switch statement with an equivalent if/elseif construct which will allow a morte fine-grained destinction of fd types and flags in the future. WriteFile(): dito. Martin Wilck <Martin.Wilck@Fujitsu-Siemens.com> diff -ruX diffignore CVS/wine/files/file.c MW/wine/files/file.c --- CVS/wine/files/file.c Tue Jan 8 10:59:59 2002 +++ MW/wine/files/file.c Tue Jan 8 12:00:39 2002 @@ -1459,9 +1459,8 @@ unix_handle = FILE_GetUnixHandleType( hFile, GENERIC_READ, &type ); - switch (type) + if ( FD_TYPE_IS_OVERLAPPED (type) ) { - case FD_TYPE_OVERLAPPED: if (unix_handle == -1) return FALSE; if ( (overlapped==NULL) || NtResetEvent( overlapped->hEvent, NULL ) ) { @@ -1506,15 +1505,21 @@ /* fail on return, with ERROR_IO_PENDING */ SetLastError(ERROR_IO_PENDING); return FALSE; + } - case FD_TYPE_CONSOLE: + else if ( FD_TYPE (type) == FD_TYPE_CONSOLE ) + { return ReadConsoleA(hFile, buffer, bytesToRead, bytesRead, NULL); + } - case FD_TYPE_TIMEOUT: + else if ( FD_TYPE_HAS_TIMEOUT (type) ) + { close(unix_handle); return FILE_TimeoutRead(hFile, buffer, bytesToRead, bytesRead); + } - default: + else + { /* normal unix files */ if (unix_handle == -1) return FALSE; @@ -1524,7 +1529,6 @@ SetLastError(ERROR_INVALID_PARAMETER); return FALSE; } - break; } /* code for synchronous reads */ @@ -1678,9 +1682,8 @@ unix_handle = FILE_GetUnixHandleType( hFile, GENERIC_WRITE, &type ); - switch (type) + if ( FD_TYPE_IS_OVERLAPPED (type) ) { - case FD_TYPE_OVERLAPPED: if (unix_handle == -1) return FALSE; if ( (overlapped==NULL) || NtResetEvent( overlapped->hEvent, NULL ) ) { @@ -1728,11 +1731,17 @@ SetLastError(ERROR_IO_PENDING); return FALSE; - case FD_TYPE_CONSOLE: + } + + else if ( FD_TYPE (type) == FD_TYPE_CONSOLE ) + { TRACE("%d %s %ld %p %p\n", hFile, debugstr_an(buffer, bytesToWrite), bytesToWrite, bytesWritten, overlapped ); return WriteConsoleA(hFile, buffer, bytesToWrite, bytesWritten, NULL); - default: + } + + else + { if (unix_handle == -1) return FALSE; } diff -ruX diffignore CVS/wine/server/file.c MW/wine/server/file.c --- CVS/wine/server/file.c Tue Jan 8 10:53:08 2002 +++ MW/wine/server/file.c Tue Jan 8 12:01:03 2002 @@ -307,6 +307,7 @@ { struct stat st; struct file *file = (struct file *)obj; + int fd_type = FD_TYPE_DEFAULT; assert( obj->ops == &file_ops ); if (reply) @@ -340,9 +341,9 @@ reply->serial = 0; /* FIXME */ } - if (file->flags & FILE_FLAG_OVERLAPPED) return FD_TYPE_OVERLAPPED; + if (file->flags & FILE_FLAG_OVERLAPPED) fd_type |= FD_TYPE_FLAG_OVERLAPPED; - return FD_TYPE_DEFAULT; + return fd_type; } static struct async_queue *file_queue_async(struct object *obj, struct async *async, int type, int count) diff -ruX diffignore CVS/wine/server/protocol.def MW/wine/server/protocol.def --- CVS/wine/server/protocol.def Mon Jan 7 16:08:44 2002 +++ MW/wine/server/protocol.def Tue Jan 8 11:54:30 2002 @@ -544,12 +544,17 @@ int fd; /* file descriptor */ int type; /* the type of file */ @END +#define FD_TYPE(x) ((x) & 0xff) + #define FD_TYPE_INVALID 0 #define FD_TYPE_DEFAULT 1 #define FD_TYPE_CONSOLE 2 -#define FD_TYPE_OVERLAPPED 3 -#define FD_TYPE_TIMEOUT 4 + +#define FD_TYPE_FLAG_OVERLAPPED 0x100 +#define FD_TYPE_FLAG_TIMEOUT 0x200 +#define FD_TYPE_IS_OVERLAPPED(x) ((x) & FD_TYPE_FLAG_OVERLAPPED) +#define FD_TYPE_HAS_TIMEOUT(x) ((x) & FD_TYPE_FLAG_TIMEOUT) /* Set a file current position */ @REQ(set_file_pointer) diff -ruX diffignore CVS/wine/server/serial.c MW/wine/server/serial.c --- CVS/wine/server/serial.c Mon Jan 7 16:08:44 2002 +++ MW/wine/server/serial.c Tue Jan 8 11:54:30 2002 @@ -192,6 +192,7 @@ static int serial_get_info( struct object *obj, struct get_file_info_reply *reply ) { struct serial *serial = (struct serial *) obj; + int fd_type = FD_TYPE_DEFAULT; assert( obj->ops == &serial_ops ); if (reply) @@ -209,13 +210,13 @@ } if(serial->attrib & FILE_FLAG_OVERLAPPED) - return FD_TYPE_OVERLAPPED; + fd_type |= FD_TYPE_FLAG_OVERLAPPED; - if( (serial->readinterval == MAXDWORD) && - (serial->readmult == 0) && (serial->readconst == 0) ) - return FD_TYPE_DEFAULT; + else if( !((serial->readinterval == MAXDWORD) && + (serial->readmult == 0) && (serial->readconst == 0)) ) + fd_type |= FD_TYPE_FLAG_TIMEOUT; - return FD_TYPE_TIMEOUT; + return fd_type; } static void serial_poll_event(struct object *obj, int event)