2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Copyright (C) 2012 Samsung Electronics Ltd. All Rights Reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include "SocketStreamHandle.h"
39 #include "SessionID.h"
40 #include <wtf/RefCounted.h>
41 #include <wtf/StreamBuffer.h>
42 #include <wtf/glib/GRefPtr.h>
46 class SocketStreamError;
47 class SocketStreamHandleClient;
49 class SocketStreamHandleImpl final : public SocketStreamHandle {
51 static Ref<SocketStreamHandleImpl> create(const URL&, SocketStreamHandleClient&, SessionID, const String&);
52 static Ref<SocketStreamHandle> create(GSocketConnection*, SocketStreamHandleClient&, SourceApplicationAuditToken&&);
54 virtual ~SocketStreamHandleImpl();
56 void platformSend(const char* data, size_t length, Function<void(bool)>&&) final;
57 void platformClose() final;
59 SocketStreamHandleImpl(const URL&, SocketStreamHandleClient&);
61 size_t bufferedAmount() final;
62 std::optional<size_t> platformSendInternal(const char*, size_t);
63 bool sendPendingData();
65 void beginWaitingForSocketWritability();
66 void stopWaitingForSocketWritability();
68 static void connectedCallback(GSocketClient*, GAsyncResult*, SocketStreamHandleImpl*);
69 static void readReadyCallback(GInputStream*, GAsyncResult*, SocketStreamHandleImpl*);
70 static gboolean writeReadyCallback(GPollableOutputStream*, SocketStreamHandleImpl*);
72 void connected(GRefPtr<GSocketConnection>&&);
73 void readBytes(gssize);
74 void didFail(SocketStreamError&&);
77 GRefPtr<GSocketConnection> m_socketConnection;
78 GRefPtr<GInputStream> m_inputStream;
79 GRefPtr<GPollableOutputStream> m_outputStream;
80 GRefPtr<GSource> m_writeReadySource;
81 GRefPtr<GCancellable> m_cancellable;
82 std::unique_ptr<char[]> m_readBuffer;
84 StreamBuffer<char, 1024 * 1024> m_buffer;
85 static const unsigned maxBufferSize = 100 * 1024 * 1024;
88 } // namespace WebCore