win32_socket_init.h 1022 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Copyright 2009 The WebRTC Project Authors. All rights reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef RTC_BASE_WIN32_SOCKET_INIT_H_
  11. #define RTC_BASE_WIN32_SOCKET_INIT_H_
  12. #ifndef WEBRTC_WIN
  13. #error "Only #include this header in Windows builds"
  14. #endif
  15. #include "rtc_base/win32.h"
  16. namespace rtc {
  17. class WinsockInitializer {
  18. public:
  19. WinsockInitializer() {
  20. WSADATA wsaData;
  21. WORD wVersionRequested = MAKEWORD(1, 0);
  22. err_ = WSAStartup(wVersionRequested, &wsaData);
  23. }
  24. ~WinsockInitializer() {
  25. if (!err_)
  26. WSACleanup();
  27. }
  28. int error() { return err_; }
  29. private:
  30. int err_;
  31. };
  32. } // namespace rtc
  33. #endif // RTC_BASE_WIN32_SOCKET_INIT_H_