Twitch SDK (Internal)
winappsocket.h
Go to the documentation of this file.
1 /********************************************************************************************
2 * Twitch Broadcasting SDK
3 *
4 * This software is supplied under the terms of a license agreement with Twitch Interactive, Inc. and
5 * may not be copied or used except in accordance with the terms of that agreement
6 * Copyright (c) 2012-2016 Twitch Interactive, Inc.
7 *********************************************************************************************/
8 
9 #pragma once
10 
13 #include "twitchsdk/core/socket.h"
14 
15 #include <wrl.h>
16 #include <Windows.Networking.Sockets.h>
17 #include <array>
18 
19 
20 namespace ttv
21 {
22  class WinAppSocket;
23  class WinAppSocketFactory;
24 }
25 
26 
27 class ttv::WinAppSocket : public ISocket
28 {
29 public:
30  WinAppSocket();
31  virtual ~WinAppSocket();
32 
33  TTV_ErrorCode Initialize(const std::string& host, const std::string& port);
34 
35  // ISocket implementation
36  virtual TTV_ErrorCode Connect();
37  virtual TTV_ErrorCode Disconnect();
38  virtual TTV_ErrorCode Send(const uint8_t* buffer, size_t length);
39  virtual TTV_ErrorCode Recv(uint8_t* buffer, size_t length, size_t& received);
40  virtual uint64_t TotalSent() const;
41  virtual uint64_t TotalReceived() const;
42 
43  virtual bool Connected();
44 
45 private:
46  HRESULT ReadAndResetInputBuffer(uint8_t* buffer, size_t length, UINT32& readLength);
47 
48  std::string mHostName;
49  std::string mPort;
51  uint64_t mTotalSent;
52  uint64_t mTotalRecieved;
53 
54  Microsoft::WRL::ComPtr<ABI::Windows::Networking::Sockets::IStreamSocket> mSocket;
55  Microsoft::WRL::ComPtr<ABI::Windows::Storage::Streams::IBufferFactory> mBufferFactory;
56  Microsoft::WRL::ComPtr<ABI::Windows::Storage::Streams::IBuffer> mInputBuffer;
57  Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncOperationWithProgress<ABI::Windows::Storage::Streams::IBuffer*, UINT32>> mAsyncReadOp;
59 };
60 
61 
63 {
64 public:
65  virtual ~WinAppSocketFactory();
66  virtual bool IsProtocolSupported(const std::string& protocol);
67  virtual TTV_ErrorCode CreateSocket(const std::string& uri, std::shared_ptr<ISocket>& result);
68 };
Microsoft::WRL::ComPtr< ABI::Windows::Foundation::IAsyncOperationWithProgress< ABI::Windows::Storage::Streams::IBuffer *, UINT32 > > mAsyncReadOp
Definition: winappsocket.h:57
TTV_ErrorCode CreateSocket(const std::string &uri, std::shared_ptr< ISocket > &result)
virtual ~WinAppSocket()
bool mAsyncReadInProgress
Definition: winappsocket.h:58
virtual TTV_ErrorCode Disconnect()
HRESULT ReadAndResetInputBuffer(uint8_t *buffer, size_t length, UINT32 &readLength)
virtual bool Connected()
virtual TTV_ErrorCode Connect()
std::string mHostName
Definition: winappsocket.h:48
JSON (JavaScript Object Notation).
Definition: adsapi.h:16
virtual TTV_ErrorCode Recv(uint8_t *buffer, size_t length, size_t &received)
uint64_t mTotalRecieved
Definition: winappsocket.h:52
uint64_t mTotalSent
Definition: winappsocket.h:51
Microsoft::WRL::ComPtr< ABI::Windows::Storage::Streams::IBuffer > mInputBuffer
Definition: winappsocket.h:56
Microsoft::WRL::ComPtr< ABI::Windows::Networking::Sockets::IStreamSocket > mSocket
Definition: winappsocket.h:54
uint32_t TTV_ErrorCode
Definition: errortypes.h:30
TTV_ErrorCode Initialize(const std::string &host, const std::string &port)
Definition: socket.h:181
virtual uint64_t TotalReceived() const
Definition: socket.h:405
virtual uint64_t TotalSent() const
Definition: winappsocket.h:27
Definition: winappsocket.h:62
Microsoft::WRL::ComPtr< ABI::Windows::Storage::Streams::IBufferFactory > mBufferFactory
Definition: winappsocket.h:55
std::string mPort
Definition: winappsocket.h:49
virtual TTV_ErrorCode Send(const uint8_t *buffer, size_t length)
int mLastSocketError
Definition: winappsocket.h:50