Sponsored Content
Top Forums Programming how to write application for 32 com port Post 302130535 by porter on Monday 6th of August 2007 03:52:09 PM
Old 08-06-2007
The technique I normally use is to have a list of structs with a file-descriptor and a bitmask

Code:
struct serial_port
{
     struct serial_port *next
     int fd;
     int flags;
     .....
};

        .....

        fd_set fdr,fdw,fde;
        int n=-1; 
        FD_ZERO(&fdr); FD_ZERO(&fdw); FD_ZERO(&fde);

        struct serial_port *p=list;

        while (p) {        
              if (p->flags & 1) { FD_SET(p->fd,&fdr); n=max(n,p->fd); }
              if (p->flags & 2) { FD_SET(p->fd,&fdw); n=max(n,p->fd); }
              if (p->flags & 4) { FD_SET(p->fd,&fde); n=max(n,p->fd); }
             p=p->next;
        }
...
        n=select(n+1,&fdr,&fdw,&fde,NULL);
...
        p=list;
        
        while (p)
        {
            if ((p->flags & 1)&&FD_ISSET(p->fd,&fdr)) .... do read ...
            if ((p->flags & 2)&&FD_ISSET(p->fd,&fdw)) .... do write ...
            if ((p->flags & 4)&&FD_ISSET(p->fd,&fde)) .... do except ...
            p=p->next;
        }

 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

which port to write my server application?

I want to write a server application that would accept HTTP requests from client. The server would be on a machine that has no connection to the INTERNET. The clients that would be posting their HTTP requests would be doing so through webbrowser .Thus it would be sort of intranet application.... (0 Replies)
Discussion started by: rraajjiibb
0 Replies

2. IP Networking

How can I check what port addresses used the application

Hello Mentors! I am a new here in the furom, i hope somebody can understand my problem. Basically we have an application here called unigraphics and being installed per station and the setup is look like this. 1. installed unigraphics UGNX3 version on every station 2. some are installed in... (1 Reply)
Discussion started by: eykyn17
1 Replies

3. UNIX for Dummies Questions & Answers

What application is using the port

Hello im using sunos im trying to lock down application that taking my port when Im doing "netstat -in | grep 8080" Is gives me the indication that the port is taken but no indication who is taken the port. How can I find out who is taking my port? Thanks allot (7 Replies)
Discussion started by: umen
7 Replies

4. Linux

MQ application port 1414

Hi All, I have two MQ (port) 1414 established (going out) $ netstat -an | grep 1414 tcp 0 0 0.0.0.0:1414 0.0.0.0:* LISTEN tcp 0 0 20.76.1.1:32855 142.8.1.3:1414 ESTABLISHED tcp 0 0... (2 Replies)
Discussion started by: itik
2 Replies

5. Shell Programming and Scripting

command to know the application running of the port

Hi, is there any command to findout that which application is using the particular port. or whether any port is occupied with the specfic process id ? (4 Replies)
Discussion started by: mail2sant
4 Replies

6. Programming

Write own decryption application

Hi , I need some help as I dont know where to start. I need to create a unix decryption application. The information I have been given is this so far: the specification of the encryption process is: NET 2 Cryptography classes. RijndaelManaged encryption algorithm ... (13 Replies)
Discussion started by: caciing_help
13 Replies

7. Programming

unable to send read and write serial port

hey frns pls help me out !! i hav a code of c that i have to include in my project. i am using a device (geomeda) that has unix based OS. it also support SIM card for connecting to server . I need to send SMS to user from this device.. below code is not working .. i am unable to send sms and the... (7 Replies)
Discussion started by: yashwantkumar
7 Replies

8. HP-UX

how to check remote server port listening from application.

Hi, I have an application running on HP-UX, from this application I need to findout if the port number. lets say 7890,7891, 7892 are listening on the remote server running on HP-UX. Is there any way of doing it using "system()" function or any other? I noticed that nmap, netcat are not... (0 Replies)
Discussion started by: einsteinBrain
0 Replies

9. UNIX for Advanced & Expert Users

How to write if condition in shell script for application server?

Hi all, I have a code to create folder in application server through shell script and i want to create if conditional based folder folder=$HOME/test/sample/whatever if ; then echo "$folder already exists, not created." else mkdir -p "$folder" > /dev/null 2>&1 ... (7 Replies)
Discussion started by: Boost
7 Replies

10. Shell Programming and Scripting

Help Generate new port base on the last port but not in used by other application

Hi Expert, Anybody can figure it out on how to generate new port base on my last port let say my last port var1=124 and increment for new port 125,126 but this new two ports need to look at first if this port is not in used by any service, if the port is in used add 1 to new port and if in used... (6 Replies)
Discussion started by: lxdorney
6 Replies
SELECT(2)						      BSD System Calls Manual							 SELECT(2)

