Ignore:
File:
1 edited

Legend:

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

    rb623b68 r779541b  
    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       
     
    8694                /* Interpret as a host name */
    8795                dnsr_hostinfo_t *hinfo = NULL;
    88                 rc = dnsr_name2host(http->host, &hinfo, AF_NONE);
     96                rc = dnsr_name2host(http->host, &hinfo, ip_any);
    8997               
    9098                if (rc != EOK)
     
    95103        }
    96104       
    97         struct sockaddr_in addr;
    98         struct sockaddr_in6 addr6;
    99         uint16_t af = inet_addr_sockaddr_in(&http->addr, &addr, &addr6);
     105        inet_ep2_t epp;
    100106       
    101         http->conn_sd = socket(PF_INET, SOCK_STREAM, 0);
    102         if (http->conn_sd < 0)
    103                 return http->conn_sd;
     107        inet_ep2_init(&epp);
     108        epp.remote.addr = http->addr;
     109        epp.remote.port = http->port;
    104110       
    105         switch (af) {
    106         case AF_INET:
    107                 addr.sin_port = htons(http->port);
    108                 rc = connect(http->conn_sd, (struct sockaddr *) &addr, sizeof(addr));
    109                 break;
    110         case AF_INET6:
    111                 addr6.sin6_port = htons(http->port);
    112                 rc = connect(http->conn_sd, (struct sockaddr *) &addr6, sizeof(addr6));
    113                 break;
    114         default:
    115                 return ENOTSUP;
    116         }
     111        rc = tcp_create(&http->tcp);
     112        if (rc != EOK)
     113                return rc;
     114       
     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;
    117122       
    118123        return rc;
     
    121126int http_close(http_t *http)
    122127{
    123         if (!http->connected)
     128        if (http->conn == NULL)
    124129                return EINVAL;
    125130       
    126         return closesocket(http->conn_sd);
     131        tcp_conn_destroy(http->conn);
     132        tcp_destroy(http->tcp);
     133        return EOK;
    127134}
    128135
Note: See TracChangeset for help on using the changeset viewer.