亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 2278 | 回復(fù): 1
打印 上一主題 下一主題

[FastDFS] 求5.01版本tracker_get_connection_r的正確用法。 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2014-06-04 18:48 |只看該作者 |倒序瀏覽
conn = tracker_get_connection_r(&TrackerServer, &result);

這個TrackerServer  和  conn 是啥關(guān)系, 關(guān)閉的時候要如何才能正確關(guān)閉連接。


論壇徽章:
0
2 [報告]
發(fā)表于 2014-06-05 11:33 |只看該作者
本帖最后由 toniz 于 2014-06-05 11:35 編輯

這個問題已經(jīng)決解。

我為了重用,把connect和disconnect部分單獨拆成一個方法。
但其實TrackerServer不能在方法里面定義,要在使用的地方定義,作為參數(shù)帶進去才行。
不然調(diào)用close后,這個鏈接會一直存在(實際上沒有close這個socket)。
如果連接數(shù)滿了之后,服務(wù)端會發(fā)起fin,這個時候會造成客戶端大量close_wait.

正確代碼如下:

  1. ConnectionInfo* FdfsClient::connectFastDFS(ConnectionInfo &trackerServer,
  2.                                            ConnectionInfo &storageServer,
  3.                                            int &store_path_index, char group_name[])
  4. {
  5.     int result;
  6.     ConnectionInfo *conn;
  7.     conn = tracker_get_connection_r(&trackerServer, &result);
  8.     if ( result != 0 )
  9.     {   
  10.         MYLOG_WARN(logger, "tracker_get_connection fail, error no: %d, error info: %s\n", errno , STRERROR(errno));
  11.         return NULL;
  12.     }   

  13.     *group_name = '\0';
  14.     store_path_index = 0;
  15.     result = 0;
  16.     if ((result=tracker_query_storage_store(conn, &storageServer, group_name, &store_path_index)) != 0)
  17.     {   
  18.         fdfs_quit(conn);
  19.         tracker_disconnect_server(conn);
  20.         MYLOG_WARN(logger, "tracker_query_storage fail, error no: %d, error info: %s\n", result, STRERROR(result));
  21.         return NULL;
  22.     }   

  23.     return conn;
  24. }
復(fù)制代碼
錯誤代碼如下:
  1. ConnectionInfo* FdfsClient::connectFastDFS(ConnectionInfo &storageServer, int &store_path_index, char group_name[])
  2. {
  3.     int result;
  4.     ConnectionInfo TrackerServer;
  5.     ConnectionInfo *conn;
  6.     conn = tracker_get_connection_r(&TrackerServer, &result);
  7.     if ( result != 0 )
  8.     {
  9.         MYLOG_WARN(logger, "tracker_get_connection fail, error no: %d, error info: %s\n", errno , STRERROR(errno));
  10.         return NULL;
  11.     }

  12.     *group_name = '\0';
  13.     store_path_index = 0;
  14.     result = 0;
  15.     if ((result=tracker_query_storage_store(conn, &storageServer, group_name, &store_path_index)) != 0)
  16.     {
  17.         fdfs_quit(conn);
  18.         tracker_disconnect_server(conn);
  19.         MYLOG_WARN(logger, "tracker_query_storage fail, error no: %d, error info: %s\n", result, STRERROR(result));
  20.         return NULL;
  21.     }
  22.     return conn;
  23. }
復(fù)制代碼
調(diào)用的代碼如下:
  1. int FdfsClient::uploadAppenderByBuff(const char *file_content, int content_len, const char *file_ext_name, char file_id[])               
  2. {                                                                                                                                       
  3.     int store_path_index;                                                                                                               
  4.     ConnectionInfo trackerServer;                                                                                                        
  5.     ConnectionInfo storageServer;                                                                                                        
  6.     char group_name[FDFS_GROUP_NAME_MAX_LEN + 1];                                                                                       
  7.                                                                                                                                          
  8.     int result;                                                                                                                          
  9.     ConnectionInfo *pTrackerServer;                                                                                                      
  10.     pTrackerServer = connectFastDFS(trackerServer, storageServer, store_path_index, group_name);                                         
  11.                                                                                                                                          
  12.     if( pTrackerServer == NULL )                                                                                                         
  13.     {                                                                                                                                    
  14.         return RETURN_GET_CONNECTION_FAIL;                                                                                               
  15.     }                                                                                                                                    
  16.                                                                                                                                          
  17.     result = storage_upload_appender_by_filebuff1(pTrackerServer, &storageServer, store_path_index, \                                    
  18.                             file_content, content_len, file_ext_name, NULL, 0, group_name, file_id);                                    
  19.                                                                                                                                          
  20.     if (result != 0)                                                                                                                     
  21.     {                                                                                                                                    
  22.         MYLOG_WARN(logger, "upload file fail, error no: %d, error info: %s\n", result, STRERROR(result));                                
  23.         disConnectFastDFS(pTrackerServer, storageServer);                                                                                
  24.         return RETURN_UPLOAD_APPENDER_FAIL;                                                                                             
  25.     }                                                                                                                                    
  26.     disConnectFastDFS(pTrackerServer, storageServer);                                                                                    
  27.     return RETURN_SUCCESS;                                                                                                               
  28. }
復(fù)制代碼
disconnect代碼如下:
  1. int FdfsClient::disConnectFastDFS(ConnectionInfo *pTrackerServer, ConnectionInfo &storageServer)
  2. {
  3.     fdfs_quit(&storageServer);
  4.     tracker_disconnect_server(&storageServer);
  5.     fdfs_quit(pTrackerServer);
  6.     tracker_disconnect_server(pTrackerServer);
  7.     return RETURN_SUCCESS;                                                                                                               
  8. }
復(fù)制代碼
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP