Jack2 1.9.10

JackSocket.h

00001 /*
00002 Copyright (C) 2004-2008 Grame
00003 
00004 This program is free software; you can redistribute it and/or modify
00005 it under the terms of the GNU Lesser General Public License as published by
00006 the Free Software Foundation; either version 2.1 of the License, or
00007 (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU Lesser General Public License for more details.
00013 
00014 You should have received a copy of the GNU Lesser General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017 
00018 */
00019 
00020 #ifndef __JackSocket__
00021 #define __JackSocket__
00022 
00023 #include <sys/types.h>
00024 #include <sys/un.h>
00025 #include <sys/socket.h>
00026 #include <sys/ioctl.h>
00027 #include <sys/time.h>
00028 #include <arpa/inet.h>
00029 #include <errno.h>
00030 #include <unistd.h>
00031 
00032 #include "JackChannel.h"
00033 
00034 namespace Jack
00035 {
00036 
00041 class JackClientSocket : public detail::JackClientRequestInterface
00042 {
00043 
00044     private:
00045 
00046         int fSocket;
00047         int fTimeOut;
00048 
00049     public:
00050 
00051         JackClientSocket():JackClientRequestInterface(), fSocket(-1), fTimeOut(0)
00052         {}
00053         JackClientSocket(int socket);
00054 
00055         int Connect(const char* dir, const char* name, int which);
00056         int Close();
00057         int Read(void* data, int len);
00058         int Write(void* data, int len);
00059         int GetFd()
00060         {
00061             return fSocket;
00062         }
00063         void SetReadTimeOut(long sec);
00064         void SetWriteTimeOut(long sec);
00065 
00066         void SetNonBlocking(bool onoff);
00067 };
00068 
00073 #define SOCKET_MAX_NAME_SIZE 256
00074 
00075 
00076 class JackServerSocket
00077 {
00078 
00079     private:
00080 
00081         int fSocket;
00082         char fName[SOCKET_MAX_NAME_SIZE];
00083 
00084     public:
00085 
00086         JackServerSocket(): fSocket( -1)
00087         {}
00088         ~JackServerSocket()
00089         {}
00090 
00091         int Bind(const char* dir, const char* name, int which);
00092         JackClientSocket* Accept();
00093         int Close();
00094         int GetFd()
00095         {
00096             return fSocket;
00097         }
00098 };
00099 
00100 } // end of namespace
00101 
00102 #endif
00103