void * pi_a() {
	int coid;
	int rcvid;

	char send[50] = "PI_A";
	char receive[50];

	int from;
	int to;
	double result;

	int status = 0;

	coid = ConnectAttach(0, pid, chid, 0, NULL);
	checkresult(coid, "\nConnect Attach failed in PI_A: ");

	printf("PI_A: connected to channel (Connect ID = %i) \n", coid);

	while (status == 0){
		status = MsgSend(coid, &send, sizeof(send), &from, sizeof(double));
		status = MsgSend(coid, &send, sizeof(send), &to, sizeof(double));

		k = 0, pi_old = 0, pi = 0;

		for(k = from; k <= to;k++){
			pi = pi_old + 4 * (pow(-1, k+1)) / (2*k -1);
			pi_old = pi;
		}

		status = MsgSend(coid, &pi, sizeof(double), &receive, sizeof(receive));
	}

	return(NULL);
}//end pi
/** timeout callback, see doc on g_timeout_add() 
 *  -- called until this returns FALSE when it will be removed */
gboolean tmo_callback(gpointer data) {
    //printf("%s\n", (char*)data);
    twmsg(__func__, (char*)data);

    /* send msg to loop 1 and 2 
     * - ideally check to see who caused the tmo 
     */
    MsgSend(&loop_1, "TMO1");
    MsgSend(&loop_2, "TMO2");

    return TRUE;
}
// -------------------------------ReadMsg-----------------------------------------
void readMsg(int system, int sensor)
{
	hiInputSet simUpperByte;
	hiInputSet pportUpperByte;
	// msgType => write
	smsg.msgType = READ;
	// command the simulator to return system status
	MsgSend(coidsim,&smsg,sizeof(smsg),&rmsg,sizeof(rmsg));
	// extract system status data
	simUpperByte.hiInputSetByte = rmsg.rwdataMsg.upper_data;
	
	// Send the status request to the PPORT, only need the lower byte data.
	MsgSend(coidpport,&smsg,sizeof(smsg),&rmsg,sizeof(rmsg));
	readLowerByte.lowInputSetByte = rmsg.rwdataMsg.lower_data;
	pportUpperByte.hiInputSetByte = rmsg.rwdataMsg.upper_data;
	// combine the sim and pport pulses
	readUpperByte.loader_nEMPTY     = pportUpperByte.loader_nEMPTY;
	readUpperByte.unloader_nEMPTY   = pportUpperByte.unloader_nEMPTY;
	readUpperByte.baseLimit_nBL     = simUpperByte.baseLimit_nBL;
	readUpperByte.shoulderLimit_nBL = simUpperByte.shoulderLimit_nBL;
	readUpperByte.elbowLimit_nBL    = simUpperByte.elbowLimit_nBL;
	readUpperByte.pitchLimit_nBL    = simUpperByte.pitchLimit_nBL;
	readUpperByte.rollLimit_nBL     = simUpperByte.rollLimit_nBL;
	readUpperByte.hiIpReserved7     = simUpperByte.hiIpReserved7;
	 // Check whether system status has changed and whether user wants to display it
	if ((system == 1) && (memData.upperByte != readUpperByte.hiInputSetByte))
	{
		// display interpretation
		if (readUpperByte.baseLimit_nBL == 1)
			printf("base working outside limit!\n");
		if (readUpperByte.shoulderLimit_nBL == 0)
			printf("shoudler outside limit!\n");
		if (readUpperByte.elbowLimit_nBL == 0)
			printf("elbow outside its limit!\n");
		if (readUpperByte.pitchLimit_nBL == 0)
			printf("pitch outside its limit!\n");
		if (readUpperByte.rollLimit_nBL == 0)
			printf("roll outside its limit!\n");
		if (readUpperByte.unloader_nEMPTY == 0)
			printf("Unloader detect a block.\n");
		if (readUpperByte.loader_nEMPTY == 1)
			printf("loader outside its limit!\n");
//		printf("\n");
		flushall();
	}
	// Check whether user wants to see the sensor states and whether sensor states has changed
	if ((sensor == 1) && ((system == 1))) //&& (memData.lowerByte != readLowerByte.lowInputSetByte)))
	{
		printf(" A2: %i\n B1: %i\n B4: %i\n C3: %i\n C2: %i\n C1: %i\n\n",readLowerByte.sensor_nA2,readLowerByte.sensor_nB1,readLowerByte.sensor_nB4,readLowerByte.sensor_nC3,readLowerByte.sensor_nC2,readLowerByte.sensor_nC1);
		flushall();
	}
}
Beispiel #4
0
int main(int argc, char *argv[]) {
	int status;
	struct MESSAGE msg; // буфер посылаемого сообщени¤
	unsigned char rmsg; // Ѕуфер ответного сообщени¤
	char command[10]; // Ѕуфер команд оператора
	int coid;

	coid=name_open("apu/roby",0);
	printf("apu/roby has coid=%d\n\n", coid);

	do {
		printf("\n>");
		scanf("%s", command);

		switch (command[0]) {
		case 'A':       //Write port A
			msg.type = 0;
			sscanf(command + 1, "%X", &msg.buf);
			status = MsgSend(coid, &msg, sizeof(msg), &rmsg, sizeof(rmsg));
			printf("Write port A: message <0x%X>\n", msg.buf);
			break;

		case 'C':       //Write port C
			msg.type = 1;
			sscanf(command + 1, "%X", &msg.buf);
			status = MsgSend(coid, &msg, sizeof(msg), &rmsg, sizeof(rmsg));
			printf("Write port C: message <0x%X>\n", msg.buf);
			break;
		case 'c':       //Read port  C
			msg.type = 2;
			status = MsgSend(coid, &msg, sizeof(msg), &rmsg, sizeof(rmsg));
			printf("Port C: 0x%X\n", rmsg);
			break;
		case 'b':       //Read port  B
			msg.type = 3;
			status = MsgSend(coid, &msg, sizeof(msg), &rmsg, sizeof(rmsg));
			printf("Port B: 0x%X\n", rmsg);
			break;

		case 'E':
			return 0;       //Return from main
		default:
			printf("Unknown command\n");
			break;
		}
	} while (1);

	return EXIT_SUCCESS;
}
Beispiel #5
0
int main(int argc, char* argv[])
{
	int coid;         //Connection ID to server
	int status;       //status return value used for ConnectAttach and MsgSend
	int server_pid;   //server's process ID
	int server_chid;  //server's channel ID
	kom_t msg;
	kom_t reply;

	if(3 != argc) {
		printf("This program must be started with commandline arguments, for example:\n\n");
		printf("   cli 482834 1   \n\n");
		printf(" 1st arg(482834): server's pid\n");
		printf(" 2nd arg(1): server's chid\n");
		exit(EXIT_FAILURE);
	}

	server_pid = atoi(argv[1]);
	server_chid = atoi(argv[2]);

	printf("attempting to establish connection with server pid: %d, chid %d\n", server_pid, server_chid);

	coid = ConnectAttach(ND_LOCAL_NODE, server_pid, server_chid, _NTO_SIDE_CHANNEL, 0);
	if(-1 == coid) {
		perror("ConnectAttach");
		exit(EXIT_FAILURE);
	}

	int i = 0;
	while(i++ < 10) {
		msg.type = 1;
		msg.from = getpid();
		sprintf(msg.text, "Proces %d, krok petli %d\n", getpid(), i);

		status = MsgSend(coid, &msg, sizeof(msg), &reply, sizeof(reply) );
		if(-1 == status) {
			perror("MsgSend");
			exit(EXIT_FAILURE);
		}
		sleep(1);
	}

	msg.type = 0;
	status = MsgSend(coid, &msg, sizeof(msg), &reply, sizeof(reply) );


	exit(EXIT_SUCCESS);
}
Beispiel #6
0
/**
 * This function represents client thread. Thanks to this function we can send
 * data to serwer.
 *
 * @param nth - not used but demanded by pthread_create() convencion
 * @return no value returned
 */
