LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-15-2005, 09:10 PM   #1
novice_din
LQ Newbie
 
Registered: Feb 2005
Posts: 12

Rep: Reputation: 0
Question opening port (blocking mode)


Hi Gurus,


I am writing a serial communications program and wanted to support blocking and non blocking mode. non blocking mode works fine but the blocking mode sometimes just hang-up when opening a port. Anybody encounter this? Thanks in advance...

here's the code snippet

non blocking version

main()
{ int d
d=open("/dev/tty1", O_RDWR|O_NONBLOCK); /** works fine **/
write(d, "TEST", 4);
close(d);
}

blocking mode

main()
{ int d
d=open("/dev/tty1", O_RDWR); /** sometimes just hang-up here **/
write(d, "TEST", 4);
close(d);
}





thanks again!!!
 
Old 02-16-2005, 08:39 PM   #2
PasiZ
LQ Newbie
 
Registered: Feb 2005
Posts: 1

Rep: Reputation: 0
Code:
/* blocking mode */

main()
{ int d
d=open("/dev/tty1", O_RDWR); /** sometimes just hang-up here **/
write(d, "TEST", 4);
close(d);
}

I suggest follow:

Code:
int d;
d = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
write(d, "TEST", 4);
close(d);
Becouse with O_NDELAY, routine would'n care DCD signal state... I think that's the problem...
O_NOCTTY tells that this isn't controlling terminal, so abort signals etc wouldn't mess up the process.

You can change mode on the fly to blocking with:

Code:
fcntl(d, F_SETFL, 0);
and non blocking:

Code:
fcntl(d, F_SETFL, FNDELAY);
I'm sorry of this messy post, hope you understand me no sleep whole night
 
Old 02-17-2005, 08:36 PM   #3
novice_din
LQ Newbie
 
Registered: Feb 2005
Posts: 12

Original Poster
Rep: Reputation: 0
Pasiz,

Thanks for your reply. You solved my problem... I thought O_NDELAY and O_NONBLOCK are synonym.
Thanks again!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Port Blocking adtomar Linux - Networking 6 12-14-2004 03:35 AM
Opening a website in text mode HadesThunder Linux - Newbie 5 03-26-2004 06:20 PM
port blocking BwiNfon Linux - Security 4 09-25-2003 10:51 AM
port blocking EyaL Linux - Security 3 10-19-2002 08:58 PM
iptables - advanced port blocking/stealth mode siymann Linux - Security 1 10-26-2001 05:21 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration