* Committing new wxSocket core (socket.cpp sckint.cpp). It has to be improved ...

* Adding sckint.cpp to various makefiles.
* Fixes in threadpsx.cpp (Pause/Resume)
* Fixes in threaded event dispatching
* Added Clone() to wxObject
* Implemented Clone() in wxEvent and wxSocketEvent
* wxSocket sample save the data got from the URL in test.url (this will change)
* As I only tested wxSocket on Linux Redhat 5.2 I disabled it by default on
  Windows, Mac and Unix platforms.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2289 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Guilhem Lavaux
1999-04-26 18:16:56 +00:00
parent 6a3ab8b15a
commit a737331db6
26 changed files with 1013 additions and 1190 deletions

View File

@@ -23,6 +23,7 @@
#include "wx/wx.h"
#endif
#include "wx/wfstream.h"
#include "wx/socket.h"
#include "wx/url.h"
#include "wx/protocol/http.h"
@@ -204,12 +205,12 @@ void MyFrame::UpdateStatus()
SetStatusText("", 1);
} else {
wxIPV4address addr;
char s[100];
wxChar s[100];
sock->GetPeer(addr);
sprintf(s, "Connected to %s", (const char *)addr.Hostname());
wxSprintf(s, _T("Connected to %s"), WXSTRINGCAST addr.Hostname());
SetStatusText(s, 0);
sprintf(s, "Service: %d", addr.Service());
wxSprintf(s, _T("Service: %d"), addr.Service());
SetStatusText(s, 1);
}
}
@@ -225,7 +226,7 @@ void MyFrame::OnExecTest1(wxCommandEvent& WXUNUSED(evt))
wxTE_MULTILINE);
(void)new wxButton(dlgbox, ID_TEST_CLOSE, "Close",
wxPoint(100, 210), wxSize(100, -1));
char *buf, *buf2;
wxChar *buf, *buf2;
dlgbox->Layout();
dlgbox->Show(TRUE);
@@ -235,21 +236,25 @@ void MyFrame::OnExecTest1(wxCommandEvent& WXUNUSED(evt))
wxYield();
/* Init */
buf = copystring("Hi ! Hi ! Hi !\n");
buf2 = new char[strlen(buf)+1];
buf = copystring(_T("Hi ! Hi ! Hi !\n"));
buf2 = new wxChar[wxStrlen(buf)+1];
char c = 0xbe;
sock->WriteMsg(&c, 1);
sock->Write(&c, 1);
/* No 1 */
text_win->WriteText("Sending some byte to the server ...");
sock->Write(buf, strlen(buf)+1);
wxYield();
sock->Write((char *)buf, wxStrlen(buf)+1);
text_win->WriteText("done\n");
wxYield();
text_win->WriteText("Receiving some byte from the server ...");
sock->Read(buf2, strlen(buf)+1);
wxYield();
sock->Read((char *)buf2, wxStrlen(buf)+1);
text_win->WriteText("done\n");
wxYield();
text_win->WriteText("Comparing the two buffers ...");
if (memcmp(buf, buf2, strlen(buf)+1) != 0) {
if (memcmp(buf, buf2, wxStrlen(buf)+1) != 0) {
text_win->WriteText("Fail\n");
sock->Close();
UpdateStatus();
@@ -276,7 +281,11 @@ void MyFrame::OnExecUrlTest(wxCommandEvent& WXUNUSED(evt))
if (!datas)
wxMessageBox("Error in getting data from the URL.", "Alert !");
else {
wxFileOutputStream *str_out = new wxFileOutputStream("test.url");
str_out->Write(*datas);
wxMessageBox("Success !! Click on OK to see the text.", "OK");
delete datas;
delete str_out;
}
}

View File

@@ -42,37 +42,28 @@ class MyFrame: public wxFrame
{
DECLARE_EVENT_TABLE()
public:
MyServer *sock;
wxSocketServer *sock;
int nb_clients;
MyFrame(wxFrame *frame);
virtual ~MyFrame();
void Menu_Exit(wxCommandEvent& evt);
void OnSockRequest(wxSocketEvent& evt);
void OnSockRequestServer(wxSocketEvent& evt);
void ExecTest1(wxSocketBase *sock_o);
void UpdateStatus(int incr);
};
#define SKDEMO_QUIT 101
#define SKDEMO_SOCKET_SERV 102
#define SKDEMO_SOCKET 103
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(SKDEMO_QUIT, MyFrame::Menu_Exit)
EVT_SOCKET(SKDEMO_SOCKET_SERV, MyFrame::OnSockRequestServer)
EVT_SOCKET(SKDEMO_SOCKET, MyFrame::OnSockRequest)
END_EVENT_TABLE()
class MySock: public wxSocketBase {
public:
MyFrame *frame;
void OldOnNotify(wxRequestEvent flags);
};
class MyServer: public wxSocketServer {
public:
MyFrame *frame;
MyServer(wxSockAddress& addr) : wxSocketServer(addr) { }
void OldOnNotify(wxRequestEvent flags);
};
IMPLEMENT_APP(MyApp)
// `Main program' equivalent, creating windows and returning main app frame
@@ -102,40 +93,50 @@ bool MyApp::OnInit(void)
return TRUE;
}
void MySock::OldOnNotify(wxRequestEvent flags)
{
extern wxList WXDLLEXPORT wxPendingDelete;
extern wxList wxPendingDelete;
switch (flags) {
case EVT_READ:
void MyFrame::OnSockRequest(wxSocketEvent& evt)
{
wxSocketBase *sock = evt.Socket();
printf("OnSockRequest OK\n");
printf("OnSockRequest (event = %d)\n",evt.SocketEvent());
switch (evt.SocketEvent()) {
case wxSocketBase::EVT_READ:
unsigned char c;
ReadMsg((char *)&c, 1);
sock->Read((char *)&c, 1);
if (c == 0xbe)
frame->ExecTest1(this);
ExecTest1(sock);
break;
case EVT_LOST:
frame->UpdateStatus(-1);
wxPendingDelete.Append(this);
case wxSocketBase::EVT_LOST:
UpdateStatus(-1);
printf("Destroying socket\n");
wxPendingDelete.Append(sock);
return;
break;
}
printf("OnSockRequest Exiting\n");
sock->SetNotify(wxSocketBase::REQ_READ | wxSocketBase::REQ_LOST);
}
void MyServer::OldOnNotify(wxRequestEvent WXUNUSED(flags))
void MyFrame::OnSockRequestServer(wxSocketEvent& evt)
{
MySock *sock2 = new MySock();
wxSocketBase *sock2;
wxSocketServer *server = (wxSocketServer *) evt.Socket();
if (!AcceptWith(*sock2))
printf("OnSockRequestServer OK\n");
sock2 = server->Accept();
if (sock2 == NULL)
return;
m_handler->Register(sock2);
sock2->SetFlags(NONE);
sock2->frame = frame;
sock2->SetNotify(REQ_READ | REQ_LOST);
sock2->SetFlags(wxSocketBase::NONE);
sock2->Notify(TRUE);
frame->UpdateStatus(1);
sock2->SetEventHandler(*this, SKDEMO_SOCKET);
server->SetNotify(wxSocketBase::REQ_ACCEPT);
UpdateStatus(1);
}
// My frame Constructor
@@ -149,10 +150,10 @@ MyFrame::MyFrame(wxFrame *frame):
// Init all
wxSocketHandler::Master();
sock = new MyServer(addr);
sock = new wxSocketServer(addr);
wxSocketHandler::Master().Register(sock);
sock->frame = this;
sock->SetNotify(wxSocketBase::REQ_ACCEPT);
sock->SetEventHandler(*this, SKDEMO_SOCKET_SERV);
sock->Notify(TRUE);
nb_clients = 0;