The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #7 (permalink)  
Old 11-14-2007
arunchaudhary19 arunchaudhary19 is offline
Registered User
 

Join Date: Sep 2007
Posts: 62
ok...........here is the section of my code..........

from main I am Calling function.......
setup_ipc("msqueue",1234,INPUT_IPC,LARGE_QUEUE);
and its defination is in another *.cpp file

and here is its defination
int setup_ipc (const char * ipc_name, long base_add, int io_type, int ipc_qtype)
{
char sbuffer[FILENAMELEN + 1];
key_t msg_key;
int msg_flag;
if ((io_type != INPUT_IPC && io_type != OUTPUT_IPC) ||
(ipc_qtype != SMALL_QUEUE && ipc_qtype != LARGE_QUEUE &&
ipc_qtype != PRI_QUEUE && ipc_qtype != MAIL_BOX &&
ipc_qtype != SOCKET_QUEUE)) {return(-1);}

if (!(*ipc_name)) {return(-1);}

/** look for the end of ipc_tbl **/
lipc_tbl = &ipc_lhead;
for (ipc_tbl = ipc_lhead.ipc_nextent; ipc_tbl;lipc_tbl = ipc_tbl, ipc_tbl = ipc_tbl->ipc_nextent);

ipc_tbl = (struct ipc_ent *) malloc(sizeof(struct ipc_ent));
if ( !ipc_tbl ) {return(-1);}

/** init table entry variables **/
strncpy(sbuffer, ipc_name, FILENAMELEN);
sbuffer[FILENAMELEN - 1] = '\0';
sprintf(ipc_tbl->fname, "%s", sbuffer);
ipc_tbl->ipc_tag = ++ipc_ecnt;
ipc_tbl->io_type = io_type;
ipc_tbl->vlmsg_id = -1;
ipc_tbl->sockfd = -1;
ipc_tbl->vlkey_id = base_add;
ipc_tbl->qtype = ipc_qtype;
ipc_tbl->ipc_nextent = NULL;

/** open message queue **/
if (ipc_qtype != SOCKET_QUEUE)
{
msg_key = ipc_tbl->vlkey_id;
if (io_type == INPUT_IPC)
msg_flag = IPC_CREAT | IPC_EXCL | 0666;
else
msg_flag = 0666;

errno = 0;
while ((ipc_tbl->vlmsg_id = msgget(msg_key, msg_flag)) < 0 && errno == EEXIST)
{
errno = 0;
msg_key++;
}

if (errno != 0)
{ // error other than EEXIST occurs
free(ipc_tbl);
return(-1);
}

ipc_tbl->vlkey_id = msg_key;
}
Reply With Quote