group_common.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * SRT - Secure, Reliable, Transport
  3. * Copyright (c) 2021 Haivision Systems Inc.
  4. *
  5. * This Source Code Form is subject to the terms of the Mozilla Public
  6. * License, v. 2.0. If a copy of the MPL was not distributed with this
  7. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  8. *
  9. */
  10. /*****************************************************************************
  11. Written by
  12. Haivision Systems Inc.
  13. *****************************************************************************/
  14. #include "platform_sys.h"
  15. #include "group_common.h"
  16. #include "api.h"
  17. namespace srt
  18. {
  19. namespace groups
  20. {
  21. SocketData prepareSocketData(CUDTSocket* s)
  22. {
  23. // This uses default SRT_GST_BROKEN because when the group operation is done,
  24. // then the SRT_GST_IDLE state automatically turns into SRT_GST_RUNNING. This is
  25. // recognized as an initial state of the fresh added socket to the group,
  26. // so some "initial configuration" must be done on it, after which it's
  27. // turned into SRT_GST_RUNNING, that is, it's treated as all others. When
  28. // set to SRT_GST_BROKEN, this socket is disregarded. This socket isn't cleaned
  29. // up, however, unless the status is simultaneously SRTS_BROKEN.
  30. // The order of operations is then:
  31. // - add the socket to the group in this "broken" initial state
  32. // - connect the socket (or get it extracted from accept)
  33. // - update the socket state (should be SRTS_CONNECTED)
  34. // - once the connection is established (may take time with connect), set SRT_GST_IDLE
  35. // - the next operation of send/recv will automatically turn it into SRT_GST_RUNNING
  36. SocketData sd = {
  37. s->m_SocketID,
  38. s,
  39. -1,
  40. SRTS_INIT,
  41. SRT_GST_BROKEN,
  42. SRT_GST_BROKEN,
  43. -1,
  44. -1,
  45. sockaddr_any(),
  46. sockaddr_any(),
  47. false,
  48. false,
  49. false,
  50. 0, // weight
  51. 0 // pktSndDropTotal
  52. };
  53. return sd;
  54. }
  55. } // namespace groups
  56. } // namespace srt