資源簡(jiǎn)介
olfile readme file.
[1. 文件名解釋]
olfile: Offload File
這個(gè)工具原本是項(xiàng)目中為測(cè)試TOE引擎的效率而設(shè)計(jì)的,
可以作為socket編程的一個(gè)例子來學(xué)習(xí)。
[2. 文件介紹]
程序中使用socket實(shí)現(xiàn)了文件的傳輸。
在VC6.0中編譯通過,目錄中olfile.cpp/olfile.h是原文件,可以任意修改,不過請(qǐng)不要改動(dòng)文件頭的作者信息。
有兩個(gè)目錄:server、client,其實(shí)編譯出來的東西是一樣的,當(dāng)時(shí)是為了測(cè)試方便才分出來的。
可以直接打開client目錄中的工程來編譯。
[3. 使用介紹]
程序分client端和server端,server 端監(jiān)聽,client端使用命令行方式發(fā)送或接收文件。
在VC6.0中編譯生成olfile.exe,使用不同的選項(xiàng)啟動(dòng)client和server。
比如,我們有兩臺(tái)機(jī)器10.190.1.1(A), 10.190.1.2(B),加入都運(yùn)行windows,想把A的c:foo.dat傳到B,并放在B的c:foodst.dat,
則需要在B啟動(dòng)server:
olfile -server
A啟動(dòng)client進(jìn)行傳輸:
o
lfile -src c:foo.dat -dst c:foodst.dat -ip 10.190.1.2 -y
-src 表示源文件的位置
-dst 表示目標(biāo)文件的位置
-ip 表示遠(yuǎn)程主機(jī)的IP。
-y 表示如果遠(yuǎn)程主機(jī)上的目標(biāo)文件位置原來有文件,則強(qiáng)制覆蓋。
可以看出,可以讓A當(dāng)作Server,B當(dāng)作Client,使用不同的命令行實(shí)現(xiàn)上面的文件傳遞:
A啟動(dòng)server:
olfile -server
B啟動(dòng)client 進(jìn)行文件傳輸,這時(shí)B的c:foodst.dat是目標(biāo):
olfile -dst c:foodst.dat -src c:foo.dat -ip 10.190.1.1 -y
[4.兼容性]
附帶的Makefile文件表明,代碼可以在Linux下正常編譯。所以,可以運(yùn)行在Linux下,實(shí)現(xiàn)Linux與Windows文件的互傳。
可能的命令行會(huì)變成:
olfile -dst /home/foodst.dat -src c:foo.dat -ip 10.190.1.1 -y
[5. 局限和可能存在的問題]
1.程序不會(huì)對(duì)你所使用的系統(tǒng)產(chǎn)生致命影響,因?yàn)樗鼉H僅是一個(gè)socket 實(shí)例。
2.server 在進(jìn)行一次文件傳輸之后就退出,因?yàn)槌绦蚴菃我痪€程的。
3.可以利用程序的打印輸出看一下大概的傳輸速度(因?yàn)檫@時(shí)我當(dāng)時(shí)在項(xiàng)目中寫這個(gè)工具的原因)。
[1. 文件名解釋]
olfile: Offload File
這個(gè)工具原本是項(xiàng)目中為測(cè)試TOE引擎的效率而設(shè)計(jì)的,
可以作為socket編程的一個(gè)例子來學(xué)習(xí)。
[2. 文件介紹]
程序中使用socket實(shí)現(xiàn)了文件的傳輸。
在VC6.0中編譯通過,目錄中olfile.cpp/olfile.h是原文件,可以任意修改,不過請(qǐng)不要改動(dòng)文件頭的作者信息。
有兩個(gè)目錄:server、client,其實(shí)編譯出來的東西是一樣的,當(dāng)時(shí)是為了測(cè)試方便才分出來的。
可以直接打開client目錄中的工程來編譯。
[3. 使用介紹]
程序分client端和server端,server 端監(jiān)聽,client端使用命令行方式發(fā)送或接收文件。
在VC6.0中編譯生成olfile.exe,使用不同的選項(xiàng)啟動(dòng)client和server。
比如,我們有兩臺(tái)機(jī)器10.190.1.1(A), 10.190.1.2(B),加入都運(yùn)行windows,想把A的c:foo.dat傳到B,并放在B的c:foodst.dat,
則需要在B啟動(dòng)server:
olfile -server
A啟動(dòng)client進(jìn)行傳輸:
o
lfile -src c:foo.dat -dst c:foodst.dat -ip 10.190.1.2 -y
-src 表示源文件的位置
-dst 表示目標(biāo)文件的位置
-ip 表示遠(yuǎn)程主機(jī)的IP。
-y 表示如果遠(yuǎn)程主機(jī)上的目標(biāo)文件位置原來有文件,則強(qiáng)制覆蓋。
可以看出,可以讓A當(dāng)作Server,B當(dāng)作Client,使用不同的命令行實(shí)現(xiàn)上面的文件傳遞:
A啟動(dòng)server:
olfile -server
B啟動(dòng)client 進(jìn)行文件傳輸,這時(shí)B的c:foodst.dat是目標(biāo):
olfile -dst c:foodst.dat -src c:foo.dat -ip 10.190.1.1 -y
[4.兼容性]
附帶的Makefile文件表明,代碼可以在Linux下正常編譯。所以,可以運(yùn)行在Linux下,實(shí)現(xiàn)Linux與Windows文件的互傳。
可能的命令行會(huì)變成:
olfile -dst /home/foodst.dat -src c:foo.dat -ip 10.190.1.1 -y
[5. 局限和可能存在的問題]
1.程序不會(huì)對(duì)你所使用的系統(tǒng)產(chǎn)生致命影響,因?yàn)樗鼉H僅是一個(gè)socket 實(shí)例。
2.server 在進(jìn)行一次文件傳輸之后就退出,因?yàn)槌绦蚴菃我痪€程的。
3.可以利用程序的打印輸出看一下大概的傳輸速度(因?yàn)檫@時(shí)我當(dāng)時(shí)在項(xiàng)目中寫這個(gè)工具的原因)。
代碼片段和文件信息
??????????????????????????????????
/**
Offload?file?transfer?module?using?socket?to?test?TCP?offload?engine(TOE).
By?Vino?@?9th?June?2004.
Email:?rtc@eyou.com
All?copyrights?reserved.
*/
#include?
#include?
#include?
#include?
#include?
#include?
#ifdef?WIN32
#include?
#include?
#else
#include?
#include?
#include?
#include?
#include?
#endif
#include?
#include?“olfile.h“
const?char?str_usg[]?=?
“\nTransfer?a?file?from?data?source?to?data?sink?through?network.\n\n“
“??olfile?-src?sourcefile?-snk?sinkfile?-ip?dotip?[-y]\n“
“?????Copy?sourcefile?on?local?to?sinkfile?on?ip?dotip.\n\n“
“??olfile?-snk?sinkfile?-src?sourcefile?-ip?dotip?[-y]\n“
“?????Copy?sourcefile?on?ip?dotip?to?sinkfile?on?local.\n\n“
“??olfile?-server\n“
“?????Start?olfile?service.\n\n“
“Options:\n“
“????-src?+?sourcefile??????Data?source?file?full?path\n“
“????-snk?+?sinkfile????????Data?sink?file?full?path\n“
“????-ip??+?dotip???????????Dot?divided?ip?address\n“
“????-y?????????????????????Default?to?delete?exists?file.\n\n“
“Example:\n“
“?????-snk?f:/data.txt?-src?f:/datarcv.txt?-ip?10.190.5.179?-y\n\n“
“By?Vino.Cui?@?9th?June?2004?from?Inventec.\n“
“Revision:\n“
“1.?13th?June?2004?Completed?the?original?version:?Transfering?file?\nfrom?data?source?to?data?sink?via?ip?specified?by?-ip?argument.?\n“;
const?size_t?OP_HEAD_SIZE?=?sizeof(struct?st_op_head);
struct?st_reg_sem?s_reg_sem;
/**?these?4?buffer?pools?are?dynamic?allocated?in?the?program.
??file?->?read-File?Buffer?Pool?->?send-NIC?Buffer?Pool?->?NIC
??file?<-?write-File?Buffer?Pool?<-?receive-NIC?Buffer?Pool?<-?NIC
but?this?implementation?needs?buffer?copy(copy?read-file?Buffer?to?send-NIC?Buffer?pool?and?back-forth).
??char?*rdFileBufPool?*wrFileBufPool;
??char?*sendNicBufPool?*recvNicBufPool;
*/
char?*lanin_buf?*lanout_buf;
char?*gfin_buf?*gfout_buf;
float?ftop_spd?=?0.0;?//?top?speed?bytes/s
/***/
int
init_socket()
{
#ifdef?WIN32
WSADATA?wsaData;
int?iResult?=?WSAStartup(MAKEWORD(22)?&wsaData);
if?(iResult?!=?NO_ERROR)
{
printf(“Error?at?WSAStartup()\n“);
return?-1;
}
return?0;
#else
return?0;
#endif
}
int
create_conn(){
SOCKET?s;
struct?sockaddr_in?local;
BOOL?bOptVal?=?TRUE;
int?bOptLen?=?sizeof(BOOL);
int?iOptLen?=?sizeof(int);
if((s?=?socket(AF_INET_NORMAL?SOCK_STREAM?0))?==?-1){
perror(“socket“);
return?-1;
}
int?a=?setsockopt(s?SOL_SOCKET?SO_REUSEADDR?(char*)&bOptVal?bOptLen);
memset(&(local)?0?sizeof(struct?sockaddr_in));
local.sin_family?=?AF_INET;??????/*?host?byte?order?*/
local.sin_port?=?htons(SERVER_PORT);
local.sin_addr.s_addr?=?INADDR_ANY;
if?(?-1?==?bind(s?(struct?sockaddr*)&local?sizeof(struct?sockaddr))?)
{
fprintf(stderr?“bind?error\n“);
show_err();
return?(-1);
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄??????????0??2004-06-25?12:08??client
?????文件??????58368??2004-07-07?13:13??client\olfile.ncb
?????文件???????1270??2004-07-07?13:13??client\olfile.plg
?????文件???????4425??2004-06-13?16:10??client\olfile.dsp
?????文件??????54784??2004-06-17?14:10??client\olfile.opt
?????文件????????535??2004-07-07?13:12??client\olfile.dsw
?????目錄??????????0??2004-06-25?12:07??server
?????文件????????537??2004-06-10?11:42??server\olfiled.dsw
?????文件??????58368??2004-06-17?13:43??server\olfiled.ncb
?????文件???????1300??2004-06-17?13:31??server\olfiled.plg
?????文件???????4436??2004-06-13?16:10??server\olfiled.dsp
?????文件??????54784??2004-06-17?13:43??server\olfiled.opt
?????文件????????727??2004-06-25?11:08??Makefile
?????文件??????31205??2004-07-07?13:14??olfile.cpp
?????文件???????4116??2004-07-07?13:14??olfile.h
?????文件???????1725??2004-07-07?13:31??readme.txt
?????文件???????3189??2004-04-19?10:52??代碼中國.txt
?????文件????????126??2004-04-03?17:45??代碼中國.url
?????文件???????3930??2003-11-05?18:50??說明.htm
-----------?---------??----------?-----??----
???????????????283825????????????????????19
評(píng)論
共有 條評(píng)論