[Vorbis-dev] patch for non-seekable streams on Windows

Vidur Apparao vidur at slimdevices.com
Fri Oct 15 15:43:47 PDT 2004


Dimitry Andric wrote:

>On 2004-10-15 at 01:59:34 Vidur Apparao wrote:
>  
>
>>  int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR) : -1);
>>    
>>
>>Unfortunately, fseek succeeds for a socket on Windows (even though it's
>>not seekable) with the parameters specified.
>>    
>>
>
>AFAIK, Windows sockets are not normal C/C++ file handles, in the sense
>that you can call read() and write() on them.  You have to use recv()
>and send().  At least, this is the case with Microsoft Visual C++.
>
>Or are you testing this under Cygwin?
>  
>
I'm not using Cygwin. You're correct - Windows sockets can't directly be 
used as file handles, but I believe it is possible to use a call like 
_open_osfhandle [1] to convert a socket into a file handle.

In my specific setup, I'm doing the following:

    * Instantiating the sockets in my process using socket/WSASocket.
    * Invoking DuplicateHandle [2] to make the sockets inheritable. The
      result of the call is a Windows HANDLE.
    * Calling CreateProcess [3] to instantiate oggdec, setting the
      duplicated HANDLEs as stdin and stdout of the new process.

I believe Windows is invoking the equivalent of _open_osfhandle to 
create a file handle wrapper around the socket.

FWIW, I'm doing all of this because of the limitations of IPC in Perl on 
Windows. I'm trying to do bidirectional IPC between my Perl process and 
oggdec (using the IPC::Open3 package). The pipes created by Perl for IPC 
can be used for non-blocking IO on all platforms except Windows. It 
seems that only sockets can be put into non-blocking mode on Windows, 
not pipes (at least from Perl). The process I describe above is a 
wrapper utility that I had to write on Windows to make non-blocking 
bidirectional IPC possible.

[1] 
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt__open_osfhandle.asp
[2] 
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/duplicatehandle.asp
[3] 
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/createprocess.asp



More information about the Vorbis-dev mailing list