void* send(void* nth) {
	my_data_t msg;
	
	std::string buffer;
	
	/* We trying to open connection with channel, store coid value */
	while((coid = name_open(stranger_channel, 0)) == -1) {
		std::cout<<"Waiting for the server to be created. \n";
		sleep(2);
	}
	
	msg.header.type = 0x00;
	msg.header.subtype = 0x00;
	
	/* main loop - sending data */
	while(true) {
		//std::cout<<"["<<my_channel<<"]: ";
		printf("[%s]: ", my_channel);
		fflush(stdout);
		std::getline(std::cin, buffer);
		std::strncpy(msg.data, buffer.c_str(), 32);
		msg.data[31]='\0';
		
		if(MsgSend(coid, &msg, sizeof(msg), NULL, 0) == -1) {
			std::cerr<<"Error while sending message\n";
			exit(-1);
		}
	}
}
Beispiel #7
0
void
RepDown(Link l)
{
    Rep r = l->rep;
    int n = (r->links[0] == l)?0:1;

    Log(LG_REP, ("[%s] Rep: DOWN event from %s (%d)",
	r->name, l->name, n));

    r->p_up &= ~(1 << n);

    if (r->links[1-n])
	PhysClose(r->links[1-n]);

    if (r->csock > 0 && r->node_id) {
	char path[NG_PATHSIZ];
	
	snprintf(path, sizeof(path), "[%x]:", r->node_id);
	NgFuncShutdownNode(r->csock, r->name, path);
	r->node_id = 0;
	close(r->csock);
	r->csock = -1;
    }
    
    l->rep->links[n] = NULL;
    l->rep = NULL;
    if (!l->stay) {
        REF(l);
        MsgSend(&l->msgs, MSG_SHUTDOWN, l);
    }

    if (r->links[1-n] == NULL)
	RepShutdown(r);
}
int main(int argc, char *argv[]) {
	if(argc < 2) {
		printf("use with channel_id\n");
		return 1;
	}
	int chid = atoi(argv[1]);
	sleep(1);
	coid = ConnectAttach(getppid(), chid, 0);
	if(coid < 0) {
		printf("kernel not responsible\n");
		return 2;
	}

	pthread_t tid;
	pthread_create(&tid, NULL, ping, NULL);

	printf("console\n");
	MESSAGE *pmsg = (MESSAGE *) malloc(MAXMSGSIZE);
	pmsg->type = MSGCMD;
	for(;;) {
		printf("%% "); fflush(stdout);
		if(!fgets(pmsg->body, MAXMSGSIZE - sizeof(MESSAGE) - 1, stdin)) break;
		pmsg->len = strlen(pmsg->body);
		MsgSend(coid, pmsg, sizeof(MESSAGE) + pmsg->len, pmsg, MAXMSGSIZE);
		if(pmsg->len < 1 || (pmsg->len == 1 && pmsg->body[0] == '\n')) continue;
		pmsg->body[pmsg->len] = 0;
		printf("kernel said:\n");
		printf("%s", pmsg->body);
	}
	printf("console closed\n");
	return EXIT_SUCCESS;
}
Beispiel #9
0
/*
 *  qnx_name_locate
 *
 *  Note that currently the only valid values for nid are 0 and the
 *  local nid.
 */
