http://blog.csdn.net/unix21/article/details/15337939
2013
在Redis2.8中有networking.c,这个文件没有networking.h
networking.c首先引入redis.h这个头文件
在redis.c一开始就声明了全局变量
- /* Global vars */
- struct redisServer server;
networking.c的createClient函数
- redisClient *createClient(int fd) {
- redisClient *c = zmalloc(sizeof(redisClient));
-
- /* passing -1 as fd it is possible to create a non connected client.
- * This is useful since all the Redis commands needs to be executed
- * in the context of a client. When commands are executed in other
- * contexts (for instance a Lua script) we need a non connected client. */
- if (fd != -1) {
- anetNonBlock(NULL,fd);
- anetEnableTcpNoDelay(NULL,fd);
- if (server.tcpkeepalive)
- anetKeepAlive(NULL,fd,server.tcpkeepalive);
- if (aeCreateFileEvent(server.el,fd,AE_READABLE,
- readQueryFromClient, c) == AE_ERR)
- {
- close(fd);
- zfree(c);
- return NULL;
- }
- }
这里之所以可以引用redisClient就是因为redisClient在redis.h是被声明为
extern的,而networking.c已经引入redis.h这个头文件
- /*-----------------------------------------------------------------------------
- * Extern declarations
- *----------------------------------------------------------------------------*/
-
- extern struct redisServer server;
不然注释掉extern struct redisServer server是编译不过去的:
关于extern和头文件的解释:
出自《C语言入门经典(第四版)》
出自《21天学通C语言(第6版)》
出自《C语言编程:一本全面的C语言入门教程 (第3版)》
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。