gcc编译错误,求助!

swizard04 2010-03-08 09:42:07
源代码如下:
1 #include "unpthread.h"
2
3 #define MAXFILES 20
4 #define SERV "80" /* port number or server name */
5
6 struct file {
7 char *f_name; /* filename */
8 char *f_host; /* hostname or IPv4/IPv6 address */
9 int f_fd; /* description */
10 int f_flags; /* F_xxx below */
11 pthread_t f_tid; /* thread ID */
12 } file[ MAXFILES ];
13
14 #define F_CONNECTING 1; /* connect( ) in progress */
15 #define F_READING 2; /* connect( ) complete; now reading */
16 #define F_DONE 4; /* all done */
17 #define F_JOINED 8; /* main has pthread_join'ed */
18
19 #define GET_CMD "GET %s HTTP/1.0\r\n\r\n"
20
21 int ndone; /* number of terminated threads */
22 pthread_mutex_t ndone_mutex = PTHREAD_MUTEX_INITIALIZER;
23 pthread_cond_t ndone_cond = PTHREAD_COND_INITIALIZER;
24
25 /* globals */
26 int nconn, nfiles, nlefttoconn, nlefttoread;
27
28 /* function prototypes */
29 void home_page( const char *, const char * );
30 void *do_get_read( void * );
31 void write_get_cmd( struct file * );
32
33 int
34 main( int argc, char **argv )
35 {
36 int i, n, maxconn;
37 pthread_t tid;
38 struct file *fptr;
39
40 if ( argc < 5 )
41 err_quit( "usage: web <#conns> <hostname> <homepage> <file> ..." );
42 maxconn = atoi( argv[ 1 ] );
43
44 nfiles = min( argc - 4, MAXFILES );
45 for ( i = 0; i < nfiles; i++ ) {
46 file[ i ].f_name = argv[ i + 4 ];
47 file[ i ].f_host = argv[ 2 ];
48 file[ i ].f_flags = 0;
49 }
50 printf( "nfiles = %d\n", nfiles );
51
52 home_page( argv[ 2 ], argv[ 3 ] );
53
54 nlefttoconn = nlefttoread = nfiles;
55 nconn = 0;
56
57 while ( nlefttoread > 0 ) {
58 while ( nconn < maxconn && nlefttoconn > 0 ) {
59 /* find a file to read */
60 for ( i = 0; i < nfiles; i++ )
61 if ( file[ i ].f_flags == 0 )
62 break;
63 if ( i == nfiles )
64 err_quit( "nlefttoconn = %d but nothing found", nlefttoconn );
65
66 file[ i ].f_flags = F_CONNECTING;
67 Pthread_create( &tid, NULL, &do_get_read, &file[ i ] );
68 file[ i ].f_tid = tid;
69 nconn++;
70 nlefttoconn--;
71 }
72
73 /* Wait for one of the thread to terminate */
74 Pthread_mutex_lock( &ndone_mutex );
75 while ( ndone == 0 )
76 Pthread_cond_wait( &ndone_cond, &ndone_mutex );
77 for ( i = 0; i < nfiles; i++ ) {
78 if ( file[ i ].f_flags & F_DONE ) {
79 Pthread_join( file[ i ].f_tid, ( void ** ) &fptr );
80
81 if ( &file[ i ] != fptr )
82 err_quit( "file[ i ] != fptr" );
83 fptr->f_flags = F_JOINED; /* clears F_DONE */
84 ndone--;
85 nconn--;
86 nlefttoread--;
87 printf( "thread %d for %s done\n", fptr->f_tid, fptr->f_name );
88 }
89 }
90 Pthread_mutex_unlock( &ndone_mutex );
91 }
92
93 exit( 0 );
94 }
95
96 void *
97 do_get_read( void *vptr )
98{
99 int fd, n;
100 char line[ MAXLINE ];
101 struct file *fptr;
102
103 fptr = ( struct file * ) vptr;
104
105 fd = Tcp_connect( fptr->f_host, SERV );
106 fptr->f_fd = fd;
107 printf( "do_get_read for %s, fd %d, thread %d\n",
108 fptr->f_name, fd, fptr->f_tid);
109 write_get_cmd( fptr ); /* write( ) the GET command*/
110 /* Read server's reply */
111 for ( ; ; ) {
112 if ( ( n = Read( fd, line, MAXLINE ) ) == 0 )
113 break; /* server closed connection */
114 printf( "read %d bytes from %s\n", n, fptr->f_name );
115 }
116 printf( "end-fo-file on %s\n", fptr->f_name );
117 Close( fd );
118 Pthread_mutex_lock( &ndone_mutex );
119 fptr->f_flags = F_DONE; /* close F_READING */
120
121 ndone++;
122 Pthread_cond_signal( &ndone_cond );
123 Pthread_mutex_unlock( &ndone_mutex );
124
125 return( fptr ); /* terminate thread */
126 }
127
128 void
129 write_get_cmd( struct file *fptr )
130 {
131 int n;
132 char line[ MAXLINE ];
133
134 n = snprintf( line, sizeof( line ), GET_CMD, fptr->f_name );
135 Writen( fptr->f_fd, line, n );
136 printf( "worte %d bytes for %s\n", n, fptr->f_name );
137
138 fptr->f_flags = F_READING; /* clear F_CONNECTING */
139 }
140
141 void
142 home_page( const char *host, const char *fname )
143 {
144 int fd, n;
145 char line[ MAXLINE ];
146
147 fd = Tcp_connect( host, SERV ); /* blcoking connect( ) */
148
149 n = snprintf( line, sizeof( line ), GET_CMD, fname );
150 Writen( fd, line, n );
151
152 for ( ; ; ) {
153 if ( ( n = Read( fd, line, MAXLINE ) ) == 0 )
154 break; /* server closed connection */
155 printf( "read %d bytes of home page\n", n );
156 /* do whatever with data */
157 }
158 printf( "end-of-file on home page\n" );
159 Close( fd );
160 }
[web.c]

