Messages in this thread | | | From | "Albert D. Cahalan" <> | Subject | Re: User vs. Kernel (was: To be smug, or not to be smug, that is , the question) | Date | Sun, 24 Jan 1999 07:50:01 -0500 (EST) |
| |
Oleg Krivosheev writes: > [Alan Cox wrote]
>>>> The original poster said "generalized message passing" and you >>>> responded with something that can pass 4 or 8 bytes between >>>> processes with the same UID. That isn't very general. >>> >>> You mean "can pass an address". Now add a shared memory block and >>> the rest is trivial > >> POSIX does have message queues that can send effectively arbitrary >> amount of data. It's not been implemented, though it may be doable >> entirely from userland. > > sure it was implemented - i've used it in (apparently small) project.
In userland, you can't support message queues in select() like AIX can.
-------------------------
int select ( int Nfdsmsgs, struct sellist *ReadList, struct sellist *WriteList, struct sellist *ExceptList, struct timeval *TimeOut );
Nfdsmsgs Specifies the number of file descriptors and the number of message queues to check. The low-order 16 bits give the length of a bit mask that specifies which file descriptors to check; the high-order 16 bits give the size of an array that contains message queue identifiers. If either half of the Nfdsmsgs parameter is equal to a value of 0, the corresponding bit mask or array is assumed not to be present.
ReadList, WriteList, ExceptList Each of these parameters points to a sellist structure, which can specify both file descriptors and message queues. Your program must define the sellist structure in the following form:
struct sellist{ int fdsmask[F]; /* file descriptor bit mask */ int msgids[M]; /* message queue identifiers */ };
The fdsmask array is treated as a bit string in which each bit corresponds to a file descriptor. File descriptor n is represented by the bit (1 << (n mod bits)) in the array element fdsmask[n / BITS(int)]. (The BITS macro is defined in the values.h file.) Each bit that is set to 1 indicates that the status of the corresponding file descriptor is to be checked.
Note: The low-order 16 bits of the Nfdsmsgs parameter specify the number of bits (not elements) in the fdsmask array that make up the file descriptor mask. If only part of the last int is included in the mask, the appropriate number of low-order bits are used, and the remaining high-order bits are ignored. If you set the low-order 16 bits of the Nfdsmsgs parameter to 0, you must not define an fdsmask array in the sellist structure.
Each int of the msgids array specifies a message queue identifier whose status is to be checked. Elements with a value of -1 are ignored. The high-order 16 bits of the Nfdsmsgs parameter specify the number of elements in the msgids array. If you set the high-order 16 bits of the Nfdsmsgs parameter to 0, you must not define a msgids array in the sellist structure.
Note: The arrays specified by the ReadList, WriteList, and ExceptList parameters are the same size because each of these parameters points to the same sellist structure type. However, you need not specify the same number of file descriptors or message queues in each. Set the file descriptor bits that are not of interest to 0, and set the extra elements of the msgids array to -1.
You can use the SELLIST macro defined in the sys/select.h file to define the sellist structure. The format of this macro is:
SELLIST(f, m) declarator . . . ;
where f specifies the size of the fdsmask array, m specifies the size of the msgids array, and each declarator is the name of a variable to be declared as having this type.
Return Values
Upon successful completion, the select subroutine returns a value that indicates the total number of file descriptors and message queues that satisfy the selection criteria. The fdsmask bit masks are modified so that bits set to 1 indicate file descriptors that meet the criteria. The msgids arrays are altered so that message queue identifiers that do not meet the criteria are replaced with a value of -1.
The return value is similar to the Nfdsmsgs parameter in that the low-order 16 bits give the number of file descriptors, and the high-order 16 bits give the number of message queue identifiers. These values indicate the sum total that meet each of the read, write, and exception criteria. Therefore, the same file descriptor or message queue can be counted up to three times. You can use the NFDS and NMSGS macros found in the sys/select.h file to separate out these two values from the return value. For example, if rc contains the value returned from the select subroutine, NFDS(rc) is the number of files selected, and NMSGS(rc) is the number of message queues selected.
If the time limit specified by the TimeOut parameter expires, the select subroutine returns a value of 0.
If a connection-based socket is specified in the Readlist parameter and the connection disconnects, the select subroutine returns successfully, but the recv subroutine on the socket will return a value of 0 to indicate the socket connection has been closed.
If the select subroutine is unsuccessful, it returns a value of -1 and sets the global variable errno to indicate the error. In this case, the contents of the structures pointed to by the ReadList, WriteList, and ExceptList parameters are unpredictable.
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |