• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

libkdegames/kggzmod

misc_private.h

Go to the documentation of this file.
00001 /*
00002     This file is part of the kggzmod library.
00003     Copyright (c) 2005 - 2007 Josef Spillner <josef@ggzgamingzone.org>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018     Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #ifndef KGGZMOD_MISC_PRIVATE_H
00022 #define KGGZMOD_MISC_PRIVATE_H
00023 
00024 #include <sys/types.h>
00025 #include <sys/socket.h>
00026 #include <sys/uio.h>
00027 #include <sys/un.h>
00028 #include <arpa/inet.h>
00029 #include <netinet/in.h>
00030 #include <netdb.h>
00031 
00032 #ifdef Q_OS_WIN
00033 #include <kdebug.h>
00034 #endif
00035 
00036 namespace KGGZMod
00037 {
00038 
00039 // The following function is a variant of libggz's ggz_read_fd()
00040 // All the historic Unix compatibility has been removed
00041 // The return code has been C++-ified
00042 // All GGZ debug/error handling code has been removed
00043 
00044 // On windows, this function will never be called
00045 // (no ModulePrivate::msgserverfd will ever arrive)
00046 
00047 bool readfiledescriptor(int sock, int *recvfd)
00048 {
00049 #ifndef Q_OS_WIN
00050     struct msghdr msg;
00051     struct iovec iov[1];
00052     ssize_t n;
00053         char dummy;
00054 
00055     union {
00056         struct cmsghdr cm;
00057         char control[CMSG_SPACE(sizeof(int))];
00058     } control_un;
00059     struct cmsghdr *cmptr;
00060 
00061     msg.msg_control = control_un.control;
00062     msg.msg_controllen = sizeof(control_un.control);
00063 
00064     msg.msg_name = NULL;
00065     msg.msg_namelen = 0;
00066 
00067         /* We're just sending a fd, so it's a dummy byte */
00068     iov[0].iov_base = &dummy;
00069     iov[0].iov_len = 1;
00070 
00071     msg.msg_iov = iov;
00072     msg.msg_iovlen = 1;
00073 
00074     if ( (n = recvmsg(sock, &msg, 0)) < 0) {
00075         //ggz_debug(GGZ_SOCKET_DEBUG, "Error reading fd msg.");
00076         return false;
00077     }
00078 
00079         if (n == 0) {
00080         //ggz_debug(GGZ_SOCKET_DEBUG, "Warning: fd is closed.");
00081             return false;
00082     }
00083 
00084         if ( (cmptr = CMSG_FIRSTHDR(&msg)) == NULL
00085          || cmptr->cmsg_len != CMSG_LEN(sizeof(int))) {
00086         //ggz_debug(GGZ_SOCKET_DEBUG, "Bad cmsg.");
00087         return false;
00088     }
00089 
00090     if (cmptr->cmsg_level != SOL_SOCKET) {
00091         //ggz_debug(GGZ_SOCKET_DEBUG, "Bad cmsg.");
00092         return false;
00093     }
00094 
00095     if (cmptr->cmsg_type != SCM_RIGHTS) {
00096         //ggz_debug(GGZ_SOCKET_DEBUG, "Bad cmsg.");
00097         return false;
00098     }
00099 
00100     /* Everything is good */
00101     *recvfd = *((int *) CMSG_DATA(cmptr));
00102     
00103         return true;
00104 #else
00105     kError() << "This path should never be called.";
00106     return false;
00107 #endif
00108 }
00109 
00110 }
00111 
00112 #endif
00113 

libkdegames/kggzmod

Skip menu "libkdegames/kggzmod"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • kblackbox
  • kgoldrunner
  • kmahjongg
  • ksquares
  • libkdegames
  •   highscore
  •   kgame
  •   kggzgames
  •   kggzmod
  •   kggznet
  • libkmahjongg
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal