00001 /* 00002 Copyright 2003 by Marc J. Rochkind. All rights reserved. 00003 May be copied only for purposes and under conditions described 00004 on the Web page www.basepath.com/aup/copyright.htm. 00005 00006 The Example Files are provided "as is," without any warranty; 00007 without even the implied warranty of merchantability or fitness 00008 for a particular purpose. The author and his publisher are not 00009 responsible for any damages, direct or incidental, resulting 00010 from the use or non-use of these Example Files. 00011 00012 The Example Files may contain defects, and some contain deliberate 00013 coding mistakes that were included for educational reasons. 00014 You are responsible for determining if and how the Example Files 00015 are to be used. 00016 00017 */ 00018 #include "ux.hpp" 00019 00020 using namespace Ux; 00021 00022 /** 00023 Calls ftok. 00024 */ 00025 /* static */ key_t SysVIPC::ftok(const char *path, int id) 00026 { 00027 key_t k; 00028 00029 if ((k = ::ftok(path, id)) == -1) 00030 throw Error(errno); 00031 return k; 00032 } 00033 00034 /** 00035 Calls msgget. 00036 */ 00037 void SysVMsg::get(key_t key, int flags) 00038 { 00039 if ((id = ::msgget(key, flags)) == -1) 00040 throw Error(errno); 00041 } 00042 00043 /** 00044 Calls msgctl. 00045 */ 00046 void SysVMsg::ctl(int cmd, struct msqid_ds *data) 00047 { 00048 if (::msgctl(id, cmd, data) == -1) 00049 throw Error(errno); 00050 } 00051 00052 /** 00053 Calls msgsnd. 00054 */ 00055 void SysVMsg::snd(const void *msgp, size_t msgsize, int flags) 00056 { 00057 if (::msgsnd(id, msgp, msgsize, flags) == -1) 00058 throw Error(errno); 00059 } 00060 00061 /** 00062 Calls msgrcv. 00063 */ 00064 ssize_t SysVMsg::rcv(void *msgp, size_t mtextsize, long msgtype, int flags) 00065 { 00066 ssize_t n; 00067 00068 if ((n = ::msgrcv(id, msgp, mtextsize, msgtype, flags)) == -1) 00069 throw Error(errno); 00070 return n; 00071 } 00072 00073 /** 00074 Calls shmget. 00075 */ 00076 void SysVShm::get(key_t key, size_t size, int flags) 00077 { 00078 if ((id = ::shmget(key, size, flags)) == -1) 00079 throw Error(errno); 00080 } 00081 00082 /** 00083 Calls shmctl. 00084 */ 00085 void SysVShm::ctl(int cmd, struct shmid_ds *data) 00086 { 00087 if (::shmctl(id, cmd, data) == -1) 00088 throw Error(errno); 00089 } 00090 00091 /** 00092 Calls shmat. 00093 */ 00094 void *SysVShm::at(const void *shmaddr, int flags) 00095 { 00096 void *p; 00097 00098 if ((p = ::shmat(id, shmaddr, flags)) == (void *)-1) 00099 throw Error(errno); 00100 return p; 00101 } 00102 00103 /** 00104 Calls shmdt. Could be static, as it doesn't use the id. 00105 */ 00106 void SysVShm::dt(const void *shmaddr) 00107 { 00108 if (::shmdt(shmaddr) == -1) 00109 throw Error(errno); 00110 } 00111 00112 /** 00113 Calls semget. 00114 */ 00115 void SysVSem::get(key_t key, int nsems, int flags) 00116 { 00117 if ((id = ::semget(key, nsems, flags)) == -1) 00118 throw Error(errno); 00119 } 00120 00121 /** 00122 Calls semctl. 00123 */ 00124 int SysVSem::ctl(int semnum, int cmd, union semun arg) 00125 { 00126 int r; 00127 00128 if ((r = ::semctl(id, semnum, cmd, arg)) == -1) 00129 throw Error(errno); 00130 return r; 00131 } 00132 00133 /** 00134 Calls semop. 00135 */ 00136 void SysVSem::op(struct sembuf *sops, size_t nsops) 00137 { 00138 if (::semop(id, sops, nsops) == -1) 00139 throw Error(errno); 00140 }