int
qnx_name_locate(nid_t nid, char *name, unsigned size, unsigned *copies)
{
	procmgr_msg_t   msg;
	procmgr_reply_t reply;

	if (nid != 0 && nid != getnid()) {
		errno = EHOSTUNREACH;
		return -1;
	}
	msg.hdr.type = _IO_MSG;
	msg.hdr.combine_len = sizeof(msg.hdr);
	msg.hdr.mgrid = MGR_ID_PROCMGR;
	msg.hdr.subtype = _PROCMGR_QNX_NAME_LOCATE;
	msg.un.locate.nid = nid; /* 0 */
	msg.un.locate.vc_size = size;
	strncpy(msg.un.locate.name, name, _NAME_MAX_LEN);
	msg.un.locate.name[_NAME_MAX_LEN] = '\0';
	if (MsgSend(magic.procmgr_fd, &msg, sizeof(msg), &reply, sizeof(reply)) == -1)
		return -1;
	errno = reply.set_errno_to_this;
	if (copies)
		*copies = reply.un.locate.copies;
	return reply.un.locate.pid;
}
Beispiel #10
0
/*
 *  Given a process id, iterate through all open files of that process
 *  looking for a match to the target file, and then determine how it
 *  is being used by that process.  This is quite different in QNX to
 *  UNIX, as chroot and chdir do not hold open a reference to the file.
 *  The iteration process attempts to dup each file descriptor into
 *  this process, so it can then be queried; attempt to skip things which
 *  aren't files (heuristic guess) and use a timeout as self-defence.
 */
