platformNetAsync.h
Engine/source/platform/platformNetAsync.h
Classes:
class
Detailed Description
Public Variables
NetAsync gNetAsync
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef PLATFORM_NET_ASYNC_H 25#define PLATFORM_NET_ASYNC_H 26 27#include "platform/platform.h" 28#include "platform/platformNet.h" 29#include "core/util/tVector.h" 30 31// class for doing asynchronous network operations on unix (linux and 32// hopefully osx) platforms. right now it only implements dns lookups 33class NetAsync 34{ 35 private: 36 struct NameLookupRequest; 37 struct NameLookupWorkItem; 38 39 typedef Vector< NameLookupRequest> RequestVector; 40 typedef RequestVector::iterator RequestIterator; 41 42 RequestVector mLookupRequests; 43 44 public: 45 NetAsync(); 46 47 // queue a DNS lookup. only one dns lookup can be queued per socket at 48 // a time. subsequent queue request for the socket are ignored. use 49 // checkLookup() to check the status of a request. 50 void queueLookup(const char* remoteAddr, NetSocket socket); 51 52 // check on the status of a dns lookup for a socket. if the lookup is 53 // not yet complete, the function will return false. if it is 54 // complete, the function will return true, and out_h_addr and 55 // out_h_length will be set appropriately. if out_h_length is -1, then 56 // name could not be resolved. otherwise, it provides the number of 57 // address bytes copied into out_h_addr. 58 bool checkLookup(NetSocket socket, void* out_h_addr, int* out_h_length, S32 out_h_addr_size); 59}; 60 61// the global net async object 62extern NetAsync gNetAsync; 63 64#endif 65