From phasis at gmail.com Fri May 2 01:21:24 2008 From: phasis at gmail.com (Heesob Park) Date: Fri, 2 May 2008 14:21:24 +0900 Subject: [Win32utils-devel] rb_w32_select function patch In-Reply-To: <7524A45A1A5B264FA4809E2156496CFB023D321B@ITOMAE2KM01.AD.QINTRA.COM> References: <48167A0B.2060608@gmail.com> <71166b3b0804282355n1f105392h8defbafd83c9152f@mail.gmail.com> <48171385.1030304@gmail.com> <7524A45A1A5B264FA4809E2156496CFB023D321B@ITOMAE2KM01.AD.QINTRA.COM> Message-ID: Hi, 2008/4/30 Berger, Daniel : > > Excellent, thanks! > > With this in place I'm wondering how open3 could be implemented to work > on Windows without fork and without resorting to a C extension. Or if > IO.popen needs to be reworked. Any thoughts? > Before considering open3, there is a remain issue of writing on pipe blocking problem. Blocking on write pipe will block whole application. Here is a test code: readPipe, writePipe = IO.pipe t = Thread.new { sleep 5; while true; sleep 0.1; puts "got #{readPipe.readline.length} bytes"; end } i = 1 while true i += 1 sleep 1 puts "hello from main" if i>3 writePipe.puts "a"*2048 end end t.join I have modified rb_w32_select using NtQueryInformationFile,FilePipeLocalInformation to detect or prevent blocking of pipe write. Here is the latest patch: --- win32.c.org 2008-04-29 14:44:41.000000000 +0900 +++ win32.c 2008-05-02 14:08:10.000000000 +0900 @@ -2046,6 +2050,114 @@ return fileset->fd_count; } +static HANDLE main_select_event=NULL; +static HANDLE *select_thread_list=NULL; + +static DWORD WINAPI +select_read_thread(PVOID argp) +{ + HANDLE fd_handle = (HANDLE)argp; + DWORD ret = 1; + DWORD mode = 0; + + GetConsoleMode(fd_handle,&mode); + if(mode) { + /* Console Input */ + DWORD num_events,num_events_read,pre_num=0; + INPUT_RECORD *input_record; + int i; + + while(1) { + if(WaitForSingleObject(main_select_event,0)!=WAIT_TIMEOUT) break; + GetNumberOfConsoleInputEvents(fd_handle, &num_events); + if(pre_num != num_events) { + input_record = (INPUT_RECORD *)malloc(sizeof(INPUT_RECORD)*num_events); + PeekConsoleInput(fd_handle, input_record, num_events, &num_events_read); + for(i=0;i0) { + return bytes_avail; + } + } + } + return ret; + } + return ret; +} + +typedef DWORD (WINAPI *PNtQueryInformationFile)(HANDLE, PVOID, PVOID, DWORD, DWORD ); +#define FilePipeLocalInformation 24 +typedef struct _FILE_PIPE_LOCAL_INFORMATION { + ULONG NamedPipeType; + ULONG NamedPipeConfiguration; + ULONG MaximumInstances; + ULONG CurrentInstances; + ULONG InboundQuota; + ULONG ReadDataAvailable; + ULONG OutboundQuota; + ULONG WriteQuotaAvailable; + ULONG NamedPipeState; + ULONG NamedPipeEnd; +} FILE_PIPE_LOCAL_INFORMATION, *PFILE_PIPE_LOCAL_INFORMATION; +static PNtQueryInformationFile NtQueryInformationFile=NULL; + +static DWORD WINAPI +select_write_thread(PVOID argp) +{ + HANDLE fd_handle = (HANDLE)argp; + DWORD ret = 1; + DWORD mode = 0; + + GetConsoleMode(fd_handle,&mode); + if(mode) { + /* Console Output */ + return ret; + } else { + DWORD state; + ret = GetNamedPipeHandleState(fd_handle,&state,NULL,NULL,NULL,NULL,0); + if(ret) { + /* Pipe output */ + int bytes_written=0; + int bytes_avail=0; + DWORD iob[2]; + FILE_PIPE_LOCAL_INFORMATION fpli = {0}; + if(NtQueryInformationFile) { + while(1) { + if(WaitForSingleObject(main_select_event,0)!=WAIT_TIMEOUT) break; + ret = NtQueryInformationFile(fd_handle,iob,&fpli,sizeof(fpli),FilePipeLocalInformation); + if(fpli.OutboundQuota==fpli.WriteQuotaAvailable) return ret; + } + } + } + } + return ret; +} + long rb_w32_select (int nfds, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *timeout) @@ -2074,6 +2187,86 @@ file_nfds += extract_file_fd(wr, &file_wr); if (file_nfds) { + DWORD val,exit_code; + int i; + if(!NtQueryInformationFile) + NtQueryInformationFile = (PNtQueryInformationFile) + GetProcAddress(GetModuleHandle("ntdll.dll"),"NtQueryInformationFile" ); + main_select_event = CreateEvent(NULL,TRUE,FALSE,NULL); + if(main_select_event == NULL) + { + printf("CreateEvent failed (%d)\n", GetLastError()); + return -1; + } + select_thread_list = malloc(sizeof(HANDLE)*(file_nfds+1)); + for(i=0; itv_sec * 1000 + timeout->tv_usec / 1000); + else + r = WaitForMultipleObjects(file_nfds+1,select_thread_list,FALSE, + INFINITE); + + if (!SetEvent(main_select_event) ) + { + printf("SetEvent failed (%d)\n", GetLastError()); + return -1; + } + /* thread cleanup */ + for(i=0;i References: <7524A45A1A5B264FA4809E2156496CFB023D3222@ITOMAE2KM01.AD.QINTRA.COM> Message-ID: <7524A45A1A5B264FA4809E2156496CFB023D3239@ITOMAE2KM01.AD.QINTRA.COM> > -----Original Message----- > From: win32utils-devel-bounces at rubyforge.org > [mailto:win32utils-devel-bounces at rubyforge.org] On Behalf Of > Heesob Park > Sent: Wednesday, April 30, 2008 6:42 PM > To: Development and ideas for win32utils projects > Subject: Re: [Win32utils-devel] Playing with NtQueryInformationFile > > Hi, > > 2008/5/1 Berger, Daniel : > > Hi all, > > > > I'm trying to get the allocation size of a file via a file handle > > (rather than its name). The example below works for > > FileNameInformation but I can't get it to work as expected > for FileStandardInformation. > > > > Here's some sample code: > > > > # query_test.rb > > require 'windows/handle' > > require 'windows/error' > > include Windows::Handle > > include Windows::Error > > > > NtQueryInformationFile = API.new('NtQueryInformationFile', 'LPPLL', > > 'L', > > 'ntdll') > > > > # http://msdn.microsoft.com/en-us/library/cc232064.aspx > > FileNameInformation = 9 > > FileStandardInformation = 5 > > STATUS_SUCCESS = 0 > > > > fh = File.open('test.txt', 'w') > > fh.puts "hello" > > > > handle = get_osfhandle(fh.fileno) > > > > if handle == INVALID_HANDLE_VALUE > > puts "ERROR, get_osfhandle() : " + get_last_error > > fh.close rescue nil > > File.delete('test.txt') > > exit > > end > > > > # Excessive but harmless (?) > > io_status_block = 0.chr * 512 > > file_information = 0.chr * 512 > > > > status = NtQueryInformationFile.call( > > handle, > > io_status_block, > > file_information, > > file_information.size, > > # FileStandardInformation # Doesn't work as expected > > FileNameInformation # But this does > > ) > > > > if status != STATUS_SUCCESS > > puts "ERROR, NtQueryInformationFile() : #{status}" > > fh.close > > File.delete('test.txt') > > exit > > end > > > > # p file_information[0, 8].unpack('L')[0] # Zero ??? # Use with > > FileStandardInformation > > > > p file_information[0,4].unpack('L')[0] / 2 # Unicode p > > file_information[4,file_information.length].tr("\000",'').strip > > > > fh.close > > > > # end query_test.rb > > > > The above will print the file name (without the drive > letter) as well > > as the length of the file name, which varies depending on whatever > > path you created 'test.txt' on. > > > > However, if I try to replace "FileNameInformation" with > > "FileStandardInformation" and inspect the first 8 bytes of > > file_information (the AllocationSize), it's always zero. The only > > thing I get out of the buffer at all is the NumberOfLinks, > which is always 1. > > > > What am I doing wrong? > > > > Insert fh.flush atfer fh.puts "hello" must be required. > Following code will work for you: > > fh = File.open('test.txt', 'w') > fh.puts "hello" > fh.flush > handle = get_osfhandle(fh.fileno) > io_status_block = 0.chr * 8 > file_information = 0.chr * 0x18 > status = NtQueryInformationFile.call( > handle, > io_status_block, > file_information, > file_information.size, > FileStandardInformation > ) > > For the actual buffer size, Reter to > > http://undocumented.ntinternals.net/ > http://undocumented.ntinternals.net/UserMode/Undocumented%20Fu > nctions/NT%20Objects/File/FILE_INFORMATION_CLASS.html Many thanks, that works. The AllocationSize returns the sectors, but I don't see a structure that gives me bytes per sector. Or is it always 512? Thanks, Dan This communication is the property of Qwest and may contain confidential or privileged information. Unauthorized use of this communication is strictly prohibited and may be unlawful. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy all copies of the communication and any attachments. From Daniel.Berger at qwest.com Tue May 6 16:24:47 2008 From: Daniel.Berger at qwest.com (Berger, Daniel) Date: Tue, 6 May 2008 15:24:47 -0500 Subject: [Win32utils-devel] Playing with NtQueryInformationFile In-Reply-To: <7524A45A1A5B264FA4809E2156496CFB023D3239@ITOMAE2KM01.AD.QINTRA.COM> References: <7524A45A1A5B264FA4809E2156496CFB023D3222@ITOMAE2KM01.AD.QINTRA.COM> <7524A45A1A5B264FA4809E2156496CFB023D3239@ITOMAE2KM01.AD.QINTRA.COM> Message-ID: <7524A45A1A5B264FA4809E2156496CFB023D323B@ITOMAE2KM01.AD.QINTRA.COM> > The AllocationSize returns the sectors, but I don't see a > structure that gives me bytes per sector. Or is it always 512? Hm, I think I can get this with DeviceIoControl + IOCTL_DISK_GET_DRIVE_GEOMETRY actually. Regards, Dan This communication is the property of Qwest and may contain confidential or privileged information. Unauthorized use of this communication is strictly prohibited and may be unlawful. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy all copies of the communication and any attachments. From Daniel.Berger at qwest.com Tue May 6 17:05:04 2008 From: Daniel.Berger at qwest.com (Berger, Daniel) Date: Tue, 6 May 2008 16:05:04 -0500 Subject: [Win32utils-devel] DeviceIoControl + IOCTL_DISK_GET_DRIVE_GEOMETRY problem Message-ID: <7524A45A1A5B264FA4809E2156496CFB023D323C@ITOMAE2KM01.AD.QINTRA.COM> Hi all, Ok, what am I doing wrong here? require 'windows/device_io' require 'windows/handle' require 'windows/error' include Windows::DeviceIO include Windows::Handle include Windows::Error fh = File.open('test.txt') # Assume you have this handle = get_osfhandle(fh.fileno) if handle == INVALID_HANDLE_VALUE puts "get_osfhandle failed" fh.close exit end buf = 0.chr * 24 # sizeof(DISK_GEOMETRY) bytes = [0].pack('L') bool = DeviceIoControl( handle, IOCTL_DISK_GET_DRIVE_GEOMETRY(), # 458752 nil, 0, buf, buf.size, bytes, 0 ) # Fails here unless bool puts "DeviceIoControl failed: " + get_last_error fh.close exit End fh.close Thanks, Dan PS - I've added several IOCTL macro methods to Windows::DeviceIO in CVS (part of windows-pr). This communication is the property of Qwest and may contain confidential or privileged information. Unauthorized use of this communication is strictly prohibited and may be unlawful. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy all copies of the communication and any attachments. From phasis at gmail.com Tue May 6 21:38:13 2008 From: phasis at gmail.com (Heesob Park) Date: Wed, 7 May 2008 10:38:13 +0900 Subject: [Win32utils-devel] DeviceIoControl + IOCTL_DISK_GET_DRIVE_GEOMETRY problem In-Reply-To: <7524A45A1A5B264FA4809E2156496CFB023D323C@ITOMAE2KM01.AD.QINTRA.COM> References: <7524A45A1A5B264FA4809E2156496CFB023D323C@ITOMAE2KM01.AD.QINTRA.COM> Message-ID: Hi, 2008/5/7 Berger, Daniel : > Hi all, > > Ok, what am I doing wrong here? > > require 'windows/device_io' > require 'windows/handle' > require 'windows/error' > include Windows::DeviceIO > include Windows::Handle > include Windows::Error > > fh = File.open('test.txt') # Assume you have this > > handle = get_osfhandle(fh.fileno) > > if handle == INVALID_HANDLE_VALUE > puts "get_osfhandle failed" > fh.close > exit > end > > buf = 0.chr * 24 # sizeof(DISK_GEOMETRY) > bytes = [0].pack('L') > > bool = DeviceIoControl( > handle, > IOCTL_DISK_GET_DRIVE_GEOMETRY(), # 458752 > nil, > 0, > buf, > buf.size, > bytes, > 0 > ) > > # Fails here > unless bool > puts "DeviceIoControl failed: " + get_last_error > fh.close > exit > End > > fh.close > > Thanks, > > Dan > > PS - I've added several IOCTL macro methods to Windows::DeviceIO in CVS > (part of windows-pr). > > What do you want to do? DeviceIoControl works not with file handle but with device handle. Here is a working code: require 'windows/file' require 'windows/device_io' require 'windows/handle' require 'windows/error' include Windows::File include Windows::DeviceIO include Windows::Handle include Windows::Error buf = 0.chr * 24 # sizeof(DISK_GEOMETRY) bytes = [0].pack('L') handle = CreateFile("\\\\.\\c:",0,FILE_SHARE_READ|FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0) bool = DeviceIoControl( handle, IOCTL_DISK_GET_DRIVE_GEOMETRY(), # 458752 nil, 0, buf, buf.size, bytes, 0 ) unless bool puts "DeviceIoControl failed: " + get_last_error fh.close exit end Regards, Park Heesob From djberg96 at gmail.com Tue May 6 21:45:53 2008 From: djberg96 at gmail.com (Daniel Berger) Date: Tue, 6 May 2008 19:45:53 -0600 Subject: [Win32utils-devel] DeviceIoControl + IOCTL_DISK_GET_DRIVE_GEOMETRY problem In-Reply-To: References: <7524A45A1A5B264FA4809E2156496CFB023D323C@ITOMAE2KM01.AD.QINTRA.COM> Message-ID: <6037b70c0805061845k5014ab28g6d548e921640f741@mail.gmail.com> On Tue, May 6, 2008 at 7:38 PM, Heesob Park wrote: > Hi, > > 2008/5/7 Berger, Daniel : > > > > Hi all, > > > > Ok, what am I doing wrong here? > > > > require 'windows/device_io' > > require 'windows/handle' > > require 'windows/error' > > include Windows::DeviceIO > > include Windows::Handle > > include Windows::Error > > > > fh = File.open('test.txt') # Assume you have this > > > > handle = get_osfhandle(fh.fileno) > > > > if handle == INVALID_HANDLE_VALUE > > puts "get_osfhandle failed" > > fh.close > > exit > > end > > > > buf = 0.chr * 24 # sizeof(DISK_GEOMETRY) > > bytes = [0].pack('L') > > > > bool = DeviceIoControl( > > handle, > > IOCTL_DISK_GET_DRIVE_GEOMETRY(), # 458752 > > nil, > > 0, > > buf, > > buf.size, > > bytes, > > 0 > > ) > > > > # Fails here > > unless bool > > puts "DeviceIoControl failed: " + get_last_error > > fh.close > > exit > > End > > > > fh.close > > > > Thanks, > > > > Dan > > > > PS - I've added several IOCTL macro methods to Windows::DeviceIO in CVS > > (part of windows-pr). > > > > > What do you want to do? > DeviceIoControl works not with file handle but with device handle. Hm, is there any way to go from file handle to device handle? Thanks, Dan From phasis at gmail.com Wed May 7 02:32:42 2008 From: phasis at gmail.com (Heesob Park) Date: Wed, 7 May 2008 15:32:42 +0900 Subject: [Win32utils-devel] DeviceIoControl + IOCTL_DISK_GET_DRIVE_GEOMETRY problem In-Reply-To: <6037b70c0805061845k5014ab28g6d548e921640f741@mail.gmail.com> References: <7524A45A1A5B264FA4809E2156496CFB023D323C@ITOMAE2KM01.AD.QINTRA.COM> <6037b70c0805061845k5014ab28g6d548e921640f741@mail.gmail.com> Message-ID: 2008/5/7 Daniel Berger : > > On Tue, May 6, 2008 at 7:38 PM, Heesob Park wrote: > > Hi, > > > > 2008/5/7 Berger, Daniel : > > > > > > > Hi all, > > > > > > Ok, what am I doing wrong here? > > > > > > require 'windows/device_io' > > > require 'windows/handle' > > > require 'windows/error' > > > include Windows::DeviceIO > > > include Windows::Handle > > > include Windows::Error > > > > > > fh = File.open('test.txt') # Assume you have this > > > > > > handle = get_osfhandle(fh.fileno) > > > > > > if handle == INVALID_HANDLE_VALUE > > > puts "get_osfhandle failed" > > > fh.close > > > exit > > > end > > > > > > buf = 0.chr * 24 # sizeof(DISK_GEOMETRY) > > > bytes = [0].pack('L') > > > > > > bool = DeviceIoControl( > > > handle, > > > IOCTL_DISK_GET_DRIVE_GEOMETRY(), # 458752 > > > nil, > > > 0, > > > buf, > > > buf.size, > > > bytes, > > > 0 > > > ) > > > > > > # Fails here > > > unless bool > > > puts "DeviceIoControl failed: " + get_last_error > > > fh.close > > > exit > > > End > > > > > > fh.close > > > > > > Thanks, > > > > > > Dan > > > > > > PS - I've added several IOCTL macro methods to Windows::DeviceIO in CVS > > > (part of windows-pr). > > > > > > > > What do you want to do? > > DeviceIoControl works not with file handle but with device handle. > > > > Hm, is there any way to go from file handle to device handle? > It is possible but not easy. Refer to http://msdn.microsoft.com/en-us/library/aa366789.aspx Regards, Park Heesob From phasis at gmail.com Wed May 7 02:51:51 2008 From: phasis at gmail.com (Heesob Park) Date: Wed, 7 May 2008 15:51:51 +0900 Subject: [Win32utils-devel] Playing with NtQueryInformationFile In-Reply-To: <7524A45A1A5B264FA4809E2156496CFB023D3239@ITOMAE2KM01.AD.QINTRA.COM> References: <7524A45A1A5B264FA4809E2156496CFB023D3222@ITOMAE2KM01.AD.QINTRA.COM> <7524A45A1A5B264FA4809E2156496CFB023D3239@ITOMAE2KM01.AD.QINTRA.COM> Message-ID: Hi, 2008/5/7 Berger, Daniel : > > > Many thanks, that works. > > The AllocationSize returns the sectors, but I don't see a structure that > gives me bytes per sector. Or is it always 512? > > The AllocationSize returns not sectors but bytes. In my case, it returns 4096. A file has two size. One is actual file size and the other is disk allocation size. Why do you want to get allocation size? Regards, Park Heesob From djberg96 at gmail.com Wed May 7 07:57:23 2008 From: djberg96 at gmail.com (Daniel Berger) Date: Wed, 7 May 2008 05:57:23 -0600 Subject: [Win32utils-devel] Playing with NtQueryInformationFile In-Reply-To: References: <7524A45A1A5B264FA4809E2156496CFB023D3222@ITOMAE2KM01.AD.QINTRA.COM> <7524A45A1A5B264FA4809E2156496CFB023D3239@ITOMAE2KM01.AD.QINTRA.COM> Message-ID: <6037b70c0805070457w47c1e6d3oea94aa23d8105acd@mail.gmail.com> On Wed, May 7, 2008 at 12:51 AM, Heesob Park wrote: > Hi, > > 2008/5/7 Berger, Daniel : > > > > > > > > Many thanks, that works. > > > > The AllocationSize returns the sectors, but I don't see a structure that > > gives me bytes per sector. Or is it always 512? > > > > > The AllocationSize returns not sectors but bytes. > In my case, it returns 4096. > > A file has two size. One is actual file size and the other is disk > allocation size. > Why do you want to get allocation size? I'm trying to get File::Stat#blksize working. It's easy enough when I have the file _name_, but I'd like to get it from the file _handle_ so I can make it work properly. Regards, Dan From djberg96 at gmail.com Wed May 7 08:06:58 2008 From: djberg96 at gmail.com (Daniel Berger) Date: Wed, 7 May 2008 06:06:58 -0600 Subject: [Win32utils-devel] DeviceIoControl + IOCTL_DISK_GET_DRIVE_GEOMETRY problem In-Reply-To: References: <7524A45A1A5B264FA4809E2156496CFB023D323C@ITOMAE2KM01.AD.QINTRA.COM> <6037b70c0805061845k5014ab28g6d548e921640f741@mail.gmail.com> Message-ID: <6037b70c0805070506x7b2fe321i69e347300b9ef97f@mail.gmail.com> On Wed, May 7, 2008 at 12:32 AM, Heesob Park wrote: > 2008/5/7 Daniel Berger : > > > > > > On Tue, May 6, 2008 at 7:38 PM, Heesob Park wrote: > > > Hi, > > > > > > 2008/5/7 Berger, Daniel : > > > > > > > > > > Hi all, > > > > > > > > Ok, what am I doing wrong here? > > > > > > > > require 'windows/device_io' > > > > require 'windows/handle' > > > > require 'windows/error' > > > > include Windows::DeviceIO > > > > include Windows::Handle > > > > include Windows::Error > > > > > > > > fh = File.open('test.txt') # Assume you have this > > > > > > > > handle = get_osfhandle(fh.fileno) > > > > > > > > if handle == INVALID_HANDLE_VALUE > > > > puts "get_osfhandle failed" > > > > fh.close > > > > exit > > > > end > > > > > > > > buf = 0.chr * 24 # sizeof(DISK_GEOMETRY) > > > > bytes = [0].pack('L') > > > > > > > > bool = DeviceIoControl( > > > > handle, > > > > IOCTL_DISK_GET_DRIVE_GEOMETRY(), # 458752 > > > > nil, > > > > 0, > > > > buf, > > > > buf.size, > > > > bytes, > > > > 0 > > > > ) > > > > > > > > # Fails here > > > > unless bool > > > > puts "DeviceIoControl failed: " + get_last_error > > > > fh.close > > > > exit > > > > End > > > > > > > > fh.close > > > > > > > > Thanks, > > > > > > > > Dan > > > > > > > > PS - I've added several IOCTL macro methods to Windows::DeviceIO in CVS > > > > (part of windows-pr). > > > > > > > > > > > What do you want to do? > > > DeviceIoControl works not with file handle but with device handle. > > > > > > > > Hm, is there any way to go from file handle to device handle? > > > It is possible but not easy. > Refer to http://msdn.microsoft.com/en-us/library/aa366789.aspx Yes, I saw that. I was hoping to avoid it. I thought maybe there was an easier way somewhere. Thanks, Dan From phasis at gmail.com Wed May 7 09:18:53 2008 From: phasis at gmail.com (Park Heesob) Date: Wed, 7 May 2008 22:18:53 +0900 Subject: [Win32utils-devel] Playing with NtQueryInformationFile References: <7524A45A1A5B264FA4809E2156496CFB023D3222@ITOMAE2KM01.AD.QINTRA.COM><7524A45A1A5B264FA4809E2156496CFB023D3239@ITOMAE2KM01.AD.QINTRA.COM> <6037b70c0805070457w47c1e6d3oea94aa23d8105acd@mail.gmail.com> Message-ID: <089B085EC91442A4AA45896F2A2820C9@mycomputer> Hi, ----- Original Message ----- From: "Daniel Berger" To: "Development and ideas for win32utils projects" Sent: Wednesday, May 07, 2008 8:57 PM Subject: Re: [Win32utils-devel] Playing with NtQueryInformationFile > On Wed, May 7, 2008 at 12:51 AM, Heesob Park wrote: >> Hi, >> >> 2008/5/7 Berger, Daniel : >> > >> > >> >> >> > Many thanks, that works. >> > >> > The AllocationSize returns the sectors, but I don't see a structure that >> > gives me bytes per sector. Or is it always 512? >> > >> > >> The AllocationSize returns not sectors but bytes. >> In my case, it returns 4096. >> >> A file has two size. One is actual file size and the other is disk >> allocation size. >> Why do you want to get allocation size? > > I'm trying to get File::Stat#blksize working. It's easy enough when I > have the file _name_, but I'd like to get it from the file _handle_ so > I can make it work properly. > You must need some function like 'handle_to_fn'. It can be implemented using NtQueryObject with ObjectNameInformation. Regards, Park Heesob From Daniel.Berger at qwest.com Wed May 7 10:16:48 2008 From: Daniel.Berger at qwest.com (Berger, Daniel) Date: Wed, 7 May 2008 09:16:48 -0500 Subject: [Win32utils-devel] Playing with NtQueryInformationFile In-Reply-To: <089B085EC91442A4AA45896F2A2820C9@mycomputer> References: <7524A45A1A5B264FA4809E2156496CFB023D3222@ITOMAE2KM01.AD.QINTRA.COM><7524A45A1A5B264FA4809E2156496CFB023D3239@ITOMAE2KM01.AD.QINTRA.COM><6037b70c0805070457w47c1e6d3oea94aa23d8105acd@mail.gmail.com> <089B085EC91442A4AA45896F2A2820C9@mycomputer> Message-ID: <7524A45A1A5B264FA4809E2156496CFB023D3242@ITOMAE2KM01.AD.QINTRA.COM> > -----Original Message----- > From: win32utils-devel-bounces at rubyforge.org > [mailto:win32utils-devel-bounces at rubyforge.org] On Behalf Of > Park Heesob > Sent: Wednesday, May 07, 2008 7:19 AM > To: Development and ideas for win32utils projects > Subject: Re: [Win32utils-devel] Playing with NtQueryInformationFile > > Hi, > ----- Original Message ----- > From: "Daniel Berger" > To: "Development and ideas for win32utils projects" > > Sent: Wednesday, May 07, 2008 8:57 PM > Subject: Re: [Win32utils-devel] Playing with NtQueryInformationFile > > > > On Wed, May 7, 2008 at 12:51 AM, Heesob Park > wrote: > >> Hi, > >> > >> 2008/5/7 Berger, Daniel : > >> > > >> > > >> > >> > >> > Many thanks, that works. > >> > > >> > The AllocationSize returns the sectors, but I don't see > a structure that > >> > gives me bytes per sector. Or is it always 512? > >> > > >> > > >> The AllocationSize returns not sectors but bytes. > >> In my case, it returns 4096. > >> > >> A file has two size. One is actual file size and the other is disk > >> allocation size. > >> Why do you want to get allocation size? > > > > I'm trying to get File::Stat#blksize working. It's easy > enough when I > > have the file _name_, but I'd like to get it from the file > _handle_ so > > I can make it work properly. > > > You must need some function like 'handle_to_fn'. > It can be implemented using NtQueryObject with ObjectNameInformation. I messed around with it a little bit but couldn't quite make it work. Do you have a code sample? Thanks, Dan This communication is the property of Qwest and may contain confidential or privileged information. Unauthorized use of this communication is strictly prohibited and may be unlawful. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy all copies of the communication and any attachments. From phasis at gmail.com Wed May 7 10:49:08 2008 From: phasis at gmail.com (Park Heesob) Date: Wed, 7 May 2008 23:49:08 +0900 Subject: [Win32utils-devel] Playing with NtQueryInformationFile References: <7524A45A1A5B264FA4809E2156496CFB023D3222@ITOMAE2KM01.AD.QINTRA.COM><7524A45A1A5B264FA4809E2156496CFB023D3239@ITOMAE2KM01.AD.QINTRA.COM><6037b70c0805070457w47c1e6d3oea94aa23d8105acd@mail.gmail.com><089B085EC91442A4AA45896F2A2820C9@mycomputer> <7524A45A1A5B264FA4809E2156496CFB023D3242@ITOMAE2KM01.AD.QINTRA.COM> Message-ID: ----- Original Message ----- From: "Berger, Daniel" To: "Development and ideas for win32utils projects" Sent: Wednesday, May 07, 2008 11:16 PM Subject: Re: [Win32utils-devel] Playing with NtQueryInformationFile > > >> -----Original Message----- >> From: win32utils-devel-bounces at rubyforge.org >> [mailto:win32utils-devel-bounces at rubyforge.org] On Behalf Of >> Park Heesob >> Sent: Wednesday, May 07, 2008 7:19 AM >> To: Development and ideas for win32utils projects >> Subject: Re: [Win32utils-devel] Playing with NtQueryInformationFile >> >> Hi, >> ----- Original Message ----- >> From: "Daniel Berger" >> To: "Development and ideas for win32utils projects" >> >> Sent: Wednesday, May 07, 2008 8:57 PM >> Subject: Re: [Win32utils-devel] Playing with NtQueryInformationFile >> >> >> > On Wed, May 7, 2008 at 12:51 AM, Heesob Park >> wrote: >> >> Hi, >> >> >> >> 2008/5/7 Berger, Daniel : >> >> > >> >> > >> >> >> >> >> >> > Many thanks, that works. >> >> > >> >> > The AllocationSize returns the sectors, but I don't see >> a structure that >> >> > gives me bytes per sector. Or is it always 512? >> >> > >> >> > >> >> The AllocationSize returns not sectors but bytes. >> >> In my case, it returns 4096. >> >> >> >> A file has two size. One is actual file size and the other is disk >> >> allocation size. >> >> Why do you want to get allocation size? >> > >> > I'm trying to get File::Stat#blksize working. It's easy >> enough when I >> > have the file _name_, but I'd like to get it from the file >> _handle_ so >> > I can make it work properly. >> > >> You must need some function like 'handle_to_fn'. >> It can be implemented using NtQueryObject with ObjectNameInformation. > > I messed around with it a little bit but couldn't quite make it work. Do > you have a code sample? > Here is a sample code: require 'windows/handle' require 'windows/unicode' require 'windows/error' include Windows::Handle include Windows::Unicode include Windows::Error NtQueryObject = API.new('NtQueryObject', 'LLPLP', 'L','ntdll') ObjectNameInformation = 1 fh = File.open('test.txt', 'r') handle = get_osfhandle(fh.fileno) MAX_PATH = 256 object_name_information = 0.chr * (8 + MAX_PATH*2) status = NtQueryObject.call( handle, ObjectNameInformation, object_name_information, object_name_information.size, 0 ) puts wide_to_multi(object_name_information[8..-1]) fh.close Regards, Park Heesob From djberg96 at gmail.com Sun May 11 15:23:34 2008 From: djberg96 at gmail.com (Daniel Berger) Date: Sun, 11 May 2008 13:23:34 -0600 Subject: [Win32utils-devel] converting a RSTRING to an OLESTR Message-ID: <482747B6.4080708@gmail.com> Hi, I was going to modify the TaskScheduler#save method to take an optional file name. But, I need to convert a Ruby string to an OLE string. I thought I could use this: http://msdn.microsoft.com/en-us/library/ms692615(VS.85).aspx But, it only appears to accept literal string constants. Any other suggestions? Thanks, Dan From djberg96 at gmail.com Sun May 11 16:39:25 2008 From: djberg96 at gmail.com (Daniel Berger) Date: Sun, 11 May 2008 14:39:25 -0600 Subject: [Win32utils-devel] Latest rb_win32_select patch Message-ID: <4827597D.6000904@gmail.com> Hi Park, I tried your latest patch and ran the sample code: readPipe, writePipe = IO.pipe t = Thread.new{ sleep 5 while true sleep 0.1 puts "got #{readPipe.readline.length} bytes" end } i = 1 while true i += 1 sleep 1 puts "hello from main" if i > 3 writePipe.puts "a"*2048 end end t.join At the console I typed the word "world", let it run for a bit, then hit Ctrl-C. It mostly seems to work. Here was the difference between Ruby with your patch and JRuby 1.1.1. # Ruby 1.8.6-114 with patch C:\Documents and Settings\djberge\workspace>ruby pipe_test.rb hello from main hello from main hello from main got 2049 bytes hello from main got 2049 bytes hello from main got 2049 bytes hello from main got 2049 bytes hello from main got 2049 bytes hello from main got 2049 bytes hello from main got 2049 bytes hello from main got 2049 bytes pipe_test.rb:14:in `sleep': Interrupt from pipe_test.rb:14 C:\Documents and Settings\djberge\workspace>world 'world' is not recognized as an internal or external command, operable program or batch file. # Jruby 1.1.1 C:\Documents and Settings\djberge\workspace>c:\jruby\bin\jruby pipe_test.rb hello from main hello from main hello from main hello from main hello from main got 2049 bytes got 2049 bytes got 2049 bytes hello from main got 2049 bytes hello from main got 2049 bytes Terminate batch job (Y/N)? y Is the difference anything we should worry about? Regards, Dan From waynev at gmail.com Sun May 11 16:53:52 2008 From: waynev at gmail.com (Wayne Vucenic) Date: Sun, 11 May 2008 13:53:52 -0700 Subject: [Win32utils-devel] converting a RSTRING to an OLESTR In-Reply-To: <482747B6.4080708@gmail.com> References: <482747B6.4080708@gmail.com> Message-ID: <88c9ce410805111353ja3c1er454936506339336d@mail.gmail.com> Hi Dan, I haven't had to do this in many years, but when I did the _bstr_t routines were what I used: http://msdn.microsoft.com/en-us/library/aa278285(VS.60).aspx An OLE string is really a BSTR isn't it? Anyway, this is all from memory, so I hope it's appropriate for what you're trying to do. Take care, Wayne On Sun, May 11, 2008 at 12:23 PM, Daniel Berger wrote: > Hi, > > I was going to modify the TaskScheduler#save method to take an optional > file name. But, I need to convert a Ruby string to an OLE string. I thought > I could use this: > > http://msdn.microsoft.com/en-us/library/ms692615(VS.85).aspx > > But, it only appears to accept literal string constants. > > Any other suggestions? > > Thanks, > > Dan > > _______________________________________________ > win32utils-devel mailing list > win32utils-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/win32utils-devel > -------------- next part -------------- An HTML attachment was scrubbed... URL: From djberg96 at gmail.com Sun May 11 17:40:18 2008 From: djberg96 at gmail.com (Daniel Berger) Date: Sun, 11 May 2008 15:40:18 -0600 Subject: [Win32utils-devel] converting a RSTRING to an OLESTR In-Reply-To: <88c9ce410805111353ja3c1er454936506339336d@mail.gmail.com> References: <482747B6.4080708@gmail.com> <88c9ce410805111353ja3c1er454936506339336d@mail.gmail.com> Message-ID: <482767C2.6030901@gmail.com> Wayne Vucenic wrote: > Hi Dan, > > I haven't had to do this in many years, but when I did the _bstr_t > routines were what I used: > > http://msdn.microsoft.com/en-us/library/aa278285(VS.60).aspx > > An OLE string is really a BSTR isn't it? Anyway, this is all from > memory, so I hope it's appropriate for what you're trying to do. Thanks, that worked! For the record I had to add comutil.h to the included header files, and add both comsupp.lib and comsuppwd.lib to $LIBS in the extconf.rb file. Regards, Dan From phasis at gmail.com Sun May 11 21:19:55 2008 From: phasis at gmail.com (Park Heesob) Date: Mon, 12 May 2008 10:19:55 +0900 Subject: [Win32utils-devel] Latest rb_win32_select patch References: <4827597D.6000904@gmail.com> Message-ID: <67476729B3D2498FBAB689CAA43F3038@mycomputer> Hi, ----- Original Message ----- From: "Daniel Berger" To: "Development and ideas for win32utils projects" Sent: Monday, May 12, 2008 5:39 AM Subject: [Win32utils-devel] Latest rb_win32_select patch > Hi Park, > > I tried your latest patch and ran the sample code: > > readPipe, writePipe = IO.pipe > > t = Thread.new{ > sleep 5 > while true > sleep 0.1 > puts "got #{readPipe.readline.length} bytes" > end > } > > i = 1 > while true > i += 1 > sleep 1 > puts "hello from main" > if i > 3 > writePipe.puts "a"*2048 > end > end > t.join > > At the console I typed the word "world", let it run for a bit, then hit > Ctrl-C. It mostly seems to work. Here was the difference between Ruby > with your patch and JRuby 1.1.1. > > # Ruby 1.8.6-114 with patch > C:\Documents and Settings\djberge\workspace>ruby pipe_test.rb > hello from main > hello from main > hello from main > got 2049 bytes > hello from main > got 2049 bytes > hello from main > got 2049 bytes > hello from main > got 2049 bytes > hello from main > got 2049 bytes > hello from main > got 2049 bytes > hello from main > got 2049 bytes > hello from main > got 2049 bytes > pipe_test.rb:14:in `sleep': Interrupt > from pipe_test.rb:14 > > C:\Documents and Settings\djberge\workspace>world > 'world' is not recognized as an internal or external command, > operable program or batch file. > > # Jruby 1.1.1 > > C:\Documents and Settings\djberge\workspace>c:\jruby\bin\jruby pipe_test.rb > hello from main > hello from main > hello from main > hello from main > hello from main > got 2049 bytes > got 2049 bytes > got 2049 bytes > hello from main > got 2049 bytes > hello from main > got 2049 bytes > Terminate batch job (Y/N)? y > > Is the difference anything we should worry about? > The patch is very experimental and it comes with ABSOLUTELY NO WARRANTY :) The still remaining problem is the incorrect or unwanted console input handling. I hope someone would fix the problem. Regards, Park Heesob From djberg96 at gmail.com Sun May 11 23:35:47 2008 From: djberg96 at gmail.com (Daniel Berger) Date: Sun, 11 May 2008 21:35:47 -0600 Subject: [Win32utils-devel] Latest rb_win32_select patch In-Reply-To: <67476729B3D2498FBAB689CAA43F3038@mycomputer> References: <4827597D.6000904@gmail.com> <67476729B3D2498FBAB689CAA43F3038@mycomputer> Message-ID: <4827BB13.1070008@gmail.com> Park Heesob wrote: > Hi, > ----- Original Message ----- > From: "Daniel Berger" > To: "Development and ideas for win32utils projects" > Sent: Monday, May 12, 2008 5:39 AM > Subject: [Win32utils-devel] Latest rb_win32_select patch > > >> Hi Park, >> >> I tried your latest patch and ran the sample code: >> >> readPipe, writePipe = IO.pipe >> >> t = Thread.new{ >> sleep 5 >> while true >> sleep 0.1 >> puts "got #{readPipe.readline.length} bytes" >> end >> } >> >> i = 1 >> while true >> i += 1 >> sleep 1 >> puts "hello from main" >> if i > 3 >> writePipe.puts "a"*2048 >> end >> end >> t.join >> >> At the console I typed the word "world", let it run for a bit, then hit >> Ctrl-C. It mostly seems to work. Here was the difference between Ruby >> with your patch and JRuby 1.1.1. >> >> # Ruby 1.8.6-114 with patch >> C:\Documents and Settings\djberge\workspace>ruby pipe_test.rb >> hello from main >> hello from main >> hello from main >> got 2049 bytes >> hello from main >> got 2049 bytes >> hello from main >> got 2049 bytes >> hello from main >> got 2049 bytes >> hello from main >> got 2049 bytes >> hello from main >> got 2049 bytes >> hello from main >> got 2049 bytes >> hello from main >> got 2049 bytes >> pipe_test.rb:14:in `sleep': Interrupt >> from pipe_test.rb:14 >> >> C:\Documents and Settings\djberge\workspace>world >> 'world' is not recognized as an internal or external command, >> operable program or batch file. >> >> # Jruby 1.1.1 >> >> C:\Documents and Settings\djberge\workspace>c:\jruby\bin\jruby pipe_test.rb >> hello from main >> hello from main >> hello from main >> hello from main >> hello from main >> got 2049 bytes >> got 2049 bytes >> got 2049 bytes >> hello from main >> got 2049 bytes >> hello from main >> got 2049 bytes >> Terminate batch job (Y/N)? y >> >> Is the difference anything we should worry about? >> > The patch is very experimental and it comes with ABSOLUTELY NO WARRANTY :) > The still remaining problem is the incorrect or unwanted console input handling. > I hope someone would fix the problem. Sorry if I sounded too critical. I'm just not sure what the proper behavior should be and I'm trying to work it out. I'll see what I can come up with as far as a patch (assuming one is needed). I think our options are easier if we limit ourselves to Win2k or later (or even XP or later). This is still a HUGE improvement over the current MRI behavior. :) Regards, Dan From waynev at gmail.com Mon May 12 02:25:40 2008 From: waynev at gmail.com (Wayne Vucenic) Date: Sun, 11 May 2008 23:25:40 -0700 Subject: [Win32utils-devel] converting a RSTRING to an OLESTR In-Reply-To: <482767C2.6030901@gmail.com> References: <482747B6.4080708@gmail.com> <88c9ce410805111353ja3c1er454936506339336d@mail.gmail.com> <482767C2.6030901@gmail.com> Message-ID: <88c9ce410805112325y7c5dbb05n3f3673581aa8e6af@mail.gmail.com> Great. Glad it worked! Working with OLE strings was a real pain until I found _bstr_t, which made it pretty easy. Take care, Wayne On Sun, May 11, 2008 at 2:40 PM, Daniel Berger wrote: > Wayne Vucenic wrote: > > > Hi Dan, > > I haven't had to do this in many years, but when I did the _bstr_t > > routines were what I used: > > http://msdn.microsoft.com/en-us/library/aa278285(VS.60).aspx > > An OLE string is really a BSTR isn't it? Anyway, this is all from > > memory, so I hope it's appropriate for what you're trying to do. > > > > Thanks, that worked! > > For the record I had to add comutil.h to the included header files, and > add both comsupp.lib and comsuppwd.lib to $LIBS in the extconf.rb file. > > Regards, > > > Dan > _______________________________________________ > win32utils-devel mailing list > win32utils-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/win32utils-devel > -------------- next part -------------- An HTML attachment was scrubbed... URL: From phasis at gmail.com Mon May 12 04:49:21 2008 From: phasis at gmail.com (Park Heesob) Date: Mon, 12 May 2008 17:49:21 +0900 Subject: [Win32utils-devel] Latest rb_win32_select patch References: <4827597D.6000904@gmail.com><67476729B3D2498FBAB689CAA43F3038@mycomputer> <4827BB13.1070008@gmail.com> Message-ID: <2F43DF186D864688B3544863AF09913B@mycomputer> ----- Original Message ----- From: "Daniel Berger" To: "Development and ideas for win32utils projects" Sent: Monday, May 12, 2008 12:35 PM Subject: Re: [Win32utils-devel] Latest rb_win32_select patch > Park Heesob wrote: >> Hi, >> ----- Original Message ----- >> From: "Daniel Berger" >> To: "Development and ideas for win32utils projects" >> Sent: Monday, May 12, 2008 5:39 AM >> Subject: [Win32utils-devel] Latest rb_win32_select patch >> >> >>> Hi Park, >>> >>> I tried your latest patch and ran the sample code: >>> >>> readPipe, writePipe = IO.pipe >>> >>> t = Thread.new{ >>> sleep 5 >>> while true >>> sleep 0.1 >>> puts "got #{readPipe.readline.length} bytes" >>> end >>> } >>> >>> i = 1 >>> while true >>> i += 1 >>> sleep 1 >>> puts "hello from main" >>> if i > 3 >>> writePipe.puts "a"*2048 >>> end >>> end >>> t.join >>> >>> At the console I typed the word "world", let it run for a bit, then hit >>> Ctrl-C. It mostly seems to work. Here was the difference between Ruby >>> with your patch and JRuby 1.1.1. >>> >>> # Ruby 1.8.6-114 with patch >>> C:\Documents and Settings\djberge\workspace>ruby pipe_test.rb >>> hello from main >>> got 2049 bytes >>> pipe_test.rb:14:in `sleep': Interrupt >>> from pipe_test.rb:14 >>> >>> C:\Documents and Settings\djberge\workspace>world >>> 'world' is not recognized as an internal or external command, >>> operable program or batch file. >>> >>> # Jruby 1.1.1 >>> >>> C:\Documents and Settings\djberge\workspace>c:\jruby\bin\jruby pipe_test.rb >>> hello from main >>> got 2049 bytes >>> Terminate batch job (Y/N)? y >>> >>> Is the difference anything we should worry about? >>> >> The patch is very experimental and it comes with ABSOLUTELY NO WARRANTY :) >> The still remaining problem is the incorrect or unwanted console input handling. >> I hope someone would fix the problem. > > Sorry if I sounded too critical. I'm just not sure what the proper > behavior should be and I'm trying to work it out. > I think Ruby's standard platform is Linux, and a different behavior from Linux box regarded as a misbehavior. In my test with the cygwin ruby version, cygwin fails to emulate select system call in colsole input. it act just like my patch version. Emulating Linux select is my goal. But it is not easy for now. Regards, Park Heesob From Daniel.Berger at qwest.com Mon May 12 09:27:53 2008 From: Daniel.Berger at qwest.com (Berger, Daniel) Date: Mon, 12 May 2008 08:27:53 -0500 Subject: [Win32utils-devel] Latest rb_win32_select patch In-Reply-To: <2F43DF186D864688B3544863AF09913B@mycomputer> References: <4827597D.6000904@gmail.com><67476729B3D2498FBAB689CAA43F3038@mycomputer><4827BB13.1070008@gmail.com> <2F43DF186D864688B3544863AF09913B@mycomputer> Message-ID: <7524A45A1A5B264FA4809E2156496CFB023D3251@ITOMAE2KM01.AD.QINTRA.COM> > -----Original Message----- > From: win32utils-devel-bounces at rubyforge.org > [mailto:win32utils-devel-bounces at rubyforge.org] On Behalf Of > Park Heesob > Sent: Monday, May 12, 2008 2:49 AM > To: Development and ideas for win32utils projects > Subject: Re: [Win32utils-devel] Latest rb_win32_select patch > > ----- Original Message ----- > From: "Daniel Berger" > To: "Development and ideas for win32utils projects" > > Sent: Monday, May 12, 2008 12:35 PM > Subject: Re: [Win32utils-devel] Latest rb_win32_select patch > > > > Park Heesob wrote: > >> Hi, > >> ----- Original Message ----- > >> From: "Daniel Berger" > >> To: "Development and ideas for win32utils projects" > > >> Sent: Monday, May 12, 2008 5:39 AM > >> Subject: [Win32utils-devel] Latest rb_win32_select patch > >> > >> > >>> Hi Park, > >>> > >>> I tried your latest patch and ran the sample code: > >>> > >>> readPipe, writePipe = IO.pipe > >>> > >>> t = Thread.new{ > >>> sleep 5 > >>> while true > >>> sleep 0.1 > >>> puts "got #{readPipe.readline.length} bytes" > >>> end > >>> } > >>> > >>> i = 1 > >>> while true > >>> i += 1 > >>> sleep 1 > >>> puts "hello from main" > >>> if i > 3 > >>> writePipe.puts "a"*2048 > >>> end > >>> end > >>> t.join > >>> > >>> At the console I typed the word "world", let it run for a > bit, then hit > >>> Ctrl-C. It mostly seems to work. Here was the difference > between Ruby > >>> with your patch and JRuby 1.1.1. > >>> > >>> # Ruby 1.8.6-114 with patch > >>> C:\Documents and Settings\djberge\workspace>ruby pipe_test.rb > >>> hello from main > > >>> got 2049 bytes > >>> pipe_test.rb:14:in `sleep': Interrupt > >>> from pipe_test.rb:14 > >>> > >>> C:\Documents and Settings\djberge\workspace>world > >>> 'world' is not recognized as an internal or external command, > >>> operable program or batch file. > >>> > >>> # Jruby 1.1.1 > >>> > >>> C:\Documents and > Settings\djberge\workspace>c:\jruby\bin\jruby pipe_test.rb > >>> hello from main > > >>> got 2049 bytes > >>> Terminate batch job (Y/N)? y > >>> > >>> Is the difference anything we should worry about? > >>> > >> The patch is very experimental and it comes with > ABSOLUTELY NO WARRANTY :) > >> The still remaining problem is the incorrect or unwanted > console input handling. > >> I hope someone would fix the problem. > > > > Sorry if I sounded too critical. I'm just not sure what the proper > > behavior should be and I'm trying to work it out. > > > I think Ruby's standard platform is Linux, and a different > behavior from Linux box regarded > as a misbehavior. In my test with the cygwin ruby version, > cygwin fails to emulate select system > call in colsole input. it act just like my patch version. > > Emulating Linux select is my goal. But it is not easy for now. Maybe this is just a platform specific issue that we shouldn't worry about. The behavior on my OS X box was a little different than JRuby even. I did read over this article: http://www.darkcoding.net/software/non-blocking-console-io-is-not-possib le/ Perhaps we could use SetConsoleMode? I haven't played with it yet. Regards, Dan This communication is the property of Qwest and may contain confidential or privileged information. Unauthorized use of this communication is strictly prohibited and may be unlawful. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy all copies of the communication and any attachments. From djberg96 at gmail.com Sat May 17 15:38:40 2008 From: djberg96 at gmail.com (Daniel Berger) Date: Sat, 17 May 2008 13:38:40 -0600 Subject: [Win32utils-devel] Problem reading log with win32-eventlog - buffer too small Message-ID: <482F3440.6070901@gmail.com> Hi all, A user recently ran into an issue with win32-eventlog and the EventLog#read method when reading a saved log file. It seems that there's an issue. After some experimentation I found that the problem seems to be that the initial buffer to ReadEventLog() in line 558 is too small, so it tries a second call to ReadEventLog() with a larger buffer. The problem is that, after I added some error checking code there, the second attempt returns: "The data area passed to a system call is too small" What I can't figure out is why it's failing. The buffer is plenty big, and I even tried setting it to the max value (0x7ffff bytes), but I still get that error. Any ideas? I've attached the log file in question. The error happens right after log entry 136. BTW, I've added some error handling in CVS, so please checkout the latest code. Regards, Dan -------------- next part -------------- A non-text attachment was scrubbed... Name: AppEvent.evt Type: application/octet-stream Size: 373748 bytes Desc: not available URL: From phasis at gmail.com Sat May 17 22:26:59 2008 From: phasis at gmail.com (Park Heesob) Date: Sun, 18 May 2008 11:26:59 +0900 Subject: [Win32utils-devel] Problem reading log with win32-eventlog - buffertoo small References: <482F3440.6070901@gmail.com> Message-ID: <965199A4B1AB4E5F87A18E37DBBA01BF@mycomputer> Hi, ----- Original Message ----- From: "Daniel Berger" To: "win32utils-devel" Sent: Sunday, May 18, 2008 4:38 AM Subject: [Win32utils-devel] Problem reading log with win32-eventlog - buffertoo small > Hi all, > > A user recently ran into an issue with win32-eventlog and the > EventLog#read method when reading a saved log file. It seems that > there's an issue. > > After some experimentation I found that the problem seems to be that the > initial buffer to ReadEventLog() in line 558 is too small, so it tries a > second call to ReadEventLog() with a larger buffer. The problem is that, > after I added some error checking code there, the second attempt returns: > > "The data area passed to a system call is too small" > > What I can't figure out is why it's failing. The buffer is plenty big, > and I even tried setting it to the max value (0x7ffff bytes), but I > still get that error. > > Any ideas? I've attached the log file in question. The error happens > right after log entry 136. > Modify #561-566 of eventlog.rb if GetLastError() == ERROR_INSUFFICIENT_BUFFER buf = (0.chr * buf.size) + (0.chr * needed.unpack('L')[0]) unless ReadEventLog(@handle, flags, offset, buf, size, read, needed) raise Error, get_last_error end end to if GetLastError() == ERROR_INSUFFICIENT_BUFFER buf = (0.chr * buf.size) + (0.chr * needed.unpack('L')[0]) size = buf.size unless ReadEventLog(@handle, flags, offset, buf, size, read, needed) raise Error, get_last_error end end It is a very simple but invisible bug :) Regards, Park Heesob From djberg96 at gmail.com Sat May 17 22:54:17 2008 From: djberg96 at gmail.com (Daniel Berger) Date: Sat, 17 May 2008 20:54:17 -0600 Subject: [Win32utils-devel] Problem reading log with win32-eventlog - buffertoo small In-Reply-To: <965199A4B1AB4E5F87A18E37DBBA01BF@mycomputer> References: <482F3440.6070901@gmail.com> <965199A4B1AB4E5F87A18E37DBBA01BF@mycomputer> Message-ID: <482F9A59.4080603@gmail.com> Park Heesob wrote: > Hi, > ----- Original Message ----- > From: "Daniel Berger" > To: "win32utils-devel" > Sent: Sunday, May 18, 2008 4:38 AM > Subject: [Win32utils-devel] Problem reading log with win32-eventlog - buffertoo small > > >> Hi all, >> >> A user recently ran into an issue with win32-eventlog and the >> EventLog#read method when reading a saved log file. It seems that >> there's an issue. >> >> After some experimentation I found that the problem seems to be that the >> initial buffer to ReadEventLog() in line 558 is too small, so it tries a >> second call to ReadEventLog() with a larger buffer. The problem is that, >> after I added some error checking code there, the second attempt returns: >> >> "The data area passed to a system call is too small" >> >> What I can't figure out is why it's failing. The buffer is plenty big, >> and I even tried setting it to the max value (0x7ffff bytes), but I >> still get that error. >> >> Any ideas? I've attached the log file in question. The error happens >> right after log entry 136. >> > Modify #561-566 of eventlog.rb > > if GetLastError() == ERROR_INSUFFICIENT_BUFFER > buf = (0.chr * buf.size) + (0.chr * needed.unpack('L')[0]) > unless ReadEventLog(@handle, flags, offset, buf, size, read, needed) > raise Error, get_last_error > end > end > to > if GetLastError() == ERROR_INSUFFICIENT_BUFFER > buf = (0.chr * buf.size) + (0.chr * needed.unpack('L')[0]) > size = buf.size > unless ReadEventLog(@handle, flags, offset, buf, size, read, needed) > raise Error, get_last_error > end > end > > It is a very simple but invisible bug :) Oh, that was silly of me. Wow, that's been there a long time. I guess there aren't many log entries over 64k. :) Many thanks, Dan From djberg96 at gmail.com Sun May 18 00:33:10 2008 From: djberg96 at gmail.com (Daniel Berger) Date: Sat, 17 May 2008 22:33:10 -0600 Subject: [Win32utils-devel] Pure win32-thread library? Message-ID: <482FB186.1060506@gmail.com> Hi all, Here's my initial stab at a pure Ruby win32-thread library that doesn't work at all. I'm not sure how to pass the start address of the arguments to the callback. I thought about Marshal, but you can't marshal a proc. BTW, the CreateThread method in windows-pr needs to be updated for this to have any hope of success. Any ideas? Thanks, Dan # win32/thread.rb require 'windows/thread' require 'windows/synchronize' require 'windows/error' include Windows module Win32 class Thread include Windows::Thread include Windows::Synchronize include Windows::Error extend Windows::Synchronize class Error < StandardError; end @@mutex = CreateMutex(nil, false, nil) ABOVE_NORMAL = THREAD_PRIORITY_ABOVE_NORMAL BELOW_NORMAL = THREAD_PRIORITY_BELOW_NORMAL HIGHEST = THREAD_PRIORITY_HIGHEST IDLE = THREAD_PRIORITY_IDLE LOWEST = THREAD_PRIORITY_LOWEST NORMAL = THREAD_PRIORITY_NORMAL CRITICAL = THREAD_PRIORITY_TIME_CRITICAL VERSION = '0.1.0' WinThreadFunc = API::Callback.new('L', 'L'){ |args| block = args.pop block.call(args) ReleaseMutex(@@mutex) } attr_reader :thread_id def initialize(*args, &block) raise ArgumentError, 'block must be provided' unless block_given? args.push(block) thread_id = [0].pack('L') dwArgs = nil # What should this be? @thread = CreateThread( nil, # Handle cannot be inherited 0, # Default stack size WinThreadFunc, # Pointer to thread func dwArgs, # Arguments passed to thread func 0, # Execute immediately, i.e. not suspended thread_id # Stores the thread id ) if @thread == 0 raise Error, get_last_error end @thread_id = thread_id.unpack('L')[0] end def join(limit = INFINITE) limit = limit * 1000 unless limit == INFINITE WaitForSingleObject(@thread, limit) ReleaseMutex(@@mutex) end def terminate exit_code = [0].pack('L') return nil unless TerminateThread(@thread, exit_code) end def exit ExitThread(0) end def priority GetThreadPriority(@thread) end def priority=(value) unless SetThreadPriority(@thread, value) raise Error, get_last_error end end end end if $0 == __FILE__ t = Win32::Thread.new('a', 'b'){ |x, y| puts "Hello: #{x}, #{y}" } t.join end From phasis at gmail.com Sun May 18 02:30:13 2008 From: phasis at gmail.com (Park Heesob) Date: Sun, 18 May 2008 15:30:13 +0900 Subject: [Win32utils-devel] Pure win32-thread library? References: <482FB186.1060506@gmail.com> Message-ID: Hi, ----- Original Message ----- From: "Daniel Berger" To: "Development and ideas for win32utils projects" Sent: Sunday, May 18, 2008 1:33 PM Subject: [Win32utils-devel] Pure win32-thread library? > Hi all, > > Here's my initial stab at a pure Ruby win32-thread library that doesn't > work at all. I'm not sure how to pass the start address of the arguments > to the callback. I thought about Marshal, but you can't marshal a proc. > > BTW, the CreateThread method in windows-pr needs to be updated for this > to have any hope of success. > > Any ideas? > I think object_id and ObjectSpace._id2ref did the trick. After modifing CreateThread prototype as like this: API.new('CreateThread', 'PLKPLP', 'L') Here is a working code: # win32/thread.rb require 'windows/thread' require 'windows/synchronize' require 'windows/error' include Windows module Win32 class Thread include Windows::Thread include Windows::Synchronize include Windows::Error extend Windows::Synchronize class Error < StandardError; end @@mutex = CreateMutex(nil, false, nil) ABOVE_NORMAL = THREAD_PRIORITY_ABOVE_NORMAL BELOW_NORMAL = THREAD_PRIORITY_BELOW_NORMAL HIGHEST = THREAD_PRIORITY_HIGHEST IDLE = THREAD_PRIORITY_IDLE LOWEST = THREAD_PRIORITY_LOWEST NORMAL = THREAD_PRIORITY_NORMAL CRITICAL = THREAD_PRIORITY_TIME_CRITICAL VERSION = '0.1.0' WinThreadFunc = API::Callback.new('L', 'L'){ |pargs| args = ObjectSpace._id2ref(pargs) block = args.pop block.call(args) ReleaseMutex(@@mutex) } attr_reader :thread_id def initialize(*args, &block) raise ArgumentError, 'block must be provided' unless block_given? args.push(block) thread_id = [0].pack('L') dwArgs = args.object_id @thread = CreateThread( nil, # Handle cannot be inherited 0, # Default stack size WinThreadFunc, # Pointer to thread func dwArgs, # Arguments passed to thread func 0, # Execute immediately, i.e. not suspended thread_id # Stores the thread id ) if @thread == 0 raise Error, get_last_error end @thread_id = thread_id.unpack('L')[0] end def join(limit = INFINITE) limit = limit * 1000 unless limit == INFINITE WaitForSingleObject(@thread, limit) ReleaseMutex(@@mutex) end def terminate exit_code = [0].pack('L') return nil unless TerminateThread(@thread, exit_code) end def exit ExitThread(0) end def priority GetThreadPriority(@thread) end def priority=(value) unless SetThreadPriority(@thread, value) raise Error, get_last_error end end end end if $0 == __FILE__ t = Win32::Thread.new('a', 'b'){ |x, y| puts "Hello: #{x}, #{y}" } t.join end Regards, Park Heesob From djberg96 at gmail.com Sun May 18 09:55:21 2008 From: djberg96 at gmail.com (Daniel Berger) Date: Sun, 18 May 2008 07:55:21 -0600 Subject: [Win32utils-devel] Pure win32-thread library? In-Reply-To: References: <482FB186.1060506@gmail.com> Message-ID: <48303549.8090202@gmail.com> Park Heesob wrote: > Hi, > ----- Original Message ----- > From: "Daniel Berger" > To: "Development and ideas for win32utils projects" > Sent: Sunday, May 18, 2008 1:33 PM > Subject: [Win32utils-devel] Pure win32-thread library? > > >> Hi all, >> >> Here's my initial stab at a pure Ruby win32-thread library that doesn't >> work at all. I'm not sure how to pass the start address of the arguments >> to the callback. I thought about Marshal, but you can't marshal a proc. >> >> BTW, the CreateThread method in windows-pr needs to be updated for this >> to have any hope of success. >> >> Any ideas? >> > I think object_id and ObjectSpace._id2ref did the trick. > > After modifing CreateThread prototype as like this: > API.new('CreateThread', 'PLKPLP', 'L') > > Here is a working code: Yes, that works, thanks! Now I'm remembering this post from Wayne way back in 2004: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/123720 So, anyone up for some sort of GC work to prevent multiple native threads from crashing the interpreter? Regards, Dan From djberg96 at gmail.com Mon May 19 21:54:14 2008 From: djberg96 at gmail.com (Daniel Berger) Date: Mon, 19 May 2008 19:54:14 -0600 Subject: [Win32utils-devel] Asynchronous Pipe::Server problems Message-ID: <48322F46.40102@gmail.com> Hi all, I've been working on the win32-pipe library (again) and I've reworked the interface. Instead of Pipe.new_server or Pipe.new_client, there's now a base Pipe class, with Pipe::Server and Pipe::Client subclasses. You can find the latest code in the CVS repo. Oh, and you'll need to update your windows-pr library with the latest from CVS if you want to use this. I had to add some missing pipe related error constants to the Windows::Pipe module. These will be included in windows-pr 0.8.5. Anyway, I've got the synchronous mode working alright. Unfortunately, I can't get the asynchronous server to work. When I try to run the test_server_async.rb code (in CVS) I get this: VERSION: 0.2.0 win32-pipe/lib/win32/pipe/server.rb:69:in `connect': Waiting for a process to open the other end of the pipe. (Win32::Pipe::Error) from test_server_async.rb:70:in `mainloop' from test_server_async.rb:101 Any ideas? Here's the code, btw: # test_server_async.rb require 'win32/pipe' include Win32 puts "VERSION: " + Pipe::VERSION Thread.new { loop { sleep 0.01 } } # Allow Ctrl-C CONNECTING_STATE = 0 READING_STATE = 1 WRITING_STATE = 2 class MyPipe < Pipe::Server def connected puts "connected" @state = READING_STATE end def read_complete puts "read_complete" puts "Got [#{buffer}]" @state = WRITING_STATE end def write_complete puts "write_complete" close @state = CONNECTING_STATE end def reconnect close mainloop end def mainloop @state = CONNECTING_STATE while true if wait(1) # wait for 1 second if pending? # IO is pending case @state when CONNECTING_STATE connected when READING_STATE if transferred == 0 reconnect break end read_complete when WRITING_STATE if transferred != length reconnect break end write_complete end end case @state when CONNECTING_STATE if connect connected end when READING_STATE if read if not pending? read_complete end else reconnect end when WRITING_STATE if write("Thanks for the data!") if not pending? write_complete end else reconnect break end end end sleep(1) puts "pipe server is running" end end end pserver = MyPipe.new('foo', true) pserver.mainloop pserver.close From phasis at gmail.com Mon May 19 22:57:20 2008 From: phasis at gmail.com (Heesob Park) Date: Tue, 20 May 2008 11:57:20 +0900 Subject: [Win32utils-devel] Asynchronous Pipe::Server problems In-Reply-To: <48322F46.40102@gmail.com> References: <48322F46.40102@gmail.com> Message-ID: Hi, 2008/5/20 Daniel Berger : > Hi all, > > I've been working on the win32-pipe library (again) and I've reworked the > interface. Instead of Pipe.new_server or Pipe.new_client, there's now a base > Pipe class, with Pipe::Server and Pipe::Client subclasses. You can find the > latest code in the CVS repo. > > Oh, and you'll need to update your windows-pr library with the latest from > CVS if you want to use this. I had to add some missing pipe related error > constants to the Windows::Pipe module. These will be included in windows-pr > 0.8.5. > > Anyway, I've got the synchronous mode working alright. Unfortunately, I > can't get the asynchronous server to work. When I try to run the > test_server_async.rb code (in CVS) I get this: > > VERSION: 0.2.0 > win32-pipe/lib/win32/pipe/server.rb:69:in `connect': Waiting for a > process to open the other end of the pipe. (Win32::Pipe::Error) > from test_server_async.rb:70:in `mainloop' > from test_server_async.rb:101 > > Any ideas? > Because ERROR_PIPE_LISTENING (536) is not an actual error, just ignore it like this: case error when ERROR_IO_PENDING @pending_io = true when ERROR_PIPE_CONNECTED unless SetEvent(@handle) raise Error, get_last_error(error) end when ERROR_PIPE_LISTENING # do nothing else raise Error, get_last_error(error) end Regards, Park Heesob From djberg96 at gmail.com Tue May 20 00:39:27 2008 From: djberg96 at gmail.com (Daniel Berger) Date: Mon, 19 May 2008 22:39:27 -0600 Subject: [Win32utils-devel] Asynchronous Pipe::Server problems In-Reply-To: References: <48322F46.40102@gmail.com> Message-ID: <483255FF.3070605@gmail.com> Heesob Park wrote: > Hi, > > 2008/5/20 Daniel Berger : >> Hi all, >> >> I've been working on the win32-pipe library (again) and I've reworked the >> interface. Instead of Pipe.new_server or Pipe.new_client, there's now a base >> Pipe class, with Pipe::Server and Pipe::Client subclasses. You can find the >> latest code in the CVS repo. >> >> Oh, and you'll need to update your windows-pr library with the latest from >> CVS if you want to use this. I had to add some missing pipe related error >> constants to the Windows::Pipe module. These will be included in windows-pr >> 0.8.5. >> >> Anyway, I've got the synchronous mode working alright. Unfortunately, I >> can't get the asynchronous server to work. When I try to run the >> test_server_async.rb code (in CVS) I get this: >> >> VERSION: 0.2.0 >> win32-pipe/lib/win32/pipe/server.rb:69:in `connect': Waiting for a >> process to open the other end of the pipe. (Win32::Pipe::Error) >> from test_server_async.rb:70:in `mainloop' >> from test_server_async.rb:101 >> >> Any ideas? >> > Because ERROR_PIPE_LISTENING (536) is not an actual error, just ignore > it like this: > > case error > when ERROR_IO_PENDING > @pending_io = true > when ERROR_PIPE_CONNECTED > unless SetEvent(@handle) > raise Error, get_last_error(error) > end > when ERROR_PIPE_LISTENING > # do nothing > else > raise Error, get_last_error(error) > end Ah, that definitely improved things, thanks. I also fixed up the test_client_async.rb script, btw. However, I've botched something else up. I started up the test_async_server.rb program in one terminal, then ran the test_client_async.rb program. The first time it works on the client side: # Client side Connected... write_complete pipe client is running read_complete Got [Ruby rocks!] back from server Though I see nothing on the server side. The second time I run the client it just hangs. I fixed something in the Pipe#wait method (so update from CVS) but that didn't solve it. Any ideas? Thanks, Dan From phasis at gmail.com Tue May 20 04:15:29 2008 From: phasis at gmail.com (Heesob Park) Date: Tue, 20 May 2008 17:15:29 +0900 Subject: [Win32utils-devel] Asynchronous Pipe::Server problems In-Reply-To: <483255FF.3070605@gmail.com> References: <48322F46.40102@gmail.com> <483255FF.3070605@gmail.com> Message-ID: 2008/5/20 Daniel Berger : > Heesob Park wrote: >> >> Hi, >> >> 2008/5/20 Daniel Berger : >>> >>> Hi all, >>> > > However, I've botched something else up. I started up the > test_async_server.rb program in one terminal, then ran the > test_client_async.rb program. The first time it works on the client side: > > # Client side > Connected... > write_complete > pipe client is running > read_complete > Got [Ruby rocks!] back from server > > Though I see nothing on the server side. > > The second time I run the client it just hangs. > > I fixed something in the Pipe#wait method (so update from CVS) but that > didn't solve it. > > Any ideas? > Here is the patch for pipe.rb and server.rb: --- win32-pipe/lib/win32/pipe.rb 2008-05-20 14:10:30.000000000 +0900 +++ pipe.rb 2008-05-20 17:07:53.000000000 +0900 @@ -62,7 +61,7 @@ # def close DisconnectNamedPipe(@pipe) - CloseHandle(@pipe) + # CloseHandle(@pipe) end # Returns whether or not there is a pending IO operation on the pipe. @@ -76,6 +75,7 @@ # def read bytes = [0].pack('L') + @buffer = 0.chr * PIPE_BUFFER_SIZE if @asynchronous bool = ReadFile(@pipe, @buffer, @buffer.size, bytes, @overlapped) @@ -83,13 +83,13 @@ if bool && bytes_read > 0 @pending_io = false - @buffer[bytes_read] = 0 + @buffer = @buffer[0,bytes_read] return true end error = GetLastError() if !bool && error == ERROR_IO_PENDING - @pending = true + @pending_io = true return true end --- win32-pipe/lib/win32/pipe/server.rb 2008-05-20 14:10:30.000000000 +0900 +++ server.rb 2008-05-20 16:54:23.000000000 +0900 @@ -9,13 +9,10 @@ super(name, asynchronous) @open_mode = PIPE_ACCESS_DUPLEX - @pipe_mode = PIPE_TYPE_BYTE | PIPE_READMODE_BYTE + @pipe_mode = PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT if @asynchronous - @pipe_mode |= PIPE_NOWAIT @open_mode |= FILE_FLAG_OVERLAPPED - else - @pipe_mode |= PIPE_WAIT end Regards, Park Heesob From djberg96 at gmail.com Tue May 20 07:45:46 2008 From: djberg96 at gmail.com (Daniel Berger) Date: Tue, 20 May 2008 05:45:46 -0600 Subject: [Win32utils-devel] Asynchronous Pipe::Server problems In-Reply-To: References: <48322F46.40102@gmail.com> <483255FF.3070605@gmail.com> Message-ID: <4832B9EA.3020906@gmail.com> Heesob Park wrote: > 2008/5/20 Daniel Berger : >> Heesob Park wrote: >>> Hi, >>> >>> 2008/5/20 Daniel Berger : >>>> Hi all, >>>> > >> However, I've botched something else up. I started up the >> test_async_server.rb program in one terminal, then ran the >> test_client_async.rb program. The first time it works on the client side: >> >> # Client side >> Connected... >> write_complete >> pipe client is running >> read_complete >> Got [Ruby rocks!] back from server >> >> Though I see nothing on the server side. >> >> The second time I run the client it just hangs. >> >> I fixed something in the Pipe#wait method (so update from CVS) but that >> didn't solve it. >> >> Any ideas? >> > Here is the patch for pipe.rb and server.rb: Excellent, thanks! > --- win32-pipe/lib/win32/pipe.rb 2008-05-20 14:10:30.000000000 +0900 > +++ pipe.rb 2008-05-20 17:07:53.000000000 +0900 > @@ -62,7 +61,7 @@ > # > def close > DisconnectNamedPipe(@pipe) > - CloseHandle(@pipe) > + # CloseHandle(@pipe) > end I can see why we don't do this now, but I wonder if we should do this in a finalizer, along with a call to FlushFileBuffers(). All the example code I see closes the handle. Perhaps I'm being overly paranoid about handle leaks, though. I'm also thinking about adding a block form that would automatically ensure a call to Pipe#close. What do you think? Regards, Dan From phasis at gmail.com Tue May 20 10:25:20 2008 From: phasis at gmail.com (Park Heesob) Date: Tue, 20 May 2008 23:25:20 +0900 Subject: [Win32utils-devel] Asynchronous Pipe::Server problems References: <48322F46.40102@gmail.com> <483255FF.3070605@gmail.com> <4832B9EA.3020906@gmail.com> Message-ID: ----- Original Message ----- From: "Daniel Berger" To: "Development and ideas for win32utils projects" Sent: Tuesday, May 20, 2008 8:45 PM Subject: Re: [Win32utils-devel] Asynchronous Pipe::Server problems > Heesob Park wrote: >> 2008/5/20 Daniel Berger : >>> Heesob Park wrote: >>>> Hi, >>>> >>>> 2008/5/20 Daniel Berger : >>>>> Hi all, >>>>> >> >>> However, I've botched something else up. I started up the >>> test_async_server.rb program in one terminal, then ran the >>> test_client_async.rb program. The first time it works on the client side: >>> >>> # Client side >>> Connected... >>> write_complete >>> pipe client is running >>> read_complete >>> Got [Ruby rocks!] back from server >>> >>> Though I see nothing on the server side. >>> >>> The second time I run the client it just hangs. >>> >>> I fixed something in the Pipe#wait method (so update from CVS) but that >>> didn't solve it. >>> >>> Any ideas? >>> >> Here is the patch for pipe.rb and server.rb: > > > > Excellent, thanks! > >> --- win32-pipe/lib/win32/pipe.rb 2008-05-20 14:10:30.000000000 +0900 >> +++ pipe.rb 2008-05-20 17:07:53.000000000 +0900 >> @@ -62,7 +61,7 @@ >> # >> def close >> DisconnectNamedPipe(@pipe) >> - CloseHandle(@pipe) >> + # CloseHandle(@pipe) >> end > > I can see why we don't do this now, but I wonder if we should do this in > a finalizer, along with a call to FlushFileBuffers(). All the example > code I see closes the handle. Perhaps I'm being overly paranoid about > handle leaks, though. > > I'm also thinking about adding a block form that would automatically > ensure a call to Pipe#close. > > What do you think? > The problem is due to the reconnect method. The solution is define disconnect as DisconnectNamedPipe ,close as before and modify def reconnect close mainloop end to def reconnect disconnect mainloop end Regards, Park Heesob From Daniel.Berger at qwest.com Tue May 20 11:06:22 2008 From: Daniel.Berger at qwest.com (Berger, Daniel) Date: Tue, 20 May 2008 10:06:22 -0500 Subject: [Win32utils-devel] Asynchronous Pipe::Server problems In-Reply-To: References: <48322F46.40102@gmail.com> <483255FF.3070605@gmail.com><4832B9EA.3020906@gmail.com> Message-ID: <7524A45A1A5B264FA4809E2156496CFB023D328B@ITOMAE2KM01.AD.QINTRA.COM> Hi, > -----Original Message----- > From: win32utils-devel-bounces at rubyforge.org > [mailto:win32utils-devel-bounces at rubyforge.org] On Behalf Of > Park Heesob > Sent: Tuesday, May 20, 2008 8:25 AM > To: Development and ideas for win32utils projects > Subject: Re: [Win32utils-devel] Asynchronous Pipe::Server problems > > > > I can see why we don't do this now, but I wonder if we > should do this in > > a finalizer, along with a call to FlushFileBuffers(). All > the example > > code I see closes the handle. Perhaps I'm being overly > paranoid about > > handle leaks, though. > > > > I'm also thinking about adding a block form that would > automatically > > ensure a call to Pipe#close. > > > > What do you think? > > > The problem is due to the reconnect method. > The solution is define disconnect as DisconnectNamedPipe > ,close as before > and modify > > def reconnect > close > mainloop > end > > to > > def reconnect > disconnect > mainloop > end Just to clarify, we want this in pipe.rb then? def disconnect DisconnectNamedPipe(@pipe) end def close CloseHandle(@pipe) end Thanks, Dan This communication is the property of Qwest and may contain confidential or privileged information. Unauthorized use of this communication is strictly prohibited and may be unlawful. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy all copies of the communication and any attachments. From phasis at gmail.com Tue May 20 11:11:50 2008 From: phasis at gmail.com (Park Heesob) Date: Wed, 21 May 2008 00:11:50 +0900 Subject: [Win32utils-devel] Asynchronous Pipe::Server problems References: <48322F46.40102@gmail.com> <483255FF.3070605@gmail.com><4832B9EA.3020906@gmail.com> <7524A45A1A5B264FA4809E2156496CFB023D328B@ITOMAE2KM01.AD.QINTRA.COM> Message-ID: Hi, ----- Original Message ----- From: "Berger, Daniel" To: "Development and ideas for win32utils projects" Sent: Wednesday, May 21, 2008 12:06 AM Subject: Re: [Win32utils-devel] Asynchronous Pipe::Server problems > Hi, > >> -----Original Message----- >> From: win32utils-devel-bounces at rubyforge.org >> [mailto:win32utils-devel-bounces at rubyforge.org] On Behalf Of >> Park Heesob >> Sent: Tuesday, May 20, 2008 8:25 AM >> To: Development and ideas for win32utils projects >> Subject: Re: [Win32utils-devel] Asynchronous Pipe::Server problems > > > >> > >> > I can see why we don't do this now, but I wonder if we >> should do this in >> > a finalizer, along with a call to FlushFileBuffers(). All >> the example >> > code I see closes the handle. Perhaps I'm being overly >> paranoid about >> > handle leaks, though. >> > >> > I'm also thinking about adding a block form that would >> automatically >> > ensure a call to Pipe#close. >> > >> > What do you think? >> > >> The problem is due to the reconnect method. >> The solution is define disconnect as DisconnectNamedPipe >> ,close as before >> and modify >> >> def reconnect >> close >> mainloop >> end >> >> to >> >> def reconnect >> disconnect >> mainloop >> end > > Just to clarify, we want this in pipe.rb then? > Yes, of course. > def disconnect > DisconnectNamedPipe(@pipe) > end > > def close > CloseHandle(@pipe) > end > close on server.rb could be def close FlushFileBuffers(@pipe) DisconnectNamedPipe(@pipe) CloseHandle(@pipe) end Regards, Park Heesob From Daniel.Berger at qwest.com Tue May 20 11:41:50 2008 From: Daniel.Berger at qwest.com (Berger, Daniel) Date: Tue, 20 May 2008 10:41:50 -0500 Subject: [Win32utils-devel] Asynchronous Pipe::Server problems In-Reply-To: References: <48322F46.40102@gmail.com> <483255FF.3070605@gmail.com><4832B9EA.3020906@gmail.com><7524A45A1A5B264FA4809E2156496CFB023D328B@ITOMAE2KM01.AD.QINTRA.COM> Message-ID: <7524A45A1A5B264FA4809E2156496CFB023D328E@ITOMAE2KM01.AD.QINTRA.COM> Hi, > >> The problem is due to the reconnect method. > >> The solution is define disconnect as DisconnectNamedPipe > >> ,close as before > >> and modify > >> > >> def reconnect > >> close > >> mainloop > >> end > >> > >> to > >> > >> def reconnect > >> disconnect > >> mainloop > >> end > > > > Just to clarify, we want this in pipe.rb then? > > > Yes, of course. > > > def disconnect > > DisconnectNamedPipe(@pipe) > > end > > > > def close > > CloseHandle(@pipe) > > end > > > close on server.rb could be > > def close > FlushFileBuffers(@pipe) > DisconnectNamedPipe(@pipe) > CloseHandle(@pipe) > end Ok, I made these changes, and added the begin/ensure for a block form (which you can find in CVS). But, I've botched something up in the asynchronous server again (sorry!). I fired up the async server and connected with the async client and this happened. C:\Documents and Settings\djberge\workspace\win32-pipe>ruby -Ilib -Ilib/win32 examples\test_server_async.rb VERSION: 0.2.0 pipe server is running pipe server is running connected read_complete Got [Ruby rocks!] pipe server is running write_complete pipe server is running ./lib/win32/pipe/server.rb:68:in `connect': The handle is invalid. (Win32::Pipe::Error) from examples/test_server_async.rb:67:in `mainloop' from examples/test_server_async.rb:97 from ./lib/win32/pipe/server.rb:35:in `initialize' from examples/test_server_async.rb:96:in `new' from examples/test_server_async.rb:96 So, somehow the server is calling close unexpectedly. I don't think it's the begin/ensure code, because even after removing that I get the same behavior. Regards, Dan This communication is the property of Qwest and may contain confidential or privileged information. Unauthorized use of this communication is strictly prohibited and may be unlawful. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy all copies of the communication and any attachments. From Daniel.Berger at qwest.com Tue May 20 16:07:28 2008 From: Daniel.Berger at qwest.com (Berger, Daniel) Date: Tue, 20 May 2008 15:07:28 -0500 Subject: [Win32utils-devel] Multiple tones with win32-sound? Message-ID: <7524A45A1A5B264FA4809E2156496CFB023D3299@ITOMAE2KM01.AD.QINTRA.COM> Hi all, Anyone know if this is possible? http://rubyforge.org/tracker/index.php?func=detail&aid=19668&group_id=85 &atid=414 Thanks, Dan This communication is the property of Qwest and may contain confidential or privileged information. Unauthorized use of this communication is strictly prohibited and may be unlawful. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy all copies of the communication and any attachments. From phasis at gmail.com Tue May 20 21:13:53 2008 From: phasis at gmail.com (Heesob Park) Date: Wed, 21 May 2008 10:13:53 +0900 Subject: [Win32utils-devel] Asynchronous Pipe::Server problems In-Reply-To: <7524A45A1A5B264FA4809E2156496CFB023D328E@ITOMAE2KM01.AD.QINTRA.COM> References: <48322F46.40102@gmail.com> <483255FF.3070605@gmail.com> <4832B9EA.3020906@gmail.com> <7524A45A1A5B264FA4809E2156496CFB023D328B@ITOMAE2KM01.AD.QINTRA.COM> <7524A45A1A5B264FA4809E2156496CFB023D328E@ITOMAE2KM01.AD.QINTRA.COM> Message-ID: Hi, 2008/5/21 Berger, Daniel : > > Hi, > > > >> >> The problem is due to the reconnect method. >> >> The solution is define disconnect as DisconnectNamedPipe >> >> ,close as before >> >> and modify >> >> >> >> def reconnect >> >> close >> >> mainloop >> >> end >> >> >> >> to >> >> >> >> def reconnect >> >> disconnect >> >> mainloop >> >> end >> > >> > Just to clarify, we want this in pipe.rb then? >> > >> Yes, of course. >> >> > def disconnect >> > DisconnectNamedPipe(@pipe) >> > end >> > >> > def close >> > CloseHandle(@pipe) >> > end >> > >> close on server.rb could be >> >> def close >> FlushFileBuffers(@pipe) >> DisconnectNamedPipe(@pipe) >> CloseHandle(@pipe) >> end > > Ok, I made these changes, and added the begin/ensure for a block form > (which you can find in CVS). But, I've botched something up in the > asynchronous server again (sorry!). I fired up the async server and > connected with the async client and this happened. > > C:\Documents and Settings\djberge\workspace\win32-pipe>ruby -Ilib > -Ilib/win32 examples\test_server_async.rb > VERSION: 0.2.0 > pipe server is running > pipe server is running > connected > read_complete > Got [Ruby rocks!] > pipe server is running > write_complete > pipe server is running > ./lib/win32/pipe/server.rb:68:in `connect': The handle is invalid. > (Win32::Pipe::Error) > from examples/test_server_async.rb:67:in `mainloop' > from examples/test_server_async.rb:97 > from ./lib/win32/pipe/server.rb:35:in `initialize' > from examples/test_server_async.rb:96:in `new' > from examples/test_server_async.rb:96 > > So, somehow the server is calling close unexpectedly. I don't think it's > the begin/ensure code, because even after removing that I get the same > behavior. > It is because the test_server_async.rb calls close method instead of disconnect. Modify def write_complete puts "write_complete" close @state = CONNECTING_STATE end to def write_complete puts "write_complete" disconnect @state = CONNECTING_STATE end Regards, Park Heesob From Daniel.Berger at qwest.com Wed May 21 11:50:13 2008 From: Daniel.Berger at qwest.com (Berger, Daniel) Date: Wed, 21 May 2008 10:50:13 -0500 Subject: [Win32utils-devel] Asynchronous Pipe::Server problems In-Reply-To: References: <48322F46.40102@gmail.com><483255FF.3070605@gmail.com><4832B9EA.3020906@gmail.com><7524A45A1A5B264FA4809E2156496CFB023D328B@ITOMAE2KM01.AD.QINTRA.COM><7524A45A1A5B264FA4809E2156496CFB023D328E@ITOMAE2KM01.AD.QINTRA.COM> Message-ID: <7524A45A1A5B264FA4809E2156496CFB023D32A3@ITOMAE2KM01.AD.QINTRA.COM> Hi, > It is because the test_server_async.rb calls close method > instead of disconnect. > Modify > > def write_complete > puts "write_complete" > close > @state = CONNECTING_STATE > end > > to > > def write_complete > puts "write_complete" > disconnect > @state = CONNECTING_STATE > end Oh, silly me. Thanks, Dan This communication is the property of Qwest and may contain confidential or privileged information. Unauthorized use of this communication is strictly prohibited and may be unlawful. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy all copies of the communication and any attachments. From pnasrat at googlemail.com Mon May 26 12:36:32 2008 From: pnasrat at googlemail.com (Paul Nasrat) Date: Mon, 26 May 2008 17:36:32 +0100 Subject: [Win32utils-devel] Interest in win32-installer Message-ID: <48c2022e0805260936y3541360cy576a370d6b45bb6b@mail.gmail.com> I was wondering if people would be interested in wrapping msi.dll functionality, I've started writing a small library to enable enumeration of products installed via Windows Installer using win32api (I know I can also query via win32ole to win32_product but I don't seem to get all the properties that are in msi.h). It's a little messy, and I've not got far as I'm pretty new at ruby and win32 programming coming from mostly a python/*nix background, so I thought I'd try to get some early feedback. It's inspired by psmsi (http://www.codeplex.com/psmsi/) but I want to be able to get installer information (and eventually information from an msi) in ruby as it'd help towards getting a windows installer puppet package provider. I'm trying to think how best to test the code - based upon looking at the tests in psmsi I was wondering if there is a ruby library that would allow me to set up temporary keys in the registry so I can actually set expectations/assertions on known values for installed software - this should be possible by abusing RegOverridePredefKey. Any feedback, and advice - particularly about producing ruby idiom friendly library welcome. Paul -------------- next part -------------- A non-text attachment was scrubbed... Name: win32-installer.zip Type: application/zip Size: 2282 bytes Desc: not available URL: From Daniel.Berger at qwest.com Wed May 28 15:35:52 2008 From: Daniel.Berger at qwest.com (Berger, Daniel) Date: Wed, 28 May 2008 14:35:52 -0500 Subject: [Win32utils-devel] Interest in win32-installer In-Reply-To: <48c2022e0805260936y3541360cy576a370d6b45bb6b@mail.gmail.com> References: <48c2022e0805260936y3541360cy576a370d6b45bb6b@mail.gmail.com> Message-ID: <7524A45A1A5B264FA4809E2156496CFB023D32BF@ITOMAE2KM01.AD.QINTRA.COM> > -----Original Message----- > From: win32utils-devel-bounces at rubyforge.org > [mailto:win32utils-devel-bounces at rubyforge.org] On Behalf Of > Paul Nasrat > Sent: Monday, May 26, 2008 10:37 AM > To: win32utils-devel at rubyforge.org > Subject: [Win32utils-devel] Interest in win32-installer > > I was wondering if people would be interested in wrapping > msi.dll functionality, > > I've started writing a small library to enable enumeration of > products installed via Windows Installer using win32api (I > know I can also query via win32ole to win32_product but I > don't seem to get all the properties that are in msi.h). I'm curious which properties you don't get. I did notice that there are actually a few product related WMI classes. > It's a little messy, and I've not got far as I'm pretty new > at ruby and win32 programming coming from mostly a > python/*nix background, so I thought I'd try to get some > early feedback. It's inspired by psmsi > (http://www.codeplex.com/psmsi/) but I want to be able to get > installer information (and eventually information from an > msi) in ruby as it'd help towards getting a windows installer > puppet package provider. If you want to use the Windows API directly, you could wrap the MSI functions you need and call them. For example: # Warning: untested code require 'win32/api' include Win32 MsiGetProductInfo = API.new('MsiGetProductInfo', 'PPPP', 'I', 'msi) buf = 0.chr * 512 # Or whatever you need, depending on the property buf_val = [buf.size].pack('L') MsiGetProductInfo.call(some_product, some_property, buf, buf_val) > I'm trying to think how best to test the code - based upon > looking at the tests in psmsi I was wondering if there is a > ruby library that would allow me to set up temporary keys in > the registry so I can actually set expectations/assertions on > known values for installed software - this should be possible > by abusing RegOverridePredefKey. Ruby comes with a win32-registry library. I think you could use that. Regards, Dan This communication is the property of Qwest and may contain confidential or privileged information. Unauthorized use of this communication is strictly prohibited and may be unlawful. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy all copies of the communication and any attachments. From Daniel.Berger at qwest.com Wed May 28 16:20:29 2008 From: Daniel.Berger at qwest.com (Berger, Daniel) Date: Wed, 28 May 2008 15:20:29 -0500 Subject: [Win32utils-devel] WIN32OLE rewrite? Message-ID: <7524A45A1A5B264FA4809E2156496CFB023D32C0@ITOMAE2KM01.AD.QINTRA.COM> Hi everyone, So, who wants to rewrite the WIN32OLE library? I think I've got most everything you'll need in the windows-pr library, such as Windows::COM::Automation, Windows::Error, etc. I can add anything that's missing. Advantages include: * No compiler required * Easier to debug * A potentially better and more flexible interface * The current WIN32OLE library is still occasionally buggy and crashy The major pain point is that this is a 6200+ line source file. :( Any takers? Regards, Dan This communication is the property of Qwest and may contain confidential or privileged information. Unauthorized use of this communication is strictly prohibited and may be unlawful. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy all copies of the communication and any attachments. From noreply at rubyforge.org Fri May 30 16:54:07 2008 From: noreply at rubyforge.org (noreply at rubyforge.org) Date: Fri, 30 May 2008 16:54:07 -0400 (EDT) Subject: [Win32utils-devel] [ win32utils-Bugs-20455 ] win32-open3: crashes after 170 popen3 operations Message-ID: <20080530205407.89B4518585A7@rubyforge.org> Bugs item #20455, was opened at 2008-05-30 16:54 You can respond by visiting: http://rubyforge.org/tracker/?func=detail&atid=411&aid=20455&group_id=85 Category: None Group: Code Status: Open Resolution: None Priority: 3 Submitted By: Nobody (None) Assigned to: Nobody (None) Summary: win32-open3: crashes after 170 popen3 operations Initial Comment: OS: XP w/SP2 C:\Documents and Settings\twasson>ruby -v ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32] win32-open3 (0.2.5) After looping through an "Open3.popen3", the loop crashes with an IO error. We've tried a few things like other read verbs (get, read, readlines, etc) and have tried explicitly closing things. Distilled to it's essence, I think this snippet shows the problem: require "win32/open3" i = 1 while (i<200) Open3.popen3("dir") do |stdin, stdout, stderr| e = stdout.readlines end puts i i += 1 end C:\Documents and Settings\me>ruby goober.rb 1 ... etc ... 170 goober.rb:6:in `readlines': closed stream (IOError) from goober.rb:6 from goober.rb:5:in `popen3' from goober.rb:5 The non windows version runs fine on Linux. ---------------------------------------------------------------------- You can respond by visiting: http://rubyforge.org/tracker/?func=detail&atid=411&aid=20455&group_id=85