int howused(pid_t pid, match_t *match)
{
struct _server_info	sinfo;
struct _fdinfo		finfo;
struct stat			st;
io_dup_t			msg;
uint64_t			to;
int					fd, coid, usage;

	usage = 0;
	for (fd = 0; (fd = ConnectServerInfo(pid, fd, &sinfo)) != -1; ++fd) {
		if ((pid != sinfo.pid || !(fd & _NTO_SIDE_CHANNEL)) && (coid = ConnectAttach(sinfo.nd, sinfo.pid, sinfo.chid, 0, _NTO_COF_CLOEXEC)) != -1) {
			msg.i.type = _IO_DUP;
			msg.i.combine_len = sizeof(msg.i);
			msg.i.info.nd = netmgr_remote_nd(sinfo.nd, ND_LOCAL_NODE);
			msg.i.info.pid = pid;
			msg.i.info.chid = sinfo.chid;
			msg.i.info.scoid = sinfo.scoid;
			msg.i.info.coid = fd;
			TimerTimeout(CLOCK_MONOTONIC, _NTO_TIMEOUT_SEND | _NTO_TIMEOUT_REPLY, NULL, (to = 1000000000LL, &to), NULL);
			if (MsgSend(coid, &msg.i, sizeof(msg.i), NULL, 0) == -1) {
				ConnectDetach(coid);
			}
			else {
				if (fstat(coid, &st) != -1 && ismatch(match, st.st_dev, st.st_ino)) {
					if (iofdinfo(coid, 0, &finfo, NULL, 0) == -1 || sinfo.pid != PATHMGR_PID || finfo.mode != 0)
						usage |= USED_OPEN;
				}
				close(coid);
			}
		}
	}
	return(usage);
}
Beispiel #11
0
extern "C" DLL_EXPORT bool _dbg_dbgcmdexec(const char* cmd)
{
    int len = (int)strlen(cmd);
    char* newcmd = (char*)emalloc((len + 1) * sizeof(char), "_dbg_dbgcmdexec:newcmd");
    strcpy_s(newcmd, len + 1, cmd);
    return MsgSend(gMsgStack, 0, (uint)newcmd, 0);
}
Beispiel #12
0
//Communication with the server
//Using buffers: buffer, receive
void* message_client(void* arg){

	//Define thread priority
	if(((struct thread_args*)arg)->which_thread == 0){
		set_priority(22);
		printf("I HAVE PRIORITY 22\n");
	}
	else if(((struct thread_args*)arg)->which_thread == 1){
		set_priority(21);
		printf("I HAVE PRIORITY 21\n");
	}
	else if(((struct thread_args*)arg)->which_thread == 2){
		set_priority(19);
		printf("I HAVE PRIORITY 19\n");
	}
	else{
		set_priority(18);
		printf("I HAVE PRIORITY 18\n");
	}

	//Perform communication
	int channelID, status;

	channelID = ConnectAttach(0, ((struct thread_args*)arg)->pid, 1, 0, 0);

	//Sends data in buffer. Puts returned data in receive buffer
	status = MsgSend(channelID, &buffer, sizeof buffer, &receive, sizeof receive);

	printf("SERVER REPLY: %c\n", receive[0]);

	//Detach from server
	ConnectDetach(channelID);

	return 0;
}
Beispiel #13
0
//接收到PC发来的USB数据包
void DeviceAudioOnCmd(void)
{
	if(!UsbIntFlag)
	{
		UsbIntFlag = TRUE;
		MsgSend(MSG_USB_DEVICE_INTERRUPT_CB); 
	}
}
void *ping(void *arg) {
	MESSAGE msg = { MSGPING, 0 }, reply;
	for(;;) {
		if(MsgSend(coid, &msg, sizeof(msg), &reply, sizeof(reply)) < 0 || reply.type != MSGPONG) {
			printf("kernel not responsible\n");
			exit(1);
		}
		sleep(1);
	}
}
Beispiel #15
0
//Button map
int ButtonMap::mapButton(int player, int button)
{
   recv_msg msg;
   msg.code = RETROARCH_BUTTON_MAP;

   this->player = player;
   this->button = button;

   return MsgSend(coid, (void*)&msg, sizeof(msg), (void*)NULL, 0);
}
Beispiel #16
0
int main(int argc, char *argv[]) {
	pid_t pid_2 = getpid();
	pid_t pid_1 = getppid();
	char *msg = (char*)malloc(BUFFER_LENGTH*sizeof(char));
	char *rmsg = (char*)malloc(BUFFER_LENGTH*sizeof(char));
	printf(" P2>\n");
	printf(" P2> Parent pid: %i\n", pid_1);
	int chidP1 = atoi(argv[0]);

	// Step 3 Creating channel - chidP2.
	int chidP2 = ChannelCreate(0);
	printf(" P2> pid: %i, P1 chid: %i, P2 chid: %i\n", pid_2, chidP1, chidP2);

	// Step 4 Spawning P3 process - pid_3.
	char argv0[12];
	sprintf(argv0, "%i", chidP2);
	int pid_3 = spawnl(P_NOWAITO, "/tmp/M3", argv0, NULL);

	// Step 6 Sending chidP2 to P1.
	int coid_1 = ConnectAttach(ND_LOCAL_NODE, pid_1, chidP1, _NTO_SIDE_CHANNEL, 0);
	if (coid_1==-1) {
		fprintf(stderr, "Connection error.\n");
		exit(EXIT_FAILURE);
	}
	printf(" P2> P2 coid: %i\n", coid_1);
	int msg_res = MsgSend(coid_1, &chidP2, sizeof(int), rmsg, BUFFER_LENGTH*sizeof(char)); //sizeof(bytes)
	if (msg_res < 0) {
		msg_res = errno;
		fprintf(stderr, " P2> Error MsgSend\n");
		fprintf(stderr, " P2> Error code:%i\n", msg_res);
		exit(EXIT_FAILURE);
	}
	printf(" P2> Server replied \n%s\n", rmsg);

	// Step 8 Receiving query from P3.
	int rcvid = MsgReceive(chidP2, msg, sizeof(msg), NULL);
	printf(" P2> Received, rcvid: %i\n", rcvid);
	printf(" P2> Message: %s\n", msg);

	// Step 9 Replying to P3. Sending pid_1 and chidP1.
	*(int*)((int)msg) = pid_1;
	*(int*)((int)msg + 4) = chidP1;
	MsgReply(rcvid, EOK, msg, 8);

	// Step 12 Receiving message from P1. Reply.
	rcvid = MsgReceive(chidP2, msg, sizeof(msg), NULL);
	printf(" P2> Received, rcvid: %i\n", rcvid);
	printf(" P2> Message: %s\n", msg);
	strcpy(msg, "P2 OK");
	MsgReply(rcvid, EOK, msg, strlen(msg) + 1);

	printf(" P2> Good luck!\n");
	return EXIT_SUCCESS;
}
Beispiel #17
0
//Communication with the server
//Using buffers: buffer, receive
int message_client(pid_t pid){
	int channelID, status;
	channelID = ConnectAttach(0, pid, 1, 0, 0);

	//Sends data in buffer. Puts returned data in receive buffer
	status = MsgSend(channelID, &buffer, sizeof buffer, &receive, sizeof receive);

	//Detach from server
	ConnectDetach(channelID);

	//Unnecessary return
	return channelID;
}
Beispiel #18
0
int main(int argc, char* argv[]) 
{
	int coid;         //Connection ID to server
	cksum_msg_t msg;
	int incoming_checksum;  //space for server's reply
	int status;       //status return value used for ConnectAttach and MsgSend
	int server_pid;   //server's process ID
	int server_chid;  //server's channel ID

    setvbuf (stdout, NULL, _IOLBF, 0);

	if(4 != argc) {
		printf("This program must be started with commandline arguments, for example:\n\n");
		printf("   cli 482834 1 abcdefghi    \n\n");
		printf(" 1st arg(482834): server's pid\n");
		printf(" 2nd arg(1): server's chid\n");
		printf(" 3rd arg(abcdefghi): string to send to server\n"); //to make it 
		                                //easy, let's not bother handling spaces
		exit(EXIT_FAILURE);
	}
	
	server_pid = atoi(argv[1]);
	server_chid = atoi(argv[2]);
	
	printf("attempting to establish connection with server pid: %d, chid %d\n", server_pid, server_chid);
	
	//PUT CODE HERE to establish a connection to the server's channel, store the
	//connection id in the variable 'coid'
	coid = ConnectAttach(ND_LOCAL_NODE, server_pid, server_chid, _NTO_SIDE_CHANNEL, NULL);
	if(-1 == coid) {   //was there an error attaching to server?
		perror("ConnectAttach"); //look up error code and print
		exit(EXIT_FAILURE);
	}
	
	msg.msg_type = CKSUM_MSG_TYPE;
	strcpy(msg.string_to_cksum, argv[3]);
	printf("Sending string: %s\n", msg.string_to_cksum);
	
	//PUT CODE HERE to send message to server and get the reply
	status = MsgSend(coid, &msg, sizeof(msg), &incoming_checksum, sizeof(incoming_checksum));
	if(-1 == status) {   //was there an error sending to server?
		perror("MsgSend");
		exit(EXIT_FAILURE);
	}
	
	printf("received checksum=%d from server\n", incoming_checksum);
	printf("MsgSend return status: %d\n", status);
	
	return EXIT_SUCCESS;
}
static bool GotoNextMode(void)
{
	if(gSys.NextModuleID == MODULE_ID_PLAYER_SD)
	{
		gSys.DiskType = SD_TYPE;
	}
	else if(gSys.NextModuleID == MODULE_ID_PLAYER_USB)
	{
		gSys.DiskType = USB_TYPE;
	}

	MsgSend(MSG_COMMON_CLOSE);
	return TRUE;	
}
Beispiel #20
0
/*
 *  Implement the '-u' option (display user associated with the process).
 *  First directly query procnto (however it restricts this to processes
 *  in the same session); then deduce it from profcs (address space owner).
 */
