Commit 5572386b authored by kov@webkit.org's avatar kov@webkit.org

2011-01-31 Dan Winship <danw@gnome.org>

        Reviewed by Gustavo Noronha Silva.

        wss (websockets ssl) support for gtk via new gio TLS support
        https://bugs.webkit.org/show_bug.cgi?id=50344

        Add a GPollableOutputStream typedef for TLS WebSockets support

        * wtf/gobject/GTypedefs.h:
2011-01-31  Dan Winship  <danw@gnome.org>

        Reviewed by Gustavo Noronha Silva.

        wss (websockets ssl) support for gtk via new gio TLS support
        https://bugs.webkit.org/show_bug.cgi?id=50344

        Update to use GPollableOutputStream and GTlsConnection to
        implement wss URLs

        * platform/network/soup/SocketStreamHandle.h:
        * platform/network/soup/SocketStreamHandleSoup.cpp:
        (WebCore::SocketStreamHandle::SocketStreamHandle):
        (WebCore::SocketStreamHandle::connected):
        (WebCore::SocketStreamHandle::platformSend):
        (WebCore::SocketStreamHandle::beginWaitingForSocketWritability):
        (WebCore::writeReadyCallback):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@77148 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 0288fb61
2011-01-31 Dan Winship <danw@gnome.org>
Reviewed by Gustavo Noronha Silva.
wss (websockets ssl) support for gtk via new gio TLS support
https://bugs.webkit.org/show_bug.cgi?id=50344
Add a GPollableOutputStream typedef for TLS WebSockets support
* wtf/gobject/GTypedefs.h:
2011-01-31 Gavin Barraclough <barraclough@apple.com> 2011-01-31 Gavin Barraclough <barraclough@apple.com>
Reviewed by Geoff Garen. Reviewed by Geoff Garen.
......
...@@ -53,8 +53,8 @@ typedef struct _GHashTable GHashTable; ...@@ -53,8 +53,8 @@ typedef struct _GHashTable GHashTable;
typedef struct _GInputStream GInputStream; typedef struct _GInputStream GInputStream;
typedef struct _GList GList; typedef struct _GList GList;
typedef struct _GMutex GMutex; typedef struct _GMutex GMutex;
typedef struct _GOutputStream GOutputStream;
typedef struct _GPatternSpec GPatternSpec; typedef struct _GPatternSpec GPatternSpec;
typedef struct _GPollableOutputStream GPollableOutputStream;
typedef struct _GSocketClient GSocketClient; typedef struct _GSocketClient GSocketClient;
typedef struct _GSocketConnection GSocketConnection; typedef struct _GSocketConnection GSocketConnection;
typedef struct _GSource GSource; typedef struct _GSource GSource;
......
2011-01-31 Dan Winship <danw@gnome.org>
Reviewed by Gustavo Noronha Silva.
wss (websockets ssl) support for gtk via new gio TLS support
https://bugs.webkit.org/show_bug.cgi?id=50344
Update to use GPollableOutputStream and GTlsConnection to
implement wss URLs
* platform/network/soup/SocketStreamHandle.h:
* platform/network/soup/SocketStreamHandleSoup.cpp:
(WebCore::SocketStreamHandle::SocketStreamHandle):
(WebCore::SocketStreamHandle::connected):
(WebCore::SocketStreamHandle::platformSend):
(WebCore::SocketStreamHandle::beginWaitingForSocketWritability):
(WebCore::writeReadyCallback):
2011-01-31 Abhishek Arya <inferno@chromium.org> 2011-01-31 Abhishek Arya <inferno@chromium.org>
Reviewed by Dimitri Glazkov. Reviewed by Dimitri Glazkov.
...@@ -60,7 +60,7 @@ namespace WebCore { ...@@ -60,7 +60,7 @@ namespace WebCore {
private: private:
GRefPtr<GSocketConnection> m_socketConnection; GRefPtr<GSocketConnection> m_socketConnection;
GRefPtr<GInputStream> m_inputStream; GRefPtr<GInputStream> m_inputStream;
GRefPtr<GOutputStream> m_outputStream; GRefPtr<GPollableOutputStream> m_outputStream;
GRefPtr<GSource> m_writeReadySource; GRefPtr<GSource> m_writeReadySource;
char* m_readBuffer; char* m_readBuffer;
void* m_id; void* m_id;
......
...@@ -50,7 +50,7 @@ namespace WebCore { ...@@ -50,7 +50,7 @@ namespace WebCore {
// These functions immediately call the similarly named SocketStreamHandle methods. // These functions immediately call the similarly named SocketStreamHandle methods.
static void connectedCallback(GSocketClient*, GAsyncResult*, void*); static void connectedCallback(GSocketClient*, GAsyncResult*, void*);
static void readReadyCallback(GInputStream*, GAsyncResult*, void*); static void readReadyCallback(GInputStream*, GAsyncResult*, void*);
static gboolean writeReadyCallback(GSocket*, GIOCondition, void*); static gboolean writeReadyCallback(GPollableOutputStream*, void*);
// Having a list of active handles means that we do not have to worry about WebCore // Having a list of active handles means that we do not have to worry about WebCore
// reference counting in GLib callbacks. Once the handle is off the active handles list // reference counting in GLib callbacks. Once the handle is off the active handles list
...@@ -82,13 +82,12 @@ SocketStreamHandle::SocketStreamHandle(const KURL& url, SocketStreamHandleClient ...@@ -82,13 +82,12 @@ SocketStreamHandle::SocketStreamHandle(const KURL& url, SocketStreamHandleClient
: SocketStreamHandleBase(url, client) : SocketStreamHandleBase(url, client)
, m_readBuffer(0) , m_readBuffer(0)
{ {
// No support for SSL sockets yet. unsigned int port = url.hasPort() ? url.port() : (url.protocolIs("wss") ? 443 : 80);
if (url.protocolIs("wss"))
return;
unsigned int port = url.hasPort() ? url.port() : 80;
m_id = activateHandle(this); m_id = activateHandle(this);
GRefPtr<GSocketClient> socketClient = adoptGRef(g_socket_client_new()); GRefPtr<GSocketClient> socketClient = adoptGRef(g_socket_client_new());
if (url.protocolIs("wss"))
g_socket_client_set_tls(socketClient.get(), TRUE);
g_socket_client_connect_to_host_async(socketClient.get(), url.host().utf8().data(), port, 0, g_socket_client_connect_to_host_async(socketClient.get(), url.host().utf8().data(), port, 0,
reinterpret_cast<GAsyncReadyCallback>(connectedCallback), m_id); reinterpret_cast<GAsyncReadyCallback>(connectedCallback), m_id);
} }
...@@ -108,7 +107,7 @@ void SocketStreamHandle::connected(GSocketConnection* socketConnection, GError* ...@@ -108,7 +107,7 @@ void SocketStreamHandle::connected(GSocketConnection* socketConnection, GError*
} }
m_socketConnection = adoptGRef(socketConnection); m_socketConnection = adoptGRef(socketConnection);
m_outputStream = g_io_stream_get_output_stream(G_IO_STREAM(m_socketConnection.get())); m_outputStream = G_POLLABLE_OUTPUT_STREAM(g_io_stream_get_output_stream(G_IO_STREAM(m_socketConnection.get())));
m_inputStream = g_io_stream_get_input_stream(G_IO_STREAM(m_socketConnection.get())); m_inputStream = g_io_stream_get_input_stream(G_IO_STREAM(m_socketConnection.get()));
m_readBuffer = new char[READ_BUFFER_SIZE]; m_readBuffer = new char[READ_BUFFER_SIZE];
...@@ -156,14 +155,14 @@ void SocketStreamHandle::writeReady() ...@@ -156,14 +155,14 @@ void SocketStreamHandle::writeReady()
int SocketStreamHandle::platformSend(const char* data, int length) int SocketStreamHandle::platformSend(const char* data, int length)
{ {
if (!g_socket_condition_check(g_socket_connection_get_socket(m_socketConnection.get()), G_IO_OUT)) { if (!g_pollable_output_stream_is_writable(m_outputStream.get())) {
beginWaitingForSocketWritability(); beginWaitingForSocketWritability();
return 0; return 0;
} }
GOwnPtr<GError> error; GOwnPtr<GError> error;
gssize written = g_output_stream_write(m_outputStream.get(), data, length, 0, &error.outPtr()); gssize written = g_pollable_output_stream_write_nonblocking(m_outputStream.get(), data, length, 0, &error.outPtr());
if (error) { if (error && !g_error_matches(error.get(), G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) {
m_client->didFail(this, SocketStreamError(error->code)); // FIXME: Provide a sensible error. m_client->didFail(this, SocketStreamError(error->code)); // FIXME: Provide a sensible error.
return 0; return 0;
} }
...@@ -222,8 +221,7 @@ void SocketStreamHandle::beginWaitingForSocketWritability() ...@@ -222,8 +221,7 @@ void SocketStreamHandle::beginWaitingForSocketWritability()
if (m_writeReadySource) // Already waiting. if (m_writeReadySource) // Already waiting.
return; return;
m_writeReadySource = adoptGRef(g_socket_create_source( m_writeReadySource = adoptGRef(g_pollable_output_stream_create_source(m_outputStream.get(), 0));
g_socket_connection_get_socket(m_socketConnection.get()), static_cast<GIOCondition>(G_IO_OUT), 0));
g_source_set_callback(m_writeReadySource.get(), reinterpret_cast<GSourceFunc>(writeReadyCallback), m_id, 0); g_source_set_callback(m_writeReadySource.get(), reinterpret_cast<GSourceFunc>(writeReadyCallback), m_id, 0);
g_source_attach(m_writeReadySource.get(), 0); g_source_attach(m_writeReadySource.get(), 0);
} }
...@@ -266,24 +264,13 @@ static void readReadyCallback(GInputStream* stream, GAsyncResult* result, void* ...@@ -266,24 +264,13 @@ static void readReadyCallback(GInputStream* stream, GAsyncResult* result, void*
handle->readBytes(bytesRead, error.get()); handle->readBytes(bytesRead, error.get());
} }
static gboolean writeReadyCallback(GSocket*, GIOCondition condition, void* id) static gboolean writeReadyCallback(GPollableOutputStream*, void* id)
{ {
SocketStreamHandle* handle = getHandleFromId(id); SocketStreamHandle* handle = getHandleFromId(id);
if (!handle) if (!handle)
return FALSE; return FALSE;
// G_IO_HUP and G_IO_ERR are are always active. See: handle->writeReady();
// http://library.gnome.org/devel/gio/stable/GSocket.html#g-socket-create-source
if (condition & G_IO_HUP) {
handle->close();
return FALSE;
}
if (condition & G_IO_ERR) {
handle->client()->didFail(handle, SocketStreamError(0)); // FIXME: Provide a sensible error.
return FALSE;
}
if (condition & G_IO_OUT)
handle->writeReady();
return TRUE; return TRUE;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment