|
NAMEX11::Protocol::Ext::MIT_SHM - images in SysV style shared memorySYNOPSISuse X11::Protocol; my $X = X11::Protocol->new; $X->init_extension('MIT-SHM') or print "MIT-SHM extension not available"; use IPC::SysV; my $shmid = shmget (IPC::SysV::IPC_PRIVATE(), 100000, # bytes IPC::SysV::IPC_CREAT() | 0666); my $shmseg = $X->new_rsrc; $X->MitShmAttach ($shmseg, $shmid, 0); my ($depth, $visual, $size) = $X->MitShmGetImage ($window, 0,0, 16,16, ~0, 'ZPixmap', $shmseg, 0); my $image_bytes; shmread ($shmid, $image_bytes, 0, 16*16*$bpp) || die "$!"; # $image_bytes is the top-left 16x16 pixels of the screen DESCRIPTIONThe MIT-SHM extension allows a client and server running on the same machine to transfer image data through System-V shared memory segments.The client creates a memory segment with "shmget()" (see "shmget" in perlfunc and "SysV IPC" in perlipc) and asks the server to attach to it and then read or write with equivalents to the core GetImage and PutImage. The aim is to avoid sending large images through the I/O connection when on the same machine. Memory is faster, and may help avoid request size limits for very big images. Byte order, padding, etc, required or generated in images is specified by the server "$X->{'image_byte_order'}", "$X->{'pixmap_formats'}", etc, the same as for the core "GetImage()" and "PutImage()". It's up to the client to adapt to the server's layout, which can be a bit of a chore. Shm from PerlA shared memory segment can be created from Perl with "shmget()", then read or write its contents with "shmread()" and "shmwrite()". Those functions attach and detach it each time with "shmat()" and "shmdt()" system calls, which is fine for grabbing the lot but will be a bit slow for lots of little accesses."IPC::SysV" (version 2 up) offers a "shmat()" to keep the block attached and "memread()" and "memwrite()" to access it (see IPC::SysV). See IPC::SharedMem for an object-oriented wrapper around this too. Incidentally, if "shmget()" is not available on the system then Perl's "shmget()" croaks. It's always possible for it to return "undef" too for not enough memory etc. With that, not being on the same machine, not having identifiable permissions, etc, there's several cases where a fallback to plain I/O will be necessary. Shm PermissionsA SysV shared memory segment has owner/group/other permission bits similar to a file. The server will only attach to segments which the requesting client UID/GID has permission to read or write.The server can usually determine a client's UID/GID on a local connection such as Unix socket (X11::Protocol::Connection::UNIXSocket, and "SO_PEERCRED" in socket(7)), and perhaps on a TCP localhost loopback. Failing that the server treats the client as "other" and will only attach to world-readable (or world read-writable) segments. You can make a shm segment world-readable to ensure the server can read it. If the data for a PutImage etc is already from a world-readable file or is public then it shouldn't matter much who else reads the segment. Remember to ask for read-only in the "MitShmAttach()" so the server doesn't want writable too. There's probably no need to risk relaxing permissions for segment writing. Chances are that if client UID/GID can't be identified then it's because the connection is not local and the server is on a different machine so shared memory can't be used anyway. It's usual for the server to run as root, hence it's own permission checks, but it's also possible for the server to be an ordinary user. In that case the shm segments it can access will be limited in the usual way for the user it's running as. REQUESTSThe following requests are available after an "init_extension()" per "EXTENSIONS" in X11::Protocol.my $bool = $X->init_extension('MIT-SHM'); In the following $shmid is the shared memory ID (an integer) as obtained from the kernel with "shmget()". $shmseg is an XID (allocated as usual by client "$X->new_rsrc()") on the server representing the server attachment to the block.
EVENTS"MitShmCompletionEvent" is sent to the client when requested in an "MitShmPutImage()". It says the server has finished reading the memory. The event has the usual fieldsname "MitShmCompletionEvent" synthetic true if from a SendEvent code integer opcode sequence_number integer and event-specific fields drawable XID, target as from request shmseg XID, source as from request offset integer, byte offset as from request major_opcode integer, MIT-SHM extension code minor_opcode integer, 3 for MitShmPutImage "major_opcode" and "minor_opcode" are the codes of the originating "MitShmPutImage()". These fields are similar to the core "GraphicsExposure" and "NoExposure" events, but here there's only one request ("MitShmPutImage()") which gives a completion event. ERRORSError type "ShmSeg" is a bad $shmseg resource XID in a request.SEE ALSOX11::Protocol, "shmget" in perlfunc, "SysV IPC" in perlipc, IPC::SysV, IPC::SharedMemX11::Protocol::Ext::Damage /usr/share/doc/x11proto-xext-dev/shm.txt.gz, /usr/share/X11/doc/hardcopy/Xext/mit-shm.PS.gz, ftp://ftp.xfree86.org/pub/mirror/X.Org/pub/R6.6/xc/doc/hardcopy/Xext/mit-shm.PS.gz HOME PAGE<http://user42.tuxfamily.org/x11-protocol-other/index.html>LICENSECopyright 2011 Kevin RydeX11-Protocol-Other is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. X11-Protocol-Other is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with X11-Protocol-Other. If not, see <http://www.gnu.org/licenses/>.
Visit the GSP FreeBSD Man Page Interface. |