Beispiel #1
0
void dg_cli(int socketfd,struct sockaddr_in *server_address,int server_len)
{
	
	int n=0;
	int offset=0;
	int i;
	char test[]="this wenxu  test";
	void *sharemem=NULL;
	int shmid;
	int msgid;
	while(n<10)
	{
	memset(msg_sbuf.mtext,0,sizeof(msg_sbuf.mtext));
	sprintf(msg_sbuf.mtext,"%s %d",test,n);
	
	//printf("the data is %d\n",n);		
	msg_sbuf.mtype=2;
	msg_sbuf.offset=strlen(msg_sbuf.mtext);
	struct msghdr msg;
        struct iovec iov[1];
        bzero(&msg, sizeof(msg));
        msg.msg_name = server_address;        /* attention this is a pointer to void* type */
        msg.msg_namelen = server_len;
        iov[0].iov_base = &msg_sbuf;
        iov[0].iov_len = sizeof(msg_sbuf);
        msg.msg_iov = iov;
        msg.msg_iovlen = 1;
	if (sendmsg(socketfd, &msg, 0) == -1)
                perror("sendmsg bad");
	printf("send buf ok %s \n",msg_sbuf.mtext);
	n++;	
	sleep(1);
	}
	n=0;
	while(n<10)
	{
		GetFifo();
		if((shmid=shmget((key_t)654321,(size_t)4096,0600|IPC_CREAT))==-1) 
		{
			perror("can not get share mem");
			exit(1);
		}
		if((sharemem=shmat(shmid,NULL,0))==NULL)
		{
			perror("can  mount the  share  mem");
			shmctl(shmid,IPC_RMID,0);
			exit(1);
		}			
		memcpy(sharemem+offset,&msg_sbuf2,sizeof(msg_sbuf2));		
		//printf("child input   data   and   data hhhhhhhh is : %s \n",sharemem+offset); 
		offset+=sizeof(msg_sbuf2);
		n++;	
	}
	if((msgid=msgget((key_t)0x12345,0666|IPC_CREAT))==-1)
	{
		perror("can  not  msgget");
Beispiel #2
0
void USART2_IRQHandler(void)
{
  uint8_t data;
  int status;
  if (USART_GetITStatus(USART2,USART_IT_TXE)!= RESET)
      {
        LED_On();
        status = GetFifo( &data);
        if(!status)
          {
            USART_ITConfig(USART2,USART_IT_TXE,DISABLE);
            return;
          }
        //GetFifo( &data);
        USART_SendData(USART2, data);

      }
}