NAME
FD_CLR, FD_COPY, FD_ISSET, FD_SET, FD_ZERO, select -- synchronous I/O multiplexing SYNOPSIS
#include <sys/select.h> void FD_CLR(fd, fd_set *fdset); void FD_COPY(fd_set *fdset_orig, fd_set *fdset_copy); int FD_ISSET(fd, fd_set *fdset); void FD_SET(fd, fd_set *fdset); void FD_ZERO(fd_set *fdset); int select(int nfds, fd_set *restrict readfds, fd_set *restrict writefds, fd_set *restrict errorfds, struct timeval *restrict timeout); DESCRIPTION
select() examines the I/O descriptor sets whose addresses are passed in readfds, writefds, and errorfds to see if some of their descriptors are ready for reading, are ready for writing, or have an exceptional condition pending, respectively. The first nfds descriptors are checked in each set; i.e., the descriptors from 0 through nfds-1 in the descriptor sets are examined. (Example: If you have set two file descriptors "4" and "17", nfds should not be "2", but rather "17 + 1" or "18".) On return, select() replaces the given descriptor sets with subsets consisting of those descriptors that are ready for the requested operation. select() returns the total number of ready descriptors in all the sets. The descriptor sets are stored as bit fields in arrays of integers. The following macros are provided for manipulating such descriptor sets: FD_ZERO(&fdset) initializes a descriptor set fdset to the null set. FD_SET(fd, &fdset) includes a particular descriptor fd in fdset. FD_CLR(fd, &fdset) removes fd from fdset. FD_ISSET(fd, &fdset) is non-zero if fd is a member of fdset, zero otherwise. FD_COPY(&fdset_orig, &fdset_copy) replaces an already allocated &fdset_copy file descriptor set with a copy of &fdset_orig. The behavior of these macros is unde- fined if a descriptor value is less than zero or greater than or equal to FD_SETSIZE, which is normally at least equal to the maximum number of descriptors supported by the system. If timeout is a non-nil pointer, it specifies a maximum interval to wait for the selection to complete. If timeout is a nil pointer, the select blocks indefinitely. To effect a poll, the timeout argument should be non-nil, pointing to a zero-valued timeval structure. Timeout is not changed by select(), and may be reused on subsequent calls, however it is good style to re-initialize it before each invocation of select(). Any of readfds, writefds, and errorfds may be given as nil pointers if no descriptors are of interest. RETURN VALUES
select() returns the number of ready descriptors that are contained in the descriptor sets, or -1 if an error occurred. If the time limit expires, select() returns 0. If select() returns with an error, including one due to an interrupted call, the descriptor sets will be unmod- ified and the global variable errno will be set to indicate the error. ERRORS
An error return from select() indicates: [EAGAIN] The kernel was (perhaps temporarily) unable to allocate the requested number of file descriptors. [EBADF] One of the descriptor sets specified an invalid descriptor. [EINTR] A signal was delivered before the time limit expired and before any of the selected events occurred. [EINVAL] The specified time limit is invalid. One of its components is negative or too large. [EINVAL] ndfs is greater than FD_SETSIZE and _DARWIN_UNLIMITED_SELECT is not defined. LEGACY SYNOPSIS
#include <sys/select.h> - or - #include <sys/types.h> #include <sys/time.h> #include <unistd.h> FD_SET(fd, &fdset); FD_CLR(fd, &fdset); FD_ISSET(fd, &fdset); FD_COPY(&fdset_orig, &fdset_copy); FD_ZERO(&fdset); COMPATIBILITY
select() now returns with errno set to EINVAL when nfds is greater than FD_SETSIZE. Use a smaller value for nfds or compile with -D_DAR- WIN_UNLIMITED_SELECT. SEE ALSO
accept(2), connect(2), connectx(2), getdtablesize(2), gettimeofday(2), read(2), recv(2), send(2), write(2), compat(5) BUGS
Although the provision of getdtablesize(2) was intended to allow user programs to be written independent of the kernel limit on the number of open files, the dimension of a sufficiently large bit field for select remains a problem. The default size FD_SETSIZE (currently 1024) is somewhat smaller than the current kernel limit to the number of open files. However, in order to accommodate programs which might poten- tially use a larger number of open files with select, it is possible to increase this size within a program by providing a larger definition of FD_SETSIZE before the inclusion of <sys/types.h>. select() should probably have been designed to return the time remaining from the original timeout, if any, by modifying the time value in place. However, it is unlikely this semantic will ever be implemented, as the change would cause source code compatibility problems. In general it is unwise to assume that the timeout value will be unmodified by the select() call, and the caller should reinitialize it on each invocation. HISTORY
The select() function call appeared in 4.2BSD. 4.2 Berkeley Distribution March 18, 2015 4.2 Berkeley Distribution
All times are GMT -4. The time now is 02:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy