[Mono-dev] [PATCH] Cache errno for serial port

Carlos Alberto Cortez calberto.cortez at gmail.com
Tue Feb 19 18:13:57 EST 2008


Hey Miguel,

Somehow I had this wrong idea that GetLastError would retrieve
windows-specific codes (not the ones errno gets).

Thanks,
Carlos.


El lun, 18-02-2008 a las 20:19 -0500, Miguel de Icaza escribió:
> Hello Carlos,
> 
> > The attached patch adds a 'serial_errno' variable in
> > mono/support/serial.c, to cache the last error related to serial port
> > functions.
> > 
> > At first I tried to just create a function directly retrieving errno,
> > but it was getting a different value from the original (probably some
> > code modified it after the pinvoke call?).
> > 
> > This is needed to a simple but better error reporting in the
> > System.IO.Ports.SerialPort class.
> 
> I think you can use DllImport's built-in SetLastError/GetLastError
> framework for this.
> 
> Just add this to the DllImport definitions:
> 
> 	[DllImport ("something", SetLastError=true)]
> 
> And then in the calling code, call:
> 
> 	Marshal.GetLastWin32Error ()
> 
> This will contain the errno value.



More information about the Mono-devel-list mailing list