s2n_io.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License").
  5. * You may not use this file except in compliance with the License.
  6. * A copy of the License is located at
  7. *
  8. * http://aws.amazon.com/apache2.0
  9. *
  10. * or in the "license" file accompanying this file. This file is distributed
  11. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  12. * express or implied. See the License for the specific language governing
  13. * permissions and limitations under the License.
  14. */
  15. #include "utils/s2n_io.h"
  16. #include <errno.h>
  17. #include "utils/s2n_safety.h"
  18. S2N_RESULT s2n_io_check_write_result(ssize_t result)
  19. {
  20. if (result < 0) {
  21. if (errno == EWOULDBLOCK || errno == EAGAIN) {
  22. RESULT_BAIL(S2N_ERR_IO_BLOCKED);
  23. }
  24. RESULT_BAIL(S2N_ERR_IO);
  25. }
  26. return S2N_RESULT_OK;
  27. }
  28. S2N_RESULT s2n_io_check_read_result(ssize_t result)
  29. {
  30. RESULT_GUARD(s2n_io_check_write_result(result));
  31. if (result == 0) {
  32. RESULT_BAIL(S2N_ERR_CLOSED);
  33. }
  34. return S2N_RESULT_OK;
  35. }