LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 926|回复: 0

求助:消息队列在linux系统的pc上可运行,但在S3C4510B(ARM7)板子上(uclinux系统)不能运行,为

[复制链接]
发表于 2006-5-8 14:07:30 | 显示全部楼层 |阅读模式
错误提示:
receiver:error in establish or open a message queue,errno=38
error type: Function not implemented
pid 24: failed 256

源程序:
#include <arpa/inet.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

#define debug

#define port 81
#define addr_ip INADDR_ANY
#define backlog 5
#define num 1
#define maxline 5

#define ordernum (long)('o')
#define presentnum (long)('p')

extern int errno;

char s10[]="<html><head><title>My works</title></head><body>";
char s11[]="<FORM ACTION=http://192.168.1.200:81 MATHOD=GET><p>Water level:<INPUT TYPE=TEXT NAME=level SIZE=30><p><INPUT TYPE=submit><INPUT TYPE=reset></FORM></body></html>\n";

char s20[]="<html><head><title>My works</title></head><body>";
char s21[]="</body></html>\n";

int lth1=sizeof(s10)+60,lth2=sizeof(s20)+sizeof(s21)+20+40*num;

key_t key=12345;

struct mymesg{
        long mtype;
char mtext[10];
}

/*error*/
report_error(char *s)                    
{
printf("receiver:error in %s,errno=%d\n",s,errno);
perror("error type");
exit(1);
}

/*open or creat a queue(error:-1;true:qid)*/
int open_queue(key_t keyval)
{
int qid;
if((qid=msgget(keyval,IPC_CREAT|0760))==-1)
{return(-1);}
return(qid);
}

/*send message to an opened queue(error:-1;true:0)*/
int send_message(int qid,char sbuf[maxline],long type)
{
struct mymesg *qbuf;
int result,length;
(*qbuf).mtype = type;
strcpy((*qbuf).mtext,sbuf);
length=sizeof(struct mymesg)-sizeof(long);
if((result=msgsnd(qid,qbuf,length,0))==-1)
  {return(-1);}
return(result);
}

/* Read a message from the queue(true:the read message size;have no message:0)*/
int read_message(int qid,char sbuf[maxline],long type)
{
struct mymesg *qbuf;
int result,length;
(*qbuf).mtype = type;
length=sizeof(struct mymesg)-sizeof(long);
if((result=msgrcv(qid,qbuf,length,type,IPC_NOWAIT))==-1)
return(0);
else {
       strcpy(sbuf,(*qbuf).mtext);
        return(result);
     }
}


/*write head*/
writehead(FILE *f1,int lth)      
{
fprintf(f1,"HTTP/1.0 200 OK\n");
fprintf(f1,"Content-type:text/html\n");
fprintf(f1,"Date:Sun,01-Mar-2006 12:00:00 GMT\n");
fprintf(f1,"Server:ipserver-http 1.1\n");
fprintf(f1,"Expires:Sun,01-Oct-2006 12:00:00 GMT\n");
fprintf(f1,"Context-Length:%d\n",lth);
#ifdef debug
printf("flength=%d\n\n",lth);
#endif
fprintf(f1,"\n");
}

/*handle message and send*/
handlemsg(int fd,int qid)
{
FILE *f;
char buf[2048]="",numb[maxline]="",gnum[maxline]="";
int i=0,j=0,flag1=0,flag2=0,flag=0;
/*read message*/
if(recv(fd,buf,2038,0)<0)        
{
  close(fd);
  report_error("receive");
}
#ifdef debug
printf("receive success...\n");
printf("buf=%s\n",buf);
#endif
do     
{
if(buf=='?')flag=1;  
if((flag==1)&&(buf =='=')==1)
flag1=i;
if((flag==1)&&(buf ==' ')==1)
flag2=i;
i++;
}while(buf!='\n');
#ifdef debug
printf("flag=%d\n",flag);
#endif

/*open the newfd to send message*/
f=fdopen(fd,"w");      
if(!f)
{
  close(fd);
  report_error("fdopen");
}
printf("fdopen success...\n");
setbuf(f,0);

/*no message*/
if(flag==0)
{
if(read_message(qid,gnum,presentnum)==0)
    printf("read no message/n");
writehead(f,lth1);
fprintf(f,s10);
fprintf(f,"<p>The present data:level=%s",gnum);
fprintf(f,s11);
fflush(f);
fclose(f);
}

/*resive message*/
else      
{
j=0;
for(i=flag1+1;i<flag2;i++)
numb[j++]=buf;
if(read_message(qid,gnum,presentnum)==0)
    printf("read no message/n");
if(read_message(qid,NULL,ordernum)==0)
    printf("read no message/n");
if(send_message(qid,numb,ordernum)==-1)
    report_error("send message");
writehead(f,lth2);
fprintf(f,s20);
fprintf(f,"<p>Resive message:level=%s",numb);
fprintf(f,"<p>The present data:level=%s",gnum);
fprintf(f,s21);
fflush(f);
fclose(f);
}
}

main()
{
pid_t pid;
int sockfd,newfd;
int qidx;
struct sockaddr_in my_addr,their_addr;
int sin_size;
volatile int true=1;

/*establish or open a message queue*/
if((qidx=open_queue(key))==-1)
    report_error("establish or open a message queue");
printf("establish or open a message queue success...\n");

/*vfork*/
if((pid=vfork())<0)
report_error("vfork");
printf("vfork success...\n");

/*child*/
if(pid==0)
{
/*run arm control*/
if(execl("/var/tmp/b.o","b.o",(char *)0)<0)
report_error("execl armctrl");
}

/*father*/
if(pid>0)
{

/*socket*/
if((sockfd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==-1)
report_error("socket");
printf("socket success...\n");

/*socket set*/
if((setsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR,(void *)&true,sizeof(true)))==-1)

report_error("socket set");

printf("socket set success...\n");

/*bind*/
my_addr.sin_family=AF_INET;
#ifdef port
my_addr.sin_port=htons(port);
#else
my_addr.sin_port=htons(IPPORT_USERRESERVED);
#endif
my_addr.sin_addr.s_addr=htonl(addr_ip);
printf("port=%d\n",my_addr.sin_port);
bzero(&(my_addr.sin_zero),8);
if(bind(sockfd,(struct sockaddr *)&my_addr,sizeof(my_addr))==-1)
report_error("bind...\n");
printf("bind success...\n");

/*listen*/
if(listen(sockfd,backlog)==-1)
report_error("listen");
printf("listen success...\n");
while(1)
{
sin_size=sizeof(struct sockaddr_in);
printf("server is run...\n");

/*new cling*/
newfd=accept(sockfd,(struct sockaddr *)&their_addr,&sin_size);
if(newfd<0&&errno==EINTR)
continue;

/*a signal might interrupt our accept() call*/
else if(newfd<0)

/*something quite amiss -- kill the server*/
report_error("accept");
printf("accept success...\n");

/*handle message and send*/
#ifdef debug
printf("their_ip=%s\n",inet_ntoa(their_addr.sin_addr));
#endif
handlemsg(newfd,qidx);

/*close client socket*/
close(newfd);
}

close(sockfd);  /*close listen socket*/
exit(0);
}
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表