Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



What is the Replymx() : C

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 29-01-2010
Member
 
Join Date: Jan 2010
Posts: 21
What is the Replymx() : C
  

I am the student of the Commerce background. I had just started to learn the C programming language. So, I don't anything about the C language. Today my professor of C programming ask question to me on replymx() function. But I could not be able give the answer. So, I would like to know about the replymx() function of C language, How they can be used in the C program and what is the actual use of the replymx() function in C language. If anyone has the solution then reply me.

Reply With Quote
  #2  
Old 29-01-2010
Member
 
Join Date: May 2008
Posts: 2,008
Replymx() : C

The Replymx() function is one of the kernel function. The Replymx() function replies with a message that can be taken from the buffers of array of message pointed to by msgmx to the process that is identified by pid. The nparts gives the number of elements in this array that must not exceed limit that is defined in <limits.h> header file. The size of the message is the sum of the sizes of each buffer. The process pid must have sent a message that was received and not yet replied to. It must be in the REPLY BLOCKED state.
Reply With Quote
  #3  
Old 29-01-2010
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: What is the Replymx() : C

The data transfer can occurs immediately and the replying task can not be block. Replymx() function can changes the state of the sending task from REPLY BLOCKED to READY. You have to reply to every message that you have received, but you don't need to have immediately. Replymx() function returns the 0 on success and -1 on when error can occurred. errno can be set to indicate that error. Replymx() function's main task is to reply to a message from another process.
Reply With Quote
  #4  
Old 29-01-2010
Member
 
Join Date: May 2008
Posts: 2,293
Replymx() : C

The following is the syntax of the Replymx() function :
#include <sys/kernel.h>
#include <sys/sendmx.h>
int Replymx( pid_t pid,
unsigned parts,
struct _mxfer_entry *msgmx );

The following are the list of errors that can occur while using the Replymx() function :
1. EAGAIN
2. EDSTFAULT
3. EFAULT
4. EINTR
5. EINVAL
6. ENOMEM
7. ESRCH
Reply With Quote
  #5  
Old 29-01-2010
Member
 
Join Date: Nov 2005
Posts: 1,323
Program : Replymx()

#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/kernel.h>
#include <sys/sendmx.h>
#define WRDATA 1
#define STOP 2
struct msg_wrdata {
short unsigned type;
short unsigned nbytes;
} ;
struct msg_wrdata_reply {
short unsigned status;
} ;
struct msg_stop {
short unsigned type;
} ;
struct msg_stop_reply {
short unsigned status;
} ;
union {
short unsigned type;
short unsigned status;
struct msg_wrdata wrdata;
struct msg_wrdata_reply wrdata_reply;
struct msg_stop stop;
struct msg_stop_reply stop_reply;
} msg;
char buffer[1000];
void main( void )
{
pid_t child;
if( child = fork() )
client( child );
else
server();
exit( EXIT_SUCCESS );
}
void server()
{
pid_t pid;
unsigned nbytes;
struct _mxfer_entry mx;
for( ;; ) {
_setmx( &mx, &msg, sizeof msg);
pid = Receivemx( 0, 1, &mx );
nbytes = sizeof( msg.status );
switch( msg.type ) {
case WRDATA:
printf( "Server WRDATA %d ", msg.wrdata.nbytes );
_setmx( &mx, buffer, msg.wrdata.nbytes);
Readmsgmx( pid,
sizeof( msg.wrdata ),
1, &mx );
fwrite( buffer, msg.wrdata.nbytes, 1, stdout );
fflush( stdout );
msg.wrdata_reply.status = EOK;
break;
case STOP:
printf( "Server STOP\n" );
fflush( stdout );
return;
default:
printf( "Server unknown message %04X\n",
msg.type );
msg.status = ENOSYS;
break;
}
_setmx( &mx, &msg, nbytes);
Replymx( pid, 1, &mx );
}
}
void client( child )
pid_t child;
{
int r;
printf( "Client WRDATA\n" );
r = wrdata( child, "Hello world!\n", 13 );
printf( "Client WRDATA %d %d\n", r, errno );
printf( "Client STOP\n" );
r = stop( child );
printf( "Client STOP %d %d\n", r, errno );
}
int wrdata( pid, buf, nbytes )
pid_t pid;
char *buf;
unsigned int nbytes;
{
union
{
struct msg_wrdata s;
struct msg_wrdata_reply r;
} wmsg;
struct _mxfer_entry mx[2];
wmsg.s.type = WRDATA;
wmsg.s.nbytes = nbytes;
_setmx( &mx[0], &wmsg, sizeof( wmsg.s ) );
_setmx( &mx[1], buf, nbytes );
if( Sendmx( pid, 2, 1, &mx, &mx ) == -1 )
return( -1 );
if( wmsg.r.status != EOK ) {
errno = wmsg.r.status;
return( -1 );
}
return( nbytes );
}
int stop( pid )
pid_t pid;
{
union {
struct msg_stop s;
struct msg_stop_reply r;
} smsg;
struct _mxfer_entry mx[2];
smsg.s.type = STOP;
_setmx( mx, &smsg.s, sizeof(smsg.s) );
_setmx( mx + 1, &smsg.r, sizeof(smsg.r) );
if( Sendmx( pid, 1, 1, mx, mx + 1) == -1 )
return( -1 );
if( smsg.r.status != EOK ) {
errno = smsg.r.status;
return( -1 );
}
return( 0 );
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search



All times are GMT +5.5. The time now is 06:06 AM.