uid_t whois(pid_t pid)
{
proc_getsetid_t	msg;
struct stat		st;
char			as[32];

	msg.i.type = _PROC_GETSETID, msg.i.subtype = _PROC_ID_GETID;
	msg.i.pid = pid;
    if (MsgSend(PROCMGR_COID, &msg.i, sizeof(msg.i), &msg.o, sizeof(msg.o)) != -1)
		return(msg.o.cred.ruid);
	sprintf(as, "/proc/%d/as", pid);
	if (stat(as, &st) != -1)
		return(st.st_uid);
	return((uid_t)-1);
}
Beispiel #21
0
//Communication with the server
//Using buffers: buffer, receive
void* message_client(pid_t pid){
	int channelID, status;
	printf("RECEIVED ARGUMENT FROM DUMB PROCESS: %d\n", pid);
	channelID = ConnectAttach(0, pid, 1, 0, 0);

	//Sends data in buffer. Puts returned data in receive buffer
	status = MsgSend(channelID, &buffer, sizeof buffer, &receive, sizeof receive);

	printf("SERVER REPLY: %c\n", receive[0]);

	//Detach from server
	ConnectDetach(channelID);

	return 0;
}
Beispiel #22
0
/*** Client Side of the code ***/
int client() {
    mss_t msg;
    int server_coid;
    mss_t rmsg;

    if ((server_coid = name_open(ATTACH_POINT, 0)) == -1) {
        return EXIT_FAILURE;
    }

    /* We would have pre-defined data to stuff here */
   // msg.hdr.type = 0x00;
    //msg.hdr.subtype = 0x00;
    msg.ile = 0;
    int typ = 1;
    msg.typ = typ;
    int from = getpid();
    msg.from = from;


    int i = 0;
    int count = 0;

    /* Do whatever work you wanted with server connection */

    	printf("what you want Send?");
    	scanf("%s", msg.text);

    	for(i = 0; i < strlen(msg.text); i++){
    		if(islower(msg.text[i]) )
    		count++;
    	}
    	printf("count : %d ", count);
    	msg.ile = count;

    	printf("Client sending msg, lower case letters: %d \n", msg.ile);

        if (MsgSend(server_coid, &msg, sizeof(msg), &rmsg, sizeof(rmsg)) == -1) {
        	perror("MsgSend");
        	exit(EXIT_FAILURE);
        }

        printf("received message %s from server %d\n",rmsg.text, rmsg.from);


    /* Close the connection */
    name_close(server_coid);
    return EXIT_SUCCESS;
}
Beispiel #23
0
int close(int fd) {
	io_close_t					msg;
	int							ret, err;

	msg.i.type = _IO_CLOSE;
	msg.i.combine_len = sizeof msg.i;
	if((ret = MsgSend(fd, &msg.i, sizeof msg.i, 0, 0)) != -1 || errno != EINTR) {
		if((err = ConnectDetach_r(fd)) == EOK) {
			return ret;
		}
		if(ret != -1) {
			errno = err;
		}
	}
	return -1;
}
Beispiel #24
0
int posix_fallocate64(int fd, off64_t offset, off64_t len) {
	io_space_t					msg;

	msg.i.type = _IO_SPACE;
	msg.i.combine_len = sizeof msg.i;
	msg.i.subtype = F_ALLOCSP64;
	msg.i.whence = SEEK_SET;
	msg.i.start = offset;
	msg.i.len = len;

	if(MsgSend(fd, &msg.i, sizeof msg.i, 0, 0) == -1) {
		return -1;
	}

	return 0;
}
Beispiel #25
0
int
name_init(void)
{
	procmgr_msg_t	msg;
	procmgr_reply_t	reply;

    msg.hdr.type = _IO_MSG;
	msg.hdr.combine_len = sizeof(msg.hdr);
	msg.hdr.mgrid = MGR_ID_PROCMGR;
	msg.hdr.subtype = _PROCMGR_GET_NID;
	if (MsgSend(magic.procmgr_fd, &msg, sizeof(msg), &reply, sizeof(reply)) == -1)
		return -1;
	magic.nid = reply.un.get_nid.nid;

	return 0;
}
Beispiel #26
0
void *count_primes2(void *arg) {
	int status;
	int coid;
	par_t reply;

	coid = ConnectAttach(ND_LOCAL_NODE, pid, chid, _NTO_SIDE_CHANNEL, 0);
	while (1) {
		par_t args;
		args.typ = 10;
		args.numer = pthread_self();

		status = MsgSend(coid, &args, sizeof(args), &reply, sizeof(reply));
		if (reply.typ == 1) {
			sleep(1);

			int primes_count = 0;

			printf("Proces: %d, watek: %d\n", getpid(), pthread_self());
			int i;
			for (i = reply.pocz; i < reply.kon; i++) {
				int c;
				int prime = 1;
				for (c = 2; c <= i / 2; c++) {
					if (i % c == 0) {
						prime = 0;
						break;
					}
				}
				if (prime && i != 0 && i != 1)
					primes_count++;
			}

			//sleep(15 - args->numer);

			printf("\twatek: %d, poczatek %d, koniec %d, primes %d\n",
					pthread_self(), reply.pocz, reply.kon, primes_count);

			pthread_mutex_lock(&primes_mutex);
			p_count += primes_count;
			pthread_mutex_unlock(&primes_mutex);
		} else if (reply.typ == 0) {
			return 0;
		}

	}
}
Beispiel #27
0
void nagger(void *arg){
	set_priority(*(int*)arg);

	// Creating shared memory
	int skynetDesc = shm_open("/skynetcore", O_RDWR, S_IRWXU);
	struct skynetCore_t* skynetCore = mmap(0, sizeof(struct skynetCore_t), PROT_READ|PROT_WRITE, MAP_SHARED, skynetDesc, 0);

	pthread_mutex_lock(&skynetCore->protector);
	int corePid = skynetCore->pid;
	pthread_mutex_unlock(&skynetCore->protector);

	int message = *(int*)arg;
	int skynetChannelId = ConnectAttach(0, corePid, 1, 0, 0);
	MsgSend(skynetChannelId, &message, sizeof(int), &message, sizeof(int));
	printf("I sent %i and got %i back!\n", *(int*)arg, message);
	ConnectDetach(skynetChannelId);
}
Beispiel #28
0
void *t2()
{
	int coid, sending_status;

	struct _msg_info client_info;
	client_info.tid = 2;
	client_info.priority = 13;
	coid = ConnectAttach(0, pid, chid, _NTO_SIDE_CHANNEL, &client_info);

	sending_status = MsgSend(coid, NULL, 0, NULL, 0);
	if(-1 == sending_status) {   //was there an error sending to server?
		perror("MsgSend");
		exit(EXIT_FAILURE);
	}

	return EXIT_SUCCESS;

}
Beispiel #29
0
int main( int argc, char** argv )
{
    int fd;
    unsigned *addr;
    int ConnectionID;

    /* Create a new memory object */
    fd = shm_open( "/MySharedMemory", O_RDWR, 0777 );
    if( fd == -1 ) 
    {
        printf("error: couldn't open a shared memory object\n");
        return EXIT_FAILURE;
    }
    
    /* Map the memory object */
    addr = mmap( 0, 1024, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 );
    if( addr == MAP_FAILED ) 
    {
    	    printf("error: mapping in the memory failed\n");
    	    return EXIT_FAILURE;
    }

    printf( "memory mapping address is 0x%08x\n", addr );

    if((ConnectionID = ConnectAttach(0, addr[1022], addr[1023], _NTO_SIDE_CHANNEL, 0)) == -1)
    		printf("error: couldn't attach to channel\n");
    
    while(1)
    {
    		/* synchronize with the server: block until server has written shared memory */
    		if(MsgSend(ConnectionID, NULL, 0, NULL, 0) == -1)
    			break;
 
    		/* Read to shared memory */
    		printf("read shared memory: %s\n", (char*)addr);
    		sleep(1);
    	}

    close( fd );
    shm_unlink( "/MySharedMemory" );

    return EXIT_SUCCESS;
}
Beispiel #30
0
/*
 *  qnx_name_detach
 *
 *  Note that currently the only valid values for nid are 0 and the
 *  local nid.
 */
int
qnx_name_detach(nid_t nid, int name_id)
{
	procmgr_msg_t   msg;
	procmgr_reply_t reply;

	if (nid != 0 && nid != getnid()) {
		errno = EHOSTUNREACH;
		return -1;
	}
	msg.hdr.type = _IO_MSG;
	msg.hdr.combine_len = sizeof(msg.hdr);
	msg.hdr.mgrid = MGR_ID_PROCMGR;
	msg.hdr.subtype = _PROCMGR_QNX_NAME_DETACH;
	msg.un.detach.nid = nid;
	msg.un.detach.name_id = name_id;
	if (MsgSend(magic.procmgr_fd, &msg, sizeof(msg), &reply, sizeof(reply)) == -1)
		return -1;
	errno = reply.set_errno_to_this;
	return reply.un.detach.retval;
}