亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区
Chinaunix
標(biāo)題:
求5.01版本tracker_get_connection_r的正確用法。
[打印本頁]
作者:
toniz
時(shí)間:
2014-06-04 18:48
標(biāo)題:
求5.01版本tracker_get_connection_r的正確用法。
conn = tracker_get_connection_r(&TrackerServer, &result);
這個(gè)TrackerServer 和 conn 是啥關(guān)系, 關(guān)閉的時(shí)候要如何才能正確關(guān)閉連接。
作者:
toniz
時(shí)間:
2014-06-05 11:33
本帖最后由 toniz 于 2014-06-05 11:35 編輯
這個(gè)問題已經(jīng)決解。
我為了重用,把connect和disconnect部分單獨(dú)拆成一個(gè)方法。
但其實(shí)TrackerServer不能在方法里面定義,要在使用的地方定義,作為參數(shù)帶進(jìn)去才行。
不然調(diào)用close后,這個(gè)鏈接會(huì)一直存在(實(shí)際上沒有close這個(gè)socket)。
如果連接數(shù)滿了之后,服務(wù)端會(huì)發(fā)起fin,這個(gè)時(shí)候會(huì)造成客戶端大量close_wait.
正確代碼如下:
ConnectionInfo* FdfsClient::connectFastDFS(ConnectionInfo &trackerServer,
ConnectionInfo &storageServer,
int &store_path_index, char group_name[])
{
int result;
ConnectionInfo *conn;
conn = tracker_get_connection_r(&trackerServer, &result);
if ( result != 0 )
{
MYLOG_WARN(logger, "tracker_get_connection fail, error no: %d, error info: %s\n", errno , STRERROR(errno));
return NULL;
}
*group_name = '\0';
store_path_index = 0;
result = 0;
if ((result=tracker_query_storage_store(conn, &storageServer, group_name, &store_path_index)) != 0)
{
fdfs_quit(conn);
tracker_disconnect_server(conn);
MYLOG_WARN(logger, "tracker_query_storage fail, error no: %d, error info: %s\n", result, STRERROR(result));
return NULL;
}
return conn;
}
復(fù)制代碼
錯(cuò)誤代碼如下:
ConnectionInfo* FdfsClient::connectFastDFS(ConnectionInfo &storageServer, int &store_path_index, char group_name[])
{
int result;
ConnectionInfo TrackerServer;
ConnectionInfo *conn;
conn = tracker_get_connection_r(&TrackerServer, &result);
if ( result != 0 )
{
MYLOG_WARN(logger, "tracker_get_connection fail, error no: %d, error info: %s\n", errno , STRERROR(errno));
return NULL;
}
*group_name = '\0';
store_path_index = 0;
result = 0;
if ((result=tracker_query_storage_store(conn, &storageServer, group_name, &store_path_index)) != 0)
{
fdfs_quit(conn);
tracker_disconnect_server(conn);
MYLOG_WARN(logger, "tracker_query_storage fail, error no: %d, error info: %s\n", result, STRERROR(result));
return NULL;
}
return conn;
}
復(fù)制代碼
調(diào)用的代碼如下:
int FdfsClient::uploadAppenderByBuff(const char *file_content, int content_len, const char *file_ext_name, char file_id[])
{
int store_path_index;
ConnectionInfo trackerServer;
ConnectionInfo storageServer;
char group_name[FDFS_GROUP_NAME_MAX_LEN + 1];
int result;
ConnectionInfo *pTrackerServer;
pTrackerServer = connectFastDFS(trackerServer, storageServer, store_path_index, group_name);
if( pTrackerServer == NULL )
{
return RETURN_GET_CONNECTION_FAIL;
}
result = storage_upload_appender_by_filebuff1(pTrackerServer, &storageServer, store_path_index, \
file_content, content_len, file_ext_name, NULL, 0, group_name, file_id);
if (result != 0)
{
MYLOG_WARN(logger, "upload file fail, error no: %d, error info: %s\n", result, STRERROR(result));
disConnectFastDFS(pTrackerServer, storageServer);
return RETURN_UPLOAD_APPENDER_FAIL;
}
disConnectFastDFS(pTrackerServer, storageServer);
return RETURN_SUCCESS;
}
復(fù)制代碼
disconnect代碼如下:
int FdfsClient::disConnectFastDFS(ConnectionInfo *pTrackerServer, ConnectionInfo &storageServer)
{
fdfs_quit(&storageServer);
tracker_disconnect_server(&storageServer);
fdfs_quit(pTrackerServer);
tracker_disconnect_server(pTrackerServer);
return RETURN_SUCCESS;
}
復(fù)制代碼
歡迎光臨 Chinaunix (http://www.72891.cn/)
Powered by Discuz! X3.2