是UNP中的一个例子,编译命令是:
  gcc -o web web.c -lunp -lpthread
web.c: 78: error: expected ')' before ';' token
大家帮忙检查一下那里错了 ?
...全文
125 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
swizard04 2010-03-09
  • 打赏
  • 举报
回复
Re:brookmill
谢谢! 就是这个问题。
Re:steptodream
我已经说过这是UNP中的一个例子,只是输入错误,其实代码本身很简单。
x-teamer团队 2010-03-09
  • 打赏
  • 举报
回复
非常单纯的过来支持~
steptodream 2010-03-09
  • 打赏
  • 举报
回复
楼上一点破 楼主真厉害 宏定义都用不对的情况下 能写出这牛逼的代码
brookmill 2010-03-09
  • 打赏
  • 举报
回复
14~17行,宏定义1248后面的分号都去掉

F_DONE被替换成了4;
78行经过预处理之后就变成了 if ( file[ i ].f_flags & 4; ) {

steptodream 2010-03-08
  • 打赏
  • 举报
回复
引用 4 楼 feiyinzilgd 的回复:
看到这种很乱的帖子,我想大家都有一个共同的特点:烦躁。不想看。

哈哈

这么晚才来呀 我把QQ都关了 打算睡觉了
谭海燕 2010-03-08
  • 打赏
  • 举报
回复


看到这种很乱的帖子,我想大家都有一个共同的特点:烦躁。不想看。

哈哈

spfbc 2010-03-08
  • 打赏
  • 举报
回复
引用 2 楼 steptodream 的回复:
我感觉你的{不配对 自己先检查
要么把完整的代码改写到代码框里

同意。呵呵。。。
steptodream 2010-03-08
  • 打赏
  • 举报
回复
我感觉你的{不配对 自己先检查
要么把完整的代码改写到代码框里
steptodream 2010-03-08
  • 打赏
  • 举报
回复
你也把代码发到代码框里呀 乱!

23,125

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