请大家帮忙看下,为什么这段代码无法返回???

wesleyluo 2013-04-11 03:51:39
下面的代码是ffserver里面的部分片段;
现在问题是程序执行到这个函数里面就卡住了,求解。
URLContext 为一个包含URLProtocol *prot结构的结构指针;
URLProtocol 结构中有一个函数指针url_close如下。
int url_close(URLContext *h)
{
int ret;
printf("url_close\n");

ret = h->prot->url_close(h);
av_free(h);
printf("url_close return\n");
return ret;
}
如果调用url_close(h);请问这个为什么在ret = h->prot->url_close(h);这句不返回呢?
...全文
163 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
wesleyluo 2013-04-12
  • 打赏
  • 举报
回复
感觉你说的很对,我测试下,我也看不懂这里为什么要这么写。。
空的 2013-04-12
  • 打赏
  • 举报
回复
不是加减一...指向下一个就行。。。 意思是这个意思。。。 h->prot->next->url_close(h);
空的 2013-04-12
  • 打赏
  • 举报
回复
结构体有个这个 struct URLProtocol *next; url_close意思是不是要把整个 URL链关闭 通过起始的或末端的位,后然指针加一减关闭整个 ret = (h+—1)->prot->url_close(h); 至于为什么卡住了,还看不出来
黑泡泡选手 2013-04-11
  • 打赏
  • 举报
回复
确实是,怎么自己关闭自己呢,能不能先把这句话注释掉~url_close函数的使用有问题吧?
wesleyluo 2013-04-11
  • 打赏
  • 举报
回复
但是,问题是运行了url_close(h)以后,只打印了一次url_close,然后就没了; 怎么没有无限调用呢?也就是应该打印很多次url_close啊
prohibit 2013-04-11
  • 打赏
  • 举报
回复
如果是这样,就无限调用了。。。
	URLProtocol prot;
	prot.url_close = url_close;

	URLContext text;
	text.prot = &prot;

	url_close(&text);//调用text->prot->url_close,又是url_close本身。。
wesleyluo 2013-04-11
  • 打赏
  • 举报
回复
struct URLContext { struct URLProtocol *prot; int flags; int is_streamed; /* true if streamed (no seek possible), default = false */ int max_packet_size; /* if non zero, the stream is packetized with this max packet size */ void *priv_data; char filename[1]; /* specified filename */ }; int url_close(URLContext *h); typedef struct URLProtocol { const char *name; int (*url_open)(URLContext *h, const char *filename, int flags); int (*url_read)(URLContext *h, unsigned char *buf, int size); int (*url_write)(URLContext *h, unsigned char *buf, int size); offset_t (*url_seek)(URLContext *h, offset_t pos, int whence); int (*url_close)(URLContext *h); struct URLProtocol *next; } URLProtocol; 这个url_close函数就是我上面贴的。
prohibit 2013-04-11
  • 打赏
  • 举报
回复
引用 2 楼 wesleyluo 的回复:
是啊,程序里面就这么些的,我在看别人的代码。
你把结构体(关键代码就行,不用全部代码)URLContext,URLProtocol,以及URLProtocol中函数指针的赋值贴出来看看呢~~
wesleyluo 2013-04-11
  • 打赏
  • 举报
回复
是啊,程序里面就这么些的,我在看别人的代码。
prohibit 2013-04-11
  • 打赏
  • 举报
回复
关系没搞太明白,h->prot->url_close中的函数指针又指向函数int url_close(URLContext *h)了?自己调用自己?

23,217

社区成员

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

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