Changeset ee1c2d9 in mainline for uspace/lib/http/src/http.c


Ignore:
Timestamp:
2015-06-13T18:30:18Z (9 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a157846
Parents:
0453261 (diff), 2f9a8e8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

mainline changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/http/src/http.c

    r0453261 ree1c2d9  
    3434 */
    3535
     36#include <errno.h>
    3637#include <stdio.h>
    3738#include <stdlib.h>
     
    3940#include <macros.h>
    4041
    41 #include <net/socket.h>
    4242#include <inet/dnsr.h>
     43#include <inet/tcp.h>
    4344
    4445#include <http/http.h>
     
    4849{
    4950        http_t *http = client_data;
    50         return recv(http->conn_sd, buf, buf_size, 0);
     51        size_t nrecv;
     52        int rc;
     53
     54        rc = tcp_conn_recv_wait(http->conn, buf, buf_size, &nrecv);
     55        if (rc != EOK)
     56                return rc;
     57
     58        return nrecv;
    5159}
    5260
     
    7785int http_connect(http_t *http)
    7886{
    79         if (http->connected)
     87        if (http->conn != NULL)
    8088                return EBUSY;
    8189       
     
    95103        }
    96104       
    97         struct sockaddr *saddr;
    98         socklen_t saddrlen;
     105        inet_ep2_t epp;
    99106       
    100         rc = inet_addr_sockaddr(&http->addr, http->port, &saddr, &saddrlen);
    101         if (rc != EOK) {
    102                 assert(rc == ENOMEM);
    103                 return ENOMEM;
    104         }
     107        inet_ep2_init(&epp);
     108        epp.remote.addr = http->addr;
     109        epp.remote.port = http->port;
    105110       
    106         http->conn_sd = socket(saddr->sa_family, SOCK_STREAM, 0);
    107         if (http->conn_sd < 0)
    108                 return http->conn_sd;
     111        rc = tcp_create(&http->tcp);
     112        if (rc != EOK)
     113                return rc;
    109114       
    110         rc = connect(http->conn_sd, saddr, saddrlen);
    111         free(saddr);
     115        rc = tcp_conn_create(http->tcp, &epp, NULL, NULL, &http->conn);
     116        if (rc != EOK)
     117                return rc;
     118       
     119        rc = tcp_conn_wait_connected(http->conn);
     120        if (rc != EOK)
     121                return rc;
    112122       
    113123        return rc;
     
    116126int http_close(http_t *http)
    117127{
    118         if (!http->connected)
     128        if (http->conn == NULL)
    119129                return EINVAL;
    120130       
    121         return closesocket(http->conn_sd);
     131        tcp_conn_destroy(http->conn);
     132        tcp_destroy(http->tcp);
     133        return EOK;
    122134}
    123135
Note: See TracChangeset for help on using the changeset viewer.