O_DSYNC option on serial port

I was writing a program communicating via COMM with read/write, and thinking of setting the comm to synchronous mode, such that write() function won’t return until all data in the buffer has been sent. So, I tried to set the O_DSYNC flag by calling fcntl() function. But apparently it doesn’t work, fcntl function call return with errorno:22 (/* Invalid argument*/).

Anyone has any idea? I guess qnx does’t support O_DSYNC flag for serial port, is that right?

Any idea how to walk around this: how to write() comm in a synchronous mode?

Attached is the code I used.

Thanks.

//*************** Code ***************************

#include
#include
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <pthread.h>
#include <fcntl.h>
#include <stdarg.h>
#include <termios.h>
#include <time.h>
#include <errno.h>

using namespace std;

int main (int argc, char **argv)
{
int serf = open("/dev/ser1", O_RDWR );
if (serf == -1)
{
cout << “Fail to open COM.” << endl;
exit(1);
}

int retval = fcntl(serf, F_SETFL, O_DSYNC );
if( retval == -1 ) {
    printf( "error setting stdout flags, with errorno=%d\n", errno);
    return EXIT_FAILURE;
}


ifstream iFile;

char* iFileName = "/etc/printers/epijs.cfg"; 
iFile.open(iFileName, ios::binary);
if(!iFile.is_open())
{
	cout << "Error opening input file named: " << iFileName << endl;
	exit (1); 
}

int wcount;
while(!iFile.eof())
{
	char buffer[132];
	iFile.read(buffer, 132);
	wcount=iFile.gcount();
	if (write(serf, buffer, wcount) != wcount)
	{
		cout << "Write error!" << endl;
		exit (1);
	};
}

iFile.close();
close(serf);

return EXIT_SUCCESS;

}

Hello Zhenwang,
Please try

int serf = open("/dev/ser1", O_RDWR | O_DSYNC );
or
int serf = open("/dev/ser1", O_RDWR | O_SYNC );

instead of fcntl.

Thanks,
Yuriy