Bug 3248 - write_serial function in MonoPosixHelper library never return timeout exception (solved myself!)
Summary: write_serial function in MonoPosixHelper library never return timeout excepti...
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: unspecified
Hardware: All Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2012-02-07 09:27 UTC by itow
Modified: 2012-03-20 09:26 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description itow 2012-02-07 09:27:22 UTC
First of all: sorry because of my worst english!
I'm using mono (2.6.3 but problem persist even with last version!) for communicate with a barcode scanner via SerialPort implemented via bluetooth stack...
Using System.IO.Port.SerialPort class I can open, read, write and close connection; but if barcode scanner "go away" (bluetooth connection down) and my program is sending data, it freeze waiting forever for all data is sent to the peripheral... (no timeout expetion even if set WriteTimout to 5000 msec!).

Doing reverse engineering I came in Serial.c (source file located in "mono-x.y.z/support/Serial.c") and I modified write_serial function:
		do {
			t = write (fd, buffer + offset, n);
		} while (t == -1 && errno == EINTR);

		if (t < 0)
			return -1;

		do {
			t = write (fd, buffer + offset, n);
		} while (t == -1 && errno == EINTR);

		if (t == -1)
			return -1;

That solve the problem that variable t is defined as unsigned so the condition "t < 0" is never verified even if write function return in error.

Hope this help someone.
Comment 1 Konrad Kruczyński 2012-03-20 06:50:36 UTC
I think it can be closed because of https://github.com/mono/mono/pull/244
Comment 2 Gonzalo Paniagua Javier 2012-03-20 09:26:23 UTC
Closing. Miguel checked in the fix from